From 03fb58954dec886128a4011b6121754cbcdd79ff Mon Sep 17 00:00:00 2001 From: Vib Tools Date: Sun, 22 Nov 2026 05:47:38 -0800 Subject: [PATCH] ci: add isolated backend-only P05 runtime acceptance --- .gitea/workflows/MINIFEST.md | 3 +- .gitea/workflows/README.md | 4 +- .gitea/workflows/p05-backend-acceptance.yml | 40 +++++++++ README.md | 1 + docs/FEATURES-STATUS.md | 4 +- docs/MINIFEST.md | 1 + docs/P05-CI-03.md | 38 ++++++++ docs/PHASES.md | 7 ++ docs/README.md | 4 +- docs/SETUP-GUIDE.md | 5 ++ notes/CHANGELOG.md | 1 + notes/MINIFEST.md | 1 + notes/P05-CI-03.md | 35 ++++++++ project/CHANGELOG.md | 1 + project/CI-ARCHITECTURE.md | 15 ++++ project/FILE-MAP.md | 14 +++ project/FUNCTIONS.md | 12 +++ project/SOURCE-INVENTORY.md | 47 +++++----- tests/ci/MINIFEST.md | 4 +- tests/ci/README.md | 4 + tests/ci/backend_acceptance.sh | 96 +++++++++++++++++++++ tests/ci/backend_cleanup.sh | 60 +++++++++++++ 22 files changed, 370 insertions(+), 27 deletions(-) create mode 100644 .gitea/workflows/p05-backend-acceptance.yml create mode 100644 docs/P05-CI-03.md create mode 100644 notes/P05-CI-03.md create mode 100644 tests/ci/backend_acceptance.sh create mode 100644 tests/ci/backend_cleanup.sh diff --git a/.gitea/workflows/MINIFEST.md b/.gitea/workflows/MINIFEST.md index 478ceb2..2d10665 100644 --- a/.gitea/workflows/MINIFEST.md +++ b/.gitea/workflows/MINIFEST.md @@ -4,4 +4,5 @@ | --- | --- | --- | | [README.md](README.md) | Manual CI entry, job and security instructions | P05-CI-01 | | [MINIFEST.md](MINIFEST.md) | Workflow directory file inventory | P05-CI-01 | -| [p05-ci.yml](p05-ci.yml) | Isolated account/login/backend CI verification on Gitea | P05-CI-01 | +| [p05-ci.yml](p05-ci.yml) | Isolated account/login/backend CI verification on Gitea | P05-CI-01/P05-CI-02 | +| [p05-backend-acceptance.yml](p05-backend-acceptance.yml) | Manual backend-only disposable Compose, persistence and OIDC acceptance; no Account/Login build rerun | P05-CI-03 | diff --git a/.gitea/workflows/README.md b/.gitea/workflows/README.md index b6841da..db6a88d 100644 --- a/.gitea/workflows/README.md +++ b/.gitea/workflows/README.md @@ -1,6 +1,6 @@ # CI workflows - manual verification only -P05-CI-01 introduces a single `p05-ci.yml` with **manual workflow_dispatch**. Do not enable automatic push/PR builds with Docker access without a fresh security review. +P05-CI-01 introduced `p05-ci.yml`; P05-CI-03 adds a separate backend-only `p05-backend-acceptance.yml`. Both use **manual workflow_dispatch**. Do not enable automatic push/PR builds with Docker access without a fresh security review. Job responsibilities: @@ -10,6 +10,8 @@ Job responsibilities: **P05-CI-02 additions:** Account Portal CI negative route/API smoke, npm/pnpm structured Moderate advisory detail, and disposable Postgres restart persistence plus stronger OIDC issuer/JWKS negative checks. Run #83 passed Account, Login V2 and Security jobs but backend proxy bind to shared host port 8080 failed after Postgres/ZITADEL/Login healthy. **Post-run source fix:** all backend Compose calls include `tests/ci/compose.portless.override.yaml` (`ports: !reset []`), config rejects any published proxy port; this is not CI-verified. Full authenticated user sign-in/MFA remains deferred. +**P05-CI-03:** `p05-backend-acceptance.yml` runs **only** the isolated backend job with `tests/ci/backend_acceptance.sh` and always-run `backend_cleanup.sh`. It checks portless effective config, all four services, restart persistence, ready/discovery/JWKS and absence of CI leftovers. This avoids rerunning already accepted Account/Login suites. Manual only; no production. See `docs/P05-CI-03.md`. + **Run #81 evidence:** backend's first revision failed during checkout because Alpine had no Git. Added a pre-checkout Git installation afterward; the corrected backend job remains **UNVERIFIED** until a separately approved CI rerun. See `docs/P05-CI-01.md`. A green job indicates only its executed steps. Full CI acceptance also needs end-to-end OIDC session/callback, real login/MFA, admin console and session controls in a disposable environment, documented separately. diff --git a/.gitea/workflows/p05-backend-acceptance.yml b/.gitea/workflows/p05-backend-acceptance.yml new file mode 100644 index 0000000..a134a83 --- /dev/null +++ b/.gitea/workflows/p05-backend-acceptance.yml @@ -0,0 +1,40 @@ +name: ZitPlane P05-CI-03 Backend Acceptance + +# Isolated backend-only manual verification. Never grant Docker socket +# access to untrusted PRs or run this against production services. +on: + workflow_dispatch: + +permissions: + contents: read + +jobs: + backend: + name: Disposable Backend Portless, Persistence and OIDC + runs-on: ubuntu-latest + container: node:22-alpine + timeout-minutes: 35 + steps: + - name: Install Git before Gitea checkout + run: apk add --no-cache git + - uses: actions/checkout@v4 + with: + github-server-url: https://dev.ivib.cc + - name: Backend-only isolated acceptance + run: | + set -eu + apk add --no-cache python3 docker-cli docker-cli-compose + sh tests/ci/backend_acceptance.sh + - name: Always cleanup CI-owned Docker data and prove no leftovers + if: always() + run: | + set -eu + if [ -f tests/ci/backend_cleanup.sh ]; then + if [ -f .p05-ci-owned ]; then + apk add --no-cache docker-cli docker-cli-compose + fi + sh tests/ci/backend_cleanup.sh + else + echo '::error::Checkout or cleanup script unavailable; no Docker state is claimed clean' + exit 1 + fi diff --git a/README.md b/README.md index 88c0dde..0b579da 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Compact, developer-friendly monorepo for a central identity service, a branded l - **P04 Account Portal:** Next.js + ZITADEL OIDC Auth.js source, server-protected overview/profile/security pages and compact responsive foundation implemented under `users/ui/`. **No build/test/runtime validation yet; future Gitea Actions required.** - **P05-CI-01:** Manual Gitea Run #81 **overall FAILURE**: Login V2 build + 1219 unit tests PASS, high/critical gate PASS (18 Moderate Login findings), Account Auth.js TS2345 and Docker checkout FAIL. Details: `docs/P05-CI-01.md`. - **P05-CI-02:** Gitea Run #83 **3 PASS / 1 FAIL**. Account Portal typecheck/build and negative identity checks PASS; Login V2 build + 1219/1219 tests PASS; High/Critical security threshold PASS (18 Moderate Login records + 1 Moderate Account package OPEN). Docker Postgres/ZITADEL API/Login healthy, but shared runner port 8080 blocked Traefik; cleanup PASS. CI-only portless override added afterward **not CI-verified**; full OIDC E2E deferred. See `docs/P05-CI-02.md`. +- **P05-CI-03:** Dedicated backend-only Gitea Actions verification for portless Compose, PostgreSQL restart persistence, ZITADEL ready/OIDC discovery and safe cleanup. **Source prepared; CI acceptance pending.** Existing Account/Login build suites are not rerun. - **Production / Coolify:** not configured or deployed. ## Documentation and project knowledge diff --git a/docs/FEATURES-STATUS.md b/docs/FEATURES-STATUS.md index 239dab7..f7e67fa 100644 --- a/docs/FEATURES-STATUS.md +++ b/docs/FEATURES-STATUS.md @@ -1,6 +1,6 @@ # ZitPlane - Actual feature availability / limitations -Snapshot: 2026-11-22, P05-CI-02 Gitea Run #83 on source SHA `c27fe3d` (3 PASS / 1 FAIL); post-run CI-only portless patch remains unverified. **SOURCE EXISTS != RUNNING != VERIFIED != PRODUCTION**. +Snapshot: 2026-11-22, P05-CI-03 backend-only verification source prepared on baseline `4857558`; Gitea Run #83 (3 PASS / 1 FAIL) is historical. **P05-CI-03 run not yet executed.** **SOURCE EXISTS != RUNNING != VERIFIED != PRODUCTION**. | Feature | Source present | CI/build verified | Live/deployed | | --- | --- | --- | --- | @@ -18,7 +18,7 @@ Snapshot: 2026-11-22, P05-CI-02 Gitea Run #83 on source SHA `c27fe3d` (3 PASS / | Global ZITADEL SSO logout | No | N/A | No | | Subscriptions, payments and SaaS billing | Outside ZitPlane scope | N/A | No | | Gitea Actions CI verification workflow | Yes, P05 manual dispatch | Run #83: 3 PASS / 1 FAIL; Docker proxy 8080 collision, cleanup PASS | Not deployed | -| Gitea Actions CI and isolated integration tests | Negative tests/ready/persistence probe source prepared; full interactive OIDC E2E absent | Run #83: Postgres/ZITADEL API/Login healthy; proxy port collision prevented persistence/OIDC smoke; runtime BLOCKED | No | +| Gitea Actions CI and isolated integration tests | Backend-only manual workflow, portless/persistence/discovery/cleanup scripts prepared; interactive E2E absent | Run #83 historical: Postgres/ZITADEL API/Login healthy; full backend acceptance blocked pending P05-CI-03 | No | | Coolify production stack, TLS, routing and backups | No | No | No | | Public `auth.vib.tools/login` URL | Proposed only | No | No | | Public `account.vib.tools` account website | Proposed only | No | No | diff --git a/docs/MINIFEST.md b/docs/MINIFEST.md index 8d1a441..13c1b9b 100644 --- a/docs/MINIFEST.md +++ b/docs/MINIFEST.md @@ -9,6 +9,7 @@ Every file listed below is a direct child of `docs/`. Add/remove rows whenever t | [USER-GUIDE.md](USER-GUIDE.md) | Source-grounded Account Portal page/button-by-button manual | DOCS-01 / active; runtime pending | | [P05-CI-01.md](P05-CI-01.md) | Gitea Actions manual verification workflow, gates, limitations and real run evidence | P05-CI-01 / Run #81 complete, acceptance blocked | | [P05-CI-02.md](P05-CI-02.md) | TypeScript remediation, Gitea CI verification, dependency risk and isolation evidence | P05-CI-02 / run #83 done; Docker acceptance blocked | +| [P05-CI-03.md](P05-CI-03.md) | Isolated backend-only Gitea CI procedure, checks and exact run outcomes | P05-CI-03 / acceptance pending | | [SETUP-GUIDE.md](SETUP-GUIDE.md) | Operator/developer prerequisites, configs, activation and safety | DOCS-01 / active; runtime pending | | [FEATURES-STATUS.md](FEATURES-STATUS.md) | Exact implemented/unavailable/unverified feature matrix | DOCS-01 / active | | [TROUBLESHOOTING.md](TROUBLESHOOTING.md) | Known blockers and safe diagnosis based on source status | DOCS-01 / active | diff --git a/docs/P05-CI-03.md b/docs/P05-CI-03.md new file mode 100644 index 0000000..dc1f66b --- /dev/null +++ b/docs/P05-CI-03.md @@ -0,0 +1,38 @@ +# P05-CI-03 — Backend-only Gitea CI Acceptance + +**Date:** 2026-11-22 +**Approved baseline:** `485755800504a7dea6e4c303e6b39ec9cc610b54` +**Status:** Source prepared; no P05-CI-03 workflow run yet. + +## Objective and user-visible effect + +Verify the existing official ZITADEL v4.20.4 + PostgreSQL + prebuilt Login V2 + Traefik local development stack in an **isolated Gitea Actions runner**. This is NOT an application feature release or an authentication redesign. It does not start the app on your PC, configure public domains, modify credentials/users, or deploy anything. + +## How to launch the backend-only workflow + +In Gitea `vibtools/ZitPlane`, open **Actions → ZitPlane P05-CI-03 Backend Acceptance → Run workflow → main**. Only one manual `workflow_dispatch` is authorized for this phase. The new workflow is `.gitea/workflows/p05-backend-acceptance.yml`; prior Account and Login V2 build suites are deliberately **not rerun**. + +The runner needs its registered `ubuntu-latest` label, a functional Docker daemon/socket, Docker Compose v2 with support for `!reset`, access to pinned image registries and enough storage/time for four images. Do not run it on shared hosts with existing `zitplane-backend-dev-internal` network or an identical CI Compose project name. + +## Required verification + +1. Git checkout / Docker Engine / Compose preflight; refuse existing named network, project containers, or named volumes. +2. Generate fresh disposable local secrets in ignored `.env`. Merge the **read-only** P02 Compose with `tests/ci/compose.portless.override.yaml`; inspect effective proxy config to ensure **no host port publishing**, including TCP 8080. +3. Start and wait for PostgreSQL, ZITADEL API, prebuilt Login V2 and Traefik. Confirm first three healthy and proxy running. +4. Write synthetic marker in disposable Postgres `postgres` database; restart Postgres; check marker survives after health recovery. +5. From a disposable probe container within the CI-owned Docker network, check `/debug/ready`, exact local issuer `http://localhost:8080`, OIDC discovery endpoint URLs and a nonempty JWKS. Run malformed issuer/JWKS negative fixtures. +6. In a separate always-run step, stop **only CI-owned Compose project**, remove its disposable volumes, then check that no CI network/container/volume remains. Report any cleanup failure instead of claiming success. + +Expected markers: `ZITPLANE_CI_PORTLESS_CONFIG_PASS`, `ZITPLANE_FOUR_SERVICES_READY_PASS`, `ZITPLANE_POSTGRES_RESTART_PERSISTENCE_PASS`, `ZITPLANE_OIDC_NEGATIVE_CONTRACTS_PASS`, `ZITPLANE_BACKEND_OIDC_READY_DISCOVERY_JWKS_PASS`, `ZITPLANE_BACKEND_CLEANUP_VERIFIED_PASS`. + +**Do not claim backend acceptance unless each required check actually executes and passes.** Before the run, all are PENDING. + +## Out of scope / known boundaries + +Account Portal real authenticated login/callback and protected positive session; ZITADEL Admin Console human login, MFA, passkey, global SSO logout; Moderate dependency remediation (18 Login records plus 1 Account affected package); production ZITADEL, Coolify, DNS, TLS, backups and user data. Existing P02 developer Compose, Login V2 source and Account Portal must remain unchanged. + +## Actual acceptance ledger + +**PENDING:** After the single Gitea run, record run ID, tested source SHA, job conclusion, each marker, Docker service state, Postgres persistence, exact issuer/JWKS results, cleanup outcome and reproduced blockers. If any gate fails, label acceptance BLOCKED/FAILED and propose a focused next phase. Gitea workflow source-only changes or historical P05 runs are not proof of this phase. + +Developer details: [project/CI-ARCHITECTURE.md](../project/CI-ARCHITECTURE.md). Pre-change plan and final log: [notes/P05-CI-03.md](../notes/P05-CI-03.md). diff --git a/docs/PHASES.md b/docs/PHASES.md index 13cfae6..752fb1e 100644 --- a/docs/PHASES.md +++ b/docs/PHASES.md @@ -46,6 +46,13 @@ Implement one explicitly approved phase at a time. Keep out-of-scope files, exis - B01 Auth.js TypeScript TS2345: real subject string narrowing, preserve PKCE/state/nonce, expiry and protected identity guard. B02: verify in-CI Docker checkout, disposable ZITADEL, PostgreSQL restart persistence and OIDC discovery/JWKS. B03: report real Moderate advisory IDs/package/fix; HIGH+ security threshold remains a failure gate. B04: negative OIDC metadata and anonymous Account Portal checks, with interactive user E2E explicitly deferred. - **One** manual Gitea Run #83: Account Portal, Login V2, security gates PASS; Docker health progressed to PostgreSQL/ZITADEL API/Login V2 healthy, but runner host 8080 collision blocked proxy, database persistence and discovery. Full CI acceptance BLOCKED. Post-run CI-only `tests/ci/compose.portless.override.yaml` clears inherited host port, **not CI-verified**. 18 Moderate Login + 1 Moderate Account audit record still open, no package changes. Exact evidence in `notes/P05-CI-02.md`, `docs/P05-CI-02.md`. +## P05-CI-03 - Backend Runtime Final Acceptance (APPROVED 2026-11-22) +- Baseline `485755800504a7dea6e4c303e6b39ec9cc610b54`; prior Run #83 had 3 job PASS and backend FAIL due to runner host TCP 8080 collision. +- **Exact Write Scope:** optional `.gitea/workflows/p05-backend-acceptance.yml`, narrow existing P05 workflow if justified, focused `tests/ci/**`, notes/project/docs, associated workflow README/MINIFEST and root navigation if needed. Core backend, developer Compose, Login V2, Account Portal, dependencies/locks and production config all READ ONLY. +- **Manual backend-only** Gitea Actions acceptance: effective Compose proxy portless check, four-service health, disposable Postgres restart marker persistence, ZITADEL readiness/discovery/JWKS, malformed issuer/JWKS negative contracts and verified CI-only cleanup. +- One focused isolated run after source commit/push, no local test/build/Docker, no repeated Account/Login suites, no real users/secrets or production deployment. Full interactive login/MFA remains a separate phase. +- Evidence: `notes/P05-CI-03.md`, `docs/P05-CI-03.md`. Backend PASS only after all gates and cleanup are proven in Gitea. + ## P05 - Full Integration (proposed, NOT approved) Shared design system, production-safe Compose topology and verified Login/Account OIDC wiring. No live deployment; separate approval. diff --git a/docs/README.md b/docs/README.md index 962039b..06e2e27 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,7 +2,7 @@ **Purpose:** the Git-tracked, **user-facing** knowledge base: real functions, pages, controls, account behavior, prerequisites, how to use each available capability, troubleshooting and limitations. -**Current product status:** P02 local backend Compose, P03 imported Login V2 source, P04 account portal source. No integrated deployed product yet; Account Portal dependency installs/builds, login and health checks remain unverified. **Do not claim pages/buttons are working in production merely because source exists.** +**Current product status:** P02 local backend Compose, P03 imported Login V2 source, P04 account portal source. No integrated deployed product yet; Gitea Run #83 verified Account Portal and Login V2 builds, but real user login and full backend runtime acceptance remain unverified. **Do not claim pages/buttons are working in production merely because source exists.** ## What to read @@ -26,4 +26,4 @@ Full update policy is in root [AGENTS.md](../AGENTS.md). A list of available docs is in [MINIFEST.md](MINIFEST.md). -For manual Gitea runner verification and its limitations, see [P05-CI-01.md](P05-CI-01.md). A green backend discovery smoke is not an authenticated user-login result. +For backend-only isolated runtime verification see [P05-CI-03.md](P05-CI-03.md); for initial full workflow and its limitations see [P05-CI-01.md](P05-CI-01.md). A green backend discovery smoke is not an authenticated user-login result. diff --git a/docs/SETUP-GUIDE.md b/docs/SETUP-GUIDE.md index d7ce791..d95ede5 100644 --- a/docs/SETUP-GUIDE.md +++ b/docs/SETUP-GUIDE.md @@ -68,3 +68,8 @@ Refer to [FEATURES-STATUS.md](FEATURES-STATUS.md), [TROUBLESHOOTING.md](TROUBLES **P05-CI-02 status (2026-11-22):** Run #83 verified Account Portal build/typecheck and negative auth checks, Login V2 1219/1219 unit tests and a successful high/critical dependency threshold (Moderate issues still open). Disposable Postgres/ZITADEL API/Login V2 became healthy, but host TCP 8080 prevented proxy startup; cleanup succeeded. The workflow now has a **CI-only** portless override to allow internal-Docker-network probing on a shared runner, **not yet rerun**. See `docs/P05-CI-02.md`. This is not a production deployment guide. + + +## P05-CI-03 backend-only runtime verification (Gitea only) + +In Gitea `vibtools/ZitPlane` → **Actions** → **ZitPlane P05-CI-03 Backend Acceptance** → **Run workflow** → `main`. It uses the existing `ubuntu-latest` Linux Docker-capable runner; no Account or Login V2 production build suites are rerun. All credentials are generated in the disposable runner and are never used for production accounts. It checks portless effective Compose, four container states, a synthetic PostgreSQL restart marker, backend readiness, OIDC issuer/discovery and JWKS, and always-owned-resource cleanup. Results must come from the exact Gitea Actions run, not source presence. See `docs/P05-CI-03.md`. **This is not full interactive login, Coolify or production deployment.** diff --git a/notes/CHANGELOG.md b/notes/CHANGELOG.md index 2c0bf15..6c8446b 100644 --- a/notes/CHANGELOG.md +++ b/notes/CHANGELOG.md @@ -11,5 +11,6 @@ This is the chronological **index**. Phase-specific scope/implementation evidenc | 2026-11-22 | DOCS-01 | Knowledge folders, first-party file/function maps, exact source inventory, user guides and mandatory AGENTS documentation policy | Documentation implementation complete; focused manifest/link/scope audit PASS; Git SHA in DOCS-01 local commit, see [DOCS-01.md](DOCS-01.md) | | 2026-11-22 | P05-CI-01 | Gitea verification workflow, dependency lock reconciliation, narrow checkout remediation | Run #81: 2 PASS/2 FAIL; 1219 Login tests PASS, Account TS2345 and Docker checkout blocked; see [P05-CI-01.md](P05-CI-01.md) | | 2026-11-22 | P05-CI-02 | Narrow Auth.js TS2345 fix, CI negative tests, advisory triage and post-run portless override | Run #83: Account/Login/Security PASS, Docker FAIL on host 8080; cleanup PASS; portless override unverified. [Evidence](P05-CI-02.md) | +| 2026-11-22 | P05-CI-03 | Backend-only Gitea CI workflow and disposable portless/persistence/OIDC acceptance scripts | Source preparation; one CI run pending, [scope/evidence](P05-CI-03.md) | Rules: Append new phases or fixes; never silently rewrite a past result. Separate **implemented**, **verified**, **blocked**, and **proposed**. Never log a user secret or personal data. diff --git a/notes/MINIFEST.md b/notes/MINIFEST.md index 6dc153a..2cf36fb 100644 --- a/notes/MINIFEST.md +++ b/notes/MINIFEST.md @@ -7,6 +7,7 @@ | [DOCS-01.md](DOCS-01.md) | This documentation-governance change: baseline, scope, plan, implementation and closure | DOCS-01 / implementation complete | | [P05-CI-01.md](P05-CI-01.md) | Scope/roots, allowed paths, implementation and Gitea CI acceptance evidence | P05-CI-01 / source complete, CI blockers open | | [P05-CI-02.md](P05-CI-02.md) | Auth.js narrow patch, isolated Gitea CI gate, advisory triage and exact acceptance evidence | P05-CI-02 / run #83 completed; residual Docker gate blocked | +| [P05-CI-03.md](P05-CI-03.md) | Backend-only pre-change scope, disposable CI run evidence and exact acceptance result | P05-CI-03 / planned, run pending | | [CHANGELOG.md](CHANGELOG.md) | Short append-only chronological phase log and links to detailed reports | DOCS-01 / active | Update this manifest whenever any direct child file or directory changes. Use **actual source state**; a planned file must be labeled planned, not present. diff --git a/notes/P05-CI-03.md b/notes/P05-CI-03.md new file mode 100644 index 0000000..150c965 --- /dev/null +++ b/notes/P05-CI-03.md @@ -0,0 +1,35 @@ +# ZitPlane P05-CI-03 — Backend Runtime Final Acceptance + +**Date:** 2026-11-22 +**Status:** APPROVED — PRE-CHANGE PLAN (CI not started) +**Baseline / Gitea main:** `485755800504a7dea6e4c303e6b39ec9cc610b54` +**Prior CI:** [Run #83](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/83), tested `c27fe3d`; three jobs PASS (Account Portal, Login V2 including 1219 unit tests, High/Critical security gate), backend FAIL when proxy attempted to publish occupied host port 8080. + +## Exact scope lock + +**Allowed writes:** optional **new** `.gitea/workflows/p05-backend-acceptance.yml`; narrow `.gitea/workflows/p05-ci.yml` if justified; focused `tests/ci/**` (including `compose.portless.override.yaml`, `oidc_discovery.py`, README/MINIFEST), `.gitea/**/README.md` and `MINIFEST.md`; `notes/**`, `project/**`, related `docs/**`, root `README.md`/`MINIFEST.md` only as necessary. + +**Strict read-only:** `core/backend/zitadel/**`, `deployment/docker/compose.backend.dev.yaml`, `auth/ui/v2/**`, `users/ui/**`, manifest/lockfiles, current UI/auth/session logic, production configuration and unrelated files. Existing untracked `AI_INSTRUCTIONS.md` must remain untouched. + +**Execution:** one focused **backend-only** isolated Gitea Actions CI run after source commit/push; **no local tests/builds/dev servers/Docker**, no re-run of accepted Account/Login unit suites; no production deployment, release or real users/secrets. + +## Verified pre-change root cause and constraints + +1. Run #83 backend #174: Git Alpine pre-checkout and Docker daemon preflight PASS; P02 Python stdlib unit 3/3 PASS; PostgreSQL, official ZITADEL API v4.20.4, prebuilt Login v4.20.4 healthy. Traefik failed before health/discovery: `port 8080 is already allocated`. Always-cleanup removed CI-owned containers, volumes and network. +2. Post-run `tests/ci/compose.portless.override.yaml` uses Docker Compose supported `ports: !reset []` on `proxy`; P05-CI-02 inserted it on all 10 Compose references with effective-config `proxy.ports` guard. **This override has never been executed in CI**. +3. P02 developer Compose has fixed `zitplane-backend-dev-internal` network and local-only `127.0.0.1:8080:80` port. The CI must refuse any existing fixed network or competing project; never touch shared Docker stacks. CI-specific override must remove host port entirely. +4. Existing `tests/ci/oidc_discovery.py` checks synthetic rejection cases plus real `/debug/ready`, issuer/origin discovery, JWKS (nonempty key list) through internal Docker network and host `localhost:8080`. No real login, Admin Console, MFA or callback E2E acceptance is possible in this phase. + +## Implementation plan (prior to source changes) + +A. Add **backend-only manual** `.gitea/workflows/p05-backend-acceptance.yml` to avoid repeated Account/Login/Security jobs; use existing verified Alpine Git checkout prerequisite and Docker CLI capability preflight, previous P02 focused backend helper tests, guarded fixed network/project name, and P05 portless Compose overlay. Hard-fail before starting containers unless resulting proxy has no host ports. +B. Run disposable Compose `up -d --wait`; verify all four containers (`postgres`, `zitadel-api`, `zitadel-login`, `proxy`) are present and healthy/running as appropriate. Write a synthetic marker into the disposable Postgres default `postgres` DB, restart database, wait for health and confirm marker persists; probe readiness, exact local issuer metadata and public JWKS from an ephemeral probe container attached to the *new CI-owned network*. +C. Always tear down **only the run's Compose project/volumes**, delete generated local credentials; verify no run-owned containers, volumes or fixed network remain. If failure/cleanup incomplete, report exact blocker, never claim PASS. +D. Update manifest/README, `project/` function/file/CI history and `docs/` operator status. Audit exact staged paths/secrets. Commit and push source to Gitea main, dispatch **one** backend-only run, capture its actual terminal job logs. +E. Document exact CI SHA, PASS/FAIL/BLOCKED, remedy/outstanding risks and acceptance; do one final documentation-only commit/push with exact remote SHA. No rerun even if a focused defect is found. After closure provide next precise Scope Lock, concise implementation plan, and copy-ready approval. + +## Acceptance definitions + +Backend PASS only if effective Docker config is portless, four services reach the intended state, Postgres restart retains synthetic marker, real local ZITADEL ready + OIDC discovery + JWKS and negative test cases all PASS, and CI-owned network/volumes/container cleanup verified. Else mark FAILED/BLOCKED and preserve real source/log evidence. + +**Not in scope:** real OIDC authorized login/callback, Admin Console human login, MFA/SSO, dependency Moderate fixes (18 Login + 1 Account package), UI redesign or production TLS/Coolify. diff --git a/project/CHANGELOG.md b/project/CHANGELOG.md index c58f826..c1449aa 100644 --- a/project/CHANGELOG.md +++ b/project/CHANGELOG.md @@ -11,6 +11,7 @@ This is the **developer-focused implementation history**. `notes/CHANGELOG.md` i | 2026-11-22 | DOCS-01 | Documentation governance; developer architecture, reviewed first-party function/file/page mapping and 701-path source inventory; user manual/setup/status/troubleshooting | Documentation complete; manifest/link/source-scope audit PASS; `notes/DOCS-01.md`, local commit SHA via Git history | | 2026-11-22 | P05-CI-01 | `.gitea/workflows/p05-ci.yml`, `tests/ci/**`, Account npm lock, Login pnpm importer reconciliation and in-scope Alpine Git checkout correction | Run #81 overall FAIL; 2 jobs PASS, 2 FAIL; Login 1219/1219 tests PASS, Account TS2345 and Docker checkout blocked; `notes/P05-CI-01.md` | | 2026-11-22 | P05-CI-02 | Type-safe Auth.js subject narrowing, Account anonymous negative tests, Login regression, structured advisory triage and CI-only portless Docker override | Run #83: 3 PASS/1 FAIL; Docker proxy 8080 collision, cleanup PASS, portless fix unverified; see `notes/P05-CI-02.md` | +| 2026-11-22 | P05-CI-03 | Dedicated manual backend-only CI acceptance, guarded disposable Compose, persistence/ready/JWKS probes and owned-state cleanup | Source implemented, Gitea CI run pending; `notes/P05-CI-03.md` | ## Required entry for each future change diff --git a/project/CI-ARCHITECTURE.md b/project/CI-ARCHITECTURE.md index a761745..28359da 100644 --- a/project/CI-ARCHITECTURE.md +++ b/project/CI-ARCHITECTURE.md @@ -60,3 +60,18 @@ Gitea [Run #83](https://dev.ivib.cc/vibtools/ZitPlane/actions/runs/83) on SHA `c **Only after that run**, a P05-scoped CI overlay at `tests/ci/compose.portless.override.yaml` set `proxy.ports: !reset []`, as documented by Docker Compose: https://docs.docker.com/reference/compose-file/merge/#reset-value. Every backend workflow Compose call now includes this override; a fail-closed effective-config probe rejects any inherited host port. The P02 Compose and application logic remain untouched. **Post-run override has not been CI tested.** New exact Gitea main commit is documentation/source only and must not be described as the tested Run #83 SHA. Unresolved: one separately approved isolated backend re-verification cycle for the portless override, Postgres restart persistence and live OIDC/JWKS; distinct disposable authenticated OIDC/client/user + MFA E2E; targeted dependency-only security remediation of Moderate findings (no upgrades in P05-CI-02). + + +## P05-CI-03 — backend-only disposable acceptance + +This is a **separate** `.gitea/workflows/p05-backend-acceptance.yml` triggered manually on Gitea `main`. It does not schedule the previous Account/ Login V2/ security jobs again. + +- A short Alpine Git prerequisite precedes `actions/checkout@v4`. After checkout, only Python 3 stdlib and Docker CLI/Compose are installed in CI (not on the developer PC). +- `tests/ci/backend_acceptance.sh` accepts only a numeric `GITHUB_RUN_ID`; derives a unique Compose project `zitplane-p05-`; refuses existing hardcoded P02 network, same project containers or volumes. An existing local `.env` or ownership marker also causes fail-closed. +- The original `deployment/docker/compose.backend.dev.yaml` is read-only; `tests/ci/compose.portless.override.yaml` removes `proxy.ports` and JSON merged configuration explicitly rejects host publishing. This isolates the shared Actions Docker host from an occupied TCP 8080. +- After source-level P02 unit contracts (CI only) and fresh ignored `.env` creation, a marker `.p05-ci-owned` is created **only after** all collision/config checks. Then `docker compose up -d --wait` runs official pinned PostgreSQL, ZITADEL API, Login V2 and Traefik images. Postgres/API/Login need `healthy`, proxy needs `running`. +- A synthetic marker row in disposable Postgres default `postgres` DB is written then validated after a database container restart and Compose health recovery. +- Existing `tests/ci/oidc_discovery.py` runs in a throwaway `python:3.12-alpine` container on the owned internal network, validates negative issuer/JWKS fixtures, real `/debug/ready`, exact OIDC issuer/metadata and a nonempty public JWKS. +- `tests/ci/backend_cleanup.sh` is run by an **always** step: it must find an ownership marker before any Docker teardown; only its Compose project is removed with `down -v`. Cleanup then checks that no owned containers, volumes or the fixed network remain. A missing marker means Docker was never started by this run and cleanup is not required; **not** a backend PASS. + +This phase can verify local disposable backend runtime only. It **cannot** certify real account login, Admin Console session, MFA, global SSO logout, production TLS/Coolify or open Moderate package vulnerabilities. See `docs/P05-CI-03.md` for actual run evidence and `notes/P05-CI-03.md` for approval/scope. diff --git a/project/FILE-MAP.md b/project/FILE-MAP.md index 1f55b5d..4b9380e 100644 --- a/project/FILE-MAP.md +++ b/project/FILE-MAP.md @@ -121,3 +121,17 @@ For any approved update: 3. Change only approved files. Update relevant function/feature and user docs in the same phase. 4. Add change record to `project/CHANGELOG.md` and sync `MINIFEST.md` / source inventory if structure changes. 5. Do not rewrite or claim knowledge of every upstream function without examining it. Imported source internals stay officially sourced until audited for an approved edit. + + +## P05-CI-03 backend-only CI map + +| Path | Actual role / ownership | +| --- | --- | +| `.gitea/workflows/p05-backend-acceptance.yml` | New manual backend-only Gitea job; excludes redundant Account/Login suites; bounded Alpine Git/Docker prerequisite, acceptance and always cleanup | +| `tests/ci/backend_acceptance.sh` | CI project collision checks, portless effective Compose, four services, disposable PostgreSQL restart, OIDC/JWKS smoke; **CI only** | +| `tests/ci/backend_cleanup.sh` | Cleanup gated on CI-generated ownership marker; down -v for that Compose project and orphan/volume/network checks | +| `tests/ci/compose.portless.override.yaml` | Existing P05-CI-02 CI-only reset of inherited P02 Traefik host binding; read-only in this phase | +| `tests/ci/oidc_discovery.py` | Existing negative and live metadata/JWKS verification; read-only in this phase | +| `docs/P05-CI-03.md`, `notes/P05-CI-03.md` | Public-facing CI procedure and accurate implementation/run evidence | + +P02 dev Compose, core backend helper, Login V2 source, Account Portal and all dependency manifests remain unmodified. diff --git a/project/FUNCTIONS.md b/project/FUNCTIONS.md index e88a7e9..a074d86 100644 --- a/project/FUNCTIONS.md +++ b/project/FUNCTIONS.md @@ -90,3 +90,15 @@ Record: exact path, function name/signature, callers, inputs/outputs, error beha | `main()` | Same | Check ZITADEL readiness, issuer discovery metadata and JWKS shape; print explicit interactive OIDC E2E BLOCKED | Workflow service orchestration is in `.gitea/workflows/p05-ci.yml`, not Python. It executes only in Gitea CI; no local tests were requested. A green source check does not certify real authentication. + + +## P05-CI-03 backend CI shell entrypoints + +| Symbol / entrypoint | Source | Exact behavior | +| --- | --- | --- | +| `dc()` in acceptance script | `tests/ci/backend_acceptance.sh` | Applies project-specific `docker compose` with the P02 dev file **plus** CI portless override on every operation | +| `backend_acceptance.sh` main | Same | Refuses existing project/network/volumes, runs prior backend helper static tests only in Gitea, creates disposable `.env`/ownership marker, checks effective Compose has no published ports, four-service state, Postgres restart marker, OIDC ready/discovery/JWKS | +| `dc()` in cleanup script | `tests/ci/backend_cleanup.sh` | Uses identical exact Compose project and two-file configuration only after an ownership marker is present | +| `backend_cleanup.sh` main | Same | Always-step removes only marked CI project with volumes; verifies no fixed network, matching project containers or volumes persist; no marker => no project teardown | + +The scripts execute in the **Gitea Actions** runner, not on the local developer PC. Real user authentication and MFA are not implemented as CI checks. diff --git a/project/SOURCE-INVENTORY.md b/project/SOURCE-INVENTORY.md index b39b42a..d98709f 100644 --- a/project/SOURCE-INVENTORY.md +++ b/project/SOURCE-INVENTORY.md @@ -1,25 +1,27 @@ # Source inventory ? all Git-tracked paths -**Snapshot:** 2026-11-22, P05-CI-02 post-Run #83 documentation and CI-only portless correction based on tested `c27fe3d`. This source change has not been retested. +**Snapshot:** 2026-11-22, P05-CI-03 backend-only source preparation based on `4857558`. No claim of runtime PASS until the focused Gitea run completes. -**Tracked paths: 719.** Exact Git-index path list; untracked `AI_INSTRUCTIONS.md` and ignored secrets excluded. Source existence does not prove runtime acceptance. +**Git-tracked files: 724.** Untracked `AI_INSTRUCTIONS.md` and ignored secrets excluded. -| Top-level group | Files | Ownership | +This exact path inventory does not assert every upstream function was inspected. Consult `project/FILE-MAP.md` for first-party roles and `docs/P05-CI-03.md` for acceptance. + +| Group | Files | Owner/purpose | | --- | ---: | --- | -| `(repository root)` | 6 | Repository root | -| `.gitea` | 5 | Gitea manual CI workflows | -| `auth` | 639 | Upstream Login V2 import | -| `core` | 2 | Backend config/helper | -| `deployment` | 2 | Dev-only Docker Compose | -| `docs` | 14 | User/operator docs | -| `notes` | 6 | Phase scope and evidence | -| `packages` | 1 | Shared packages placeholder | -| `project` | 10 | Developer source map | -| `scripts` | 1 | Scripts placeholder | -| `tests` | 9 | CI verification scripts | -| `users` | 24 | Account Portal | +| `(repository root)` | 6 | Root files | +| `.gitea` | 6 | Gitea manual CI workflow files | +| `auth` | 639 | Official pinned Login V2 source | +| `core` | 2 | P02 dev orchestration | +| `deployment` | 2 | P02 local Compose | +| `docs` | 15 | User/operator guides and phase evidence | +| `notes` | 7 | Pre-change plans and phase reports | +| `packages` | 1 | First-party package placeholder | +| `project` | 10 | Developer file/function/CI mapping | +| `scripts` | 1 | Script placeholder | +| `tests` | 11 | CI/backend focused contracts | +| `users` | 24 | First-party Account Portal | -## Exact tracked paths +## Exact Git-tracked paths ### (repository root) ? 6 files @@ -30,12 +32,13 @@ - `MINIFEST.md` - `README.md` -### .gitea ? 5 files +### .gitea ? 6 files - `.gitea/MINIFEST.md` - `.gitea/README.md` - `.gitea/workflows/MINIFEST.md` - `.gitea/workflows/README.md` +- `.gitea/workflows/p05-backend-acceptance.yml` - `.gitea/workflows/p05-ci.yml` ### auth ? 639 files @@ -690,7 +693,7 @@ - `deployment/README.md` - `deployment/docker/compose.backend.dev.yaml` -### docs ? 14 files +### docs ? 15 files - `docs/ARCHITECTURE.md` - `docs/DEVELOPMENT.md` @@ -701,19 +704,21 @@ - `docs/P04-ACCOUNT-PORTAL.md` - `docs/P05-CI-01.md` - `docs/P05-CI-02.md` +- `docs/P05-CI-03.md` - `docs/PHASES.md` - `docs/README.md` - `docs/SETUP-GUIDE.md` - `docs/TROUBLESHOOTING.md` - `docs/USER-GUIDE.md` -### notes ? 6 files +### notes ? 7 files - `notes/CHANGELOG.md` - `notes/DOCS-01.md` - `notes/MINIFEST.md` - `notes/P05-CI-01.md` - `notes/P05-CI-02.md` +- `notes/P05-CI-03.md` - `notes/README.md` ### packages ? 1 files @@ -737,13 +742,15 @@ - `scripts/README.md` -### tests ? 9 files +### tests ? 11 files - `tests/README.md` - `tests/ci/MINIFEST.md` - `tests/ci/README.md` - `tests/ci/account_negative.py` - `tests/ci/advisory_triage.py` +- `tests/ci/backend_acceptance.sh` +- `tests/ci/backend_cleanup.sh` - `tests/ci/compose.portless.override.yaml` - `tests/ci/oidc_discovery.py` - `tests/ci/source_contract.py` diff --git a/tests/ci/MINIFEST.md b/tests/ci/MINIFEST.md index 715c252..52f41be 100644 --- a/tests/ci/MINIFEST.md +++ b/tests/ci/MINIFEST.md @@ -8,4 +8,6 @@ | [oidc_discovery.py](oidc_discovery.py) | Disposable ZITADEL ready/discovery/JWKS plus malformed issuer/JWKS negative contracts | P05-CI-01/P05-CI-02 | | [account_negative.py](account_negative.py) | CI-only Account Portal unauthenticated 401/protected redirect smoke | P05-CI-02 | | [advisory_triage.py](advisory_triage.py) | Extract registry audit advisory IDs/package/range/fix from npm/pnpm JSON | P05-CI-02 | -| [compose.portless.override.yaml](compose.portless.override.yaml) | CI-only override to clear inherited P02 proxy host port publishing; pending CI acceptance | P05-CI-02 post-run correction | +| [compose.portless.override.yaml](compose.portless.override.yaml) | CI-only override to clear inherited P02 proxy host port publishing; pending CI acceptance | P05-CI-02/P05-CI-03 | +| [backend_acceptance.sh](backend_acceptance.sh) | Backend-only runner preflight, four-service health, Postgres restart marker and OIDC/JWKS CI checks | P05-CI-03 | +| [backend_cleanup.sh](backend_cleanup.sh) | Always-run cleanup of marked CI-owned Compose project/volumes, with leftover verification | P05-CI-03 | diff --git a/tests/ci/README.md b/tests/ci/README.md index c4bc422..63452a3 100644 --- a/tests/ci/README.md +++ b/tests/ci/README.md @@ -10,4 +10,8 @@ This folder contains **CI-only** source/lockfile checks and OIDC discovery smoke No real credentials or production domains are used. Never print bootstrap PATs, admin secrets, session cookies or `.env` contents. Cleanup of disposable volumes is mandatory; never apply `docker compose down -v` to a user's non-CI stack. +- `backend_acceptance.sh` (P05-CI-03) is the manual backend-only Gitea runner preflight, portless Compose gate, four-service readiness, disposable database restart persistence and OIDC/JWKS smoke. Refuses pre-existing fixed network/project/volumes. +- `backend_cleanup.sh` (P05-CI-03) is the workflow's `always()` cleanup script. It tears down only a marked run-owned Compose project and verifies that no project containers, volumes or fixed network remain. Unverified cleanup is an explicit failure. +- Run from `.gitea/workflows/p05-backend-acceptance.yml` **only in isolated Gitea CI**, not on a production Docker host or local developer PC. + Add new CI checks and update `MINIFEST.md`, `project/`, `docs/`, and `notes/` in the same approved phase. diff --git a/tests/ci/backend_acceptance.sh b/tests/ci/backend_acceptance.sh new file mode 100644 index 0000000..369ac1c --- /dev/null +++ b/tests/ci/backend_acceptance.sh @@ -0,0 +1,96 @@ +#!/bin/sh +# P05-CI-03: disposable Gitea runner only. CI source, not a local developer command. +set -eu + +: "${GITHUB_RUN_ID:?Gitea run ID is required for isolated project ownership}" +case "$GITHUB_RUN_ID" in + *[!0-9]*|'') echo 'Invalid numeric Gitea run ID' >&2; exit 1 ;; +esac + +project="zitplane-p05-$GITHUB_RUN_ID" +network="zitplane-backend-dev-internal" +marker=".p05-ci-owned" + +dc() { + docker compose --env-file .env -p "$project" \ + -f deployment/docker/compose.backend.dev.yaml \ + -f tests/ci/compose.portless.override.yaml "$@" +} + +echo "ZITPLANE_BACKEND_PROJECT=$project" +docker --version +docker compose version +docker info --format 'Docker driver={{.Driver}}' >/dev/null +echo 'ZITPLANE_DOCKER_DAEMON_PREFLIGHT_PASS' + +# Never take over an existing named network, project, or persistent volume. +if docker network inspect "$network" >/dev/null 2>&1; then + echo '::error::Fixed P02 network already exists; refusing to touch another stack' + exit 1 +fi +if [ -n "$(docker ps -a -q --filter "label=com.docker.compose.project=$project")" ] || + [ -n "$(docker volume ls -q --filter "label=com.docker.compose.project=$project")" ]; then + echo '::error::CI project containers/volumes already exist; refusing takeover' + exit 1 +fi +for volume in "${project}_postgres-data" "${project}_zitadel-bootstrap"; do + if docker volume inspect "$volume" >/dev/null 2>&1; then + echo '::error::Existing CI-named volume; refusing takeover' + exit 1 + fi +done + +# On a clean checkout the generated env must not already exist. +if [ -e .env ] || [ -e "$marker" ]; then + echo '::error::CI credentials or project marker already exist; refusing overwrite' + exit 1 +fi + +python3 -m unittest discover -s tests -p test_backend_dev.py -v +echo 'ZITPLANE_P02_BACKEND_CONTRACTS_PASS' +python3 core/backend/zitadel/dev.py init +dc config --quiet +dc config --format json | + python3 -c 'import json,sys; d=json.load(sys.stdin); required={"postgres","zitadel-api","zitadel-login","proxy"}; assert required==set(d["services"]), "Unexpected disposable services"; assert not d["services"]["proxy"].get("ports"), "CI proxy unexpectedly publishes host ports"; print("ZITPLANE_CI_PORTLESS_CONFIG_PASS")' + +# Created only after the absence and effective-portless-config checks passed. +# The always() cleanup step must NEVER touch an unowned network. +touch "$marker" +dc up -d --wait +for service in postgres zitadel-api zitadel-login proxy; do + cid="$(dc ps -q "$service")" + if [ -z "$cid" ] || [ "$(docker inspect -f '{{.State.Running}}' "$cid")" != true ]; then + echo "::error::CI service not running: $service" + exit 1 + fi + if [ "$service" != proxy ] && + [ "$(docker inspect -f '{{.State.Health.Status}}' "$cid")" != healthy ]; then + echo "::error::CI service unhealthy: $service" + exit 1 + fi + echo "ZITPLANE_SERVICE_RUNNING_PASS=$service" +done +echo 'ZITPLANE_FOUR_SERVICES_READY_PASS' + +# Isolated persistence marker: disposable default 'postgres' database only. +dc exec -T postgres psql -U zitadel -d postgres -v ON_ERROR_STOP=1 \ + -c 'CREATE TABLE IF NOT EXISTS public.zitplane_ci_persist(marker text PRIMARY KEY)' +dc exec -T postgres psql -U zitadel -d postgres -v ON_ERROR_STOP=1 \ + -c "INSERT INTO public.zitplane_ci_persist(marker) VALUES ('p05-$project') ON CONFLICT DO NOTHING" + +dc restart postgres +dc up -d --wait +result="$(dc exec -T postgres psql -U zitadel -d postgres -tAc \ + "SELECT marker FROM public.zitplane_ci_persist WHERE marker = 'p05-$project' LIMIT 1")" +if [ "$result" != "p05-$project" ]; then + echo '::error::Postgres marker not retained across database restart' + exit 1 +fi +echo 'ZITPLANE_POSTGRES_RESTART_PERSISTENCE_PASS' + +# Read-only smoke inside the owned network; never publish a host HTTP port. +docker run --rm --network "$network" -e ZITPLANE_CI_PROXY=http://proxy \ + python:3.12-alpine python -c "$(cat tests/ci/oidc_discovery.py)" +echo 'ZITPLANE_BACKEND_OIDC_READY_DISCOVERY_JWKS_PASS' +echo '::warning::Real user login, OIDC callback, Admin Console and MFA E2E remain DEFERRED' +echo 'ZITPLANE_BACKEND_ACCEPTANCE_CHECKS_PASS' diff --git a/tests/ci/backend_cleanup.sh b/tests/ci/backend_cleanup.sh new file mode 100644 index 0000000..e686d46 --- /dev/null +++ b/tests/ci/backend_cleanup.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# P05-CI-03 always() step: touch ONLY the project this run marked as owned. +set -eu +marker=".p05-ci-owned" + +if [ ! -f "$marker" ]; then + # No project was started by this checkout; do not inspect/delete shared state. + rm -f .env + echo 'ZITPLANE_BACKEND_CLEANUP_NOT_REQUIRED' + exit 0 +fi + +: "${GITHUB_RUN_ID:?Missing run ID; cannot prove Docker ownership}" +case "$GITHUB_RUN_ID" in + *[!0-9]*|'') echo 'Unsafe Gitea run ID; cleanup needs manual review' >&2; exit 1 ;; +esac + +project="zitplane-p05-$GITHUB_RUN_ID" +network="zitplane-backend-dev-internal" +dc() { + docker compose --env-file .env -p "$project" \ + -f deployment/docker/compose.backend.dev.yaml \ + -f tests/ci/compose.portless.override.yaml "$@" +} + +# Preserve cleanup failure even when marker/env removal succeeds. +rc=0 +if [ ! -f .env ]; then + echo '::error::Owned CI marker present but credentials missing; cleanup cannot be verified' + rc=1 +elif ! dc down -v --remove-orphans; then + echo '::error::CI Compose teardown failed' + rc=1 +fi + +if docker network inspect "$network" >/dev/null 2>&1; then + echo '::error::CI Docker network remains after teardown' + rc=1 +fi +if [ -n "$(docker ps -a -q --filter "label=com.docker.compose.project=$project")" ]; then + echo '::error::CI project containers remain after teardown' + rc=1 +fi +if [ -n "$(docker volume ls -q --filter "label=com.docker.compose.project=$project")" ]; then + echo '::error::CI project volumes remain after teardown' + rc=1 +fi +for volume in "${project}_postgres-data" "${project}_zitadel-bootstrap"; do + if docker volume inspect "$volume" >/dev/null 2>&1; then + echo "::error::CI volume remains: $volume" + rc=1 + fi +done + +rm -f .env "$marker" +if [ "$rc" -ne 0 ]; then + echo '::error::Disposable state cleanup NOT VERIFIED; operator review required' + exit 1 +fi +echo 'ZITPLANE_BACKEND_CLEANUP_VERIFIED_PASS'