From 3b04263952020b47330617bf15666f2b3de59f3b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 25 Oct 2026 09:52:43 +0000 Subject: [PATCH] =?UTF-8?q?SP8:=20the=20turso=20v8=20shape=20=E2=80=94=20o?= =?UTF-8?q?ne=20secrets=20hook=20per=20provider,=20no=20Checks,=20docs=20i?= =?UTF-8?q?n=20the=20catalog,=20tasks=20in=20the=20background,=20landings?= =?UTF-8?q?=20checked=20here?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What sourceplane/turso-starter became across baseline-v6, v7 and v8, adapted to this repository's two providers, one Terraform root and six components (sourceplane/saas-starter's SA8 is the nearest sibling). A. One secrets hook per provider (turso TU9). The four single-key reconciles each read the workspace's connections and secrets before their create, one after another. orun's `secrets: [{key, template}]` declares them together: `secrets-cloudflare` (CLOUDFLARE_API_TOKEN workers-deploy, CLOUDFLARE_ACCOUNT_ID account-id) and `secrets-supabase` (SUPABASE_ACCESS_TOKEN management-access, SUPABASE_ORG_ID org-id). Two hooks, not one: a reconcile reads one provider's connection, and the two share no other parameter. Keys, templates and the card's order are unchanged. manifest.test.sh and placement.test.sh read the `secrets` form beside `keys`. B. No Checks workflow; docs in the catalog; no domain/component clash (turso TU10). checks.yml is gone: a product carries ci.yml alone, and a bootstrap's landings are checked in the box. testing/e2e.test.sh runs the landing's own checks from a LANDING_CHECKS list (the six commands checks.yml ran), and the leak gate no longer requires checks.yml. Every component attaches its generated overview, architecture and runbook in `spec.docs`; web-tests and db-tests get descriptions (their overviews regenerated with tooling/catalog/gen-component-docs.py). apps/web's domain is `app`, not `web` (no component is named `app`): a domain and a component share one name space in the catalog. coverage.test.sh holds both rules. C. The fast shape on orun v2.88.0 (turso TU11). The task set-up runs in the background; each phase finds its task in `post`, just before its landing; both landings are `checks: local`; the convergence watch reads every 5 s (it had the action's 40); no `pnpm install --lockfile-only` hook; 02-docs has no final probe and no narrate.await, and its render asks the platform nothing — the workspace slug, three secret listings and the integrations listing were five sequential CLI calls; the record now carries a static names-only secrets table that says where each key lives, and points to the console's Secrets and Integrations pages. The `wiring` await is gone entirely. Each of its four keys is resolved in the same convergence, fail-closed at job start, by a job that waits for the supabase apply on main: SUPABASE_PROJECT_REF, SUPABASE_DB_PASSWORD and SUPABASE_DB_URL by db-migrate (its secretEnv, per environment), WIRING_SUPABASE by web's deploy (each environment's own subscription `secretEnv`). A missing one fails its lane, so a green run already proves all four. phases.test.sh replaces the rule that demanded the await: each published key must be read that way on stage and prod, or else awaited — and a key already read must not be. Unlike saas, whose app reads its wiring at the component level, this rule also reads a subscription's own `secretEnv` (orun merges both into the job). The floor is v2.88.0: baseline.yml's blueprint and product tiers (both read the blueprint; the floor is newer than ci.yml's lane pin, v2.78.4, which stays), and BOOTSTRAP.md with its troubleshooting row. The blueprint job's setup-node asks for no pnpm cache: with no lockfile hook nothing in it runs pnpm, and setup-node v5's own pnpm cache fails the job in its post step when no earlier cache exists (nuxt-boilerplate#6). expectedMinutes 16 + 2 → 15 + 1. The card said 20 ("16 + 2, with room", "Live in about twenty minutes"), which the phases never summed to; it is now their sum, 16, "about sixteen minutes" in the card and BOOTSTRAP.md. Estimates, not measurements — no bootstrap of this baseline has been timed. The context pack's "twenty minutes" and "secrets inventory" follow. Worth knowing (true of turso and saas too): a product PR's `quick-check` lanes (db, db-tests, web-tests) only install and check structure, so with checks.yml gone nothing in a product's CI runs typecheck, lint or the tests; the baseline's e2e tier still runs them on the landing before a tag. Both READMEs now say so, and the product README tells its developers to run the `pnpm` scripts before they push. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CJuLwDKfEaQGAEuBpJvN5Q --- .baseline/product/README.md | 5 +- .github/workflows/baseline.yml | 31 ++-- .github/workflows/checks.yml | 46 ------ BOOTSTRAP.md | 43 +++-- README.md | 3 +- ai/context/current.md | 2 +- ai/context/deployment.md | 6 +- ai/context/open-risks.md | 2 +- ai/context/operations.md | 2 +- apps/web/component.yaml | 12 +- apps/web/utils/supabase/admin.ts | 4 +- blueprint.yaml | 27 ++-- docs/phases/01-product.md | 27 ++-- docs/phases/02-docs.md | 7 +- docs/phases/README.md | 27 +++- hooks/render-deployment-docs.sh | 70 ++++---- infra/db-migrate/component.yaml | 8 + infra/terraform/supabase/component.yaml | 8 + packages/db/component.yaml | 8 + repo-blueprint.yaml | 191 ++++++++++++---------- testing/coverage.test.sh | 40 +++++ testing/e2e.test.sh | 48 +++--- testing/leak.test.sh | 2 +- testing/lib/bootstrap.sh | 4 +- testing/manifest.test.sh | 9 +- testing/phases.test.sh | 207 +++++++++++++++++++----- testing/placement.test.sh | 19 +-- tests/db/component.yaml | 9 ++ tests/db/docs/overview.md | 2 + tests/web/component.yaml | 9 ++ tests/web/docs/overview.md | 2 + tooling/catalog/gen-component-docs.py | 7 +- 32 files changed, 559 insertions(+), 328 deletions(-) delete mode 100644 .github/workflows/checks.yml diff --git a/.baseline/product/README.md b/.baseline/product/README.md index 7bdb89f..8af7d38 100644 --- a/.baseline/product/README.md +++ b/.baseline/product/README.md @@ -14,7 +14,7 @@ included, all on every merge to `main`. Not recorded yet. The bootstrap's last phase writes the live URLs, the -workspace, whether Stripe is connected and the secrets inventory into +workspace, whether Stripe is connected and the secrets the product uses into [ai/context/deployment.md](ai/context/deployment.md); how the product deploys and how to operate it is in [ai/context/operations.md](ai/context/operations.md). @@ -171,5 +171,4 @@ repository names the domain itself. | Workflow | What it runs | |---|---| -| `checks.yml` | install, wire fixture, typecheck, lint, test, build — every pull request (not pushes: on `main`, `ci.yml` must be the only run a commit has) | -| `ci.yml` | the Orun pipeline: `orun plan --changed`, then one job per lane; applies, migrates and deploys stage → prod on merge | +| `ci.yml` | the Orun pipeline, and the only workflow: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes — the app built and dry-deployed for each environment, the Terraform root checked and planned, the migrations planned and their checksums verified — with nothing applied or deployed. It does not typecheck, lint or run the tests: those are the `pnpm` scripts above (Getting started), run them before you push. A merge applies, migrates and deploys stage → prod | diff --git a/.github/workflows/baseline.yml b/.github/workflows/baseline.yml index 4f04bf7..0451ad2 100644 --- a/.github/workflows/baseline.yml +++ b/.github/workflows/baseline.yml @@ -9,7 +9,7 @@ name: Baseline CI # up, in and out with no Stripe key — through Supabase Auth and the Data API, # with every table in `public` behind row-level security. # -# ─── WHY THIS IS NOT IN ci.yml OR checks.yml ────────────────────────────── +# ─── WHY THIS IS NOT IN ci.yml ──────────────────────────────────────────── # # `repo-blueprint.yaml`'s `github-workflows` module copies the WHOLE `.github` # directory into every product built from this repository. These jobs run @@ -70,20 +70,30 @@ jobs: # placement tier (the offline bootstrap: both phases placed and finished by # the blueprint's own hooks, then the product's own `orun plan` for the # 01-product merge — supabase, then db-migrate, then web, enforced — and a - # --resume that changes nothing). + # --resume that changes nothing). The floor is v2.88.0 (the task set-up in + # the background, the landings checked in the box, the deploy credentials + # minted in one `secrets` reconcile per provider), newer than the product's + # lane pin (v2.78.4, ci.yml), so the product's own plans here read the + # per-edge `modeRules` as its CI does. blueprint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: sourceplane/orun-action@v1.2.0 with: - version: v2.58.11 + version: v2.88.0 - uses: pnpm/action-setup@v4 with: version: 10.12.1 - uses: actions/setup-node@v5 with: node-version: 22 + # This job installs nothing either: with no lockfile hook the offline + # bootstrap never runs pnpm, so there is no store, and the pnpm cache + # setup-node v5 turns on by itself (package.json names a packageManager) + # fails the job saving a path that does not exist whenever no earlier + # cache exists for the lockfile. + package-manager-cache: false - name: repo-blueprint.yaml, read by the pinned CLI run: | set -euo pipefail @@ -104,8 +114,10 @@ jobs: git config --global user.name "baseline ci" bash testing/placement.test.sh - # Tier 2. THE PRODUCT IT PRODUCES WORKS: the 01-product landing under the - # checks its pull request waits on; a Supabase project's API on the runner — + # Tier 2. THE PRODUCT IT PRODUCES WORKS: the 01-product landing installed, + # its fixture rendered, type-checked, linted, tested and built (its own pull + # request runs `plan` alone, and the landing is checked in the box with + # `orun validate` and `orun plan`); a Supabase project's API on the runner — # its own Postgres, Supabase Auth and the Data API (the pinned GoTrue and # PostgREST releases, checksummed) behind one gateway that checks the API # key; the migrations applied by the product's own runner (through a @@ -115,16 +127,17 @@ jobs: # over that project with no Stripe key — its smoke, every route, a sign-up, # sign-out, sign-in and the account page through its own server actions, and # the anon key refused every row the policies do not give it. Pinned at the - # product's lane version, because that is the orun its CI runs. The runner - # image carries PostgreSQL 16 (not started); the test starts its own on a - # random port. + # bootstrap floor (v2.88.0): the offline bootstrap reads the blueprint, and + # the floor is newer than the product's lane pin (v2.78.4), which is all + # the lane steps need. The runner image carries PostgreSQL 16 (not started); + # the test starts its own on a random port. product: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: sourceplane/orun-action@v1.2.0 with: - version: v2.78.4 + version: v2.88.0 - uses: pnpm/action-setup@v4 with: version: 10.12.1 diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml deleted file mode 100644 index 67bd6a0..0000000 --- a/.github/workflows/checks.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Checks - -# Credential-free verification: install, render the offline wrangler fixture, -# typecheck, lint, test and build, on every pull request, linked or not. No -# database and no Stripe account: nothing here connects to either. -# `ci.yml` is the Orun pipeline beside it (plan/run with brokered Cloudflare -# and Supabase credentials, deploys on merge); it plans nothing until -# intent.yaml names a workspace. -# -# PULL REQUESTS ONLY — not pushes to main. A push to main must start exactly -# one workflow, `ci.yml`, because a bootstrap's convergence watch -# (`orun.run/watch@v1` with `sha:`) takes the newest run for the merge commit -# from ANY workflow: with this one on push too, the watch can read this run -# green while ci.yml's deploy lanes failed, and call the product converged. -# On main the convergence builds and tests everything anyway. -on: - pull_request: - workflow_dispatch: - -concurrency: - group: checks-${{ github.event_name == 'pull_request' && github.ref || github.run_id }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -permissions: - contents: read - -jobs: - checks: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - uses: pnpm/action-setup@v4 - with: - version: 10.12.1 - - uses: actions/setup-node@v5 - with: - node-version: 22 - cache: pnpm - - run: pnpm install --frozen-lockfile - # Templated deployables render their wrangler config from the committed - # fixture; an unresolved wiring token fails here, not at deploy time. - - run: pnpm run wire:fixture - - run: pnpm typecheck - - run: pnpm lint - - run: pnpm test - - run: pnpm build diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index c56089d..666270d 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -13,21 +13,27 @@ not separate workflows. The console card the platform renders is brokered secrets and the programme, and `testing/manifest.test.sh` holds it to what the build document does. -Target wall-clock: **about twenty minutes** — an estimate summed from the -phases until a bootstrap measures it: one landing, then one convergence per -environment (stage and prod side by side until `02-docs` restores the +Target wall-clock: **about sixteen minutes** — an estimate summed from the +phases (15 + 1) until a bootstrap measures it. The shape: the task set-up in +the background while ONE landing is placed, branded and checked in the box +(`orun validate` and `orun plan`, no runner waited for), then one convergence +per environment (stage and prod side by side until `02-docs` restores the promotion gate) that creates the Supabase project (five to seven minutes), -applies the migrations and builds and deploys the app, in that order. +applies the migrations and builds and deploys the app, in that order, then a +short docs landing. ## 0. What you need - GitHub org access (repository creation) and a machine with `git`, `node` (≥ 22), `pnpm` (10.12.1), `python3` with PyYAML, `curl`, and the `orun` - CLI **≥ v2.58.11** — the floor for RUNNING the bootstrap (the phase overlay, - landings that wait on the PR's whole CI run, `githubOwner` on the doctor - probe, `environments` on the secrets probe, `from: workspace`). The - product's own `ci.yml` pins its lanes separately (v2.78.4), and that pin is - what reads the per-edge `mode` rules the convergence order relies on. + CLI **≥ v2.88.0** — the floor for RUNNING the bootstrap (the phase overlay, + `githubOwner` on the doctor probe, `from: workspace`, the deploy + credentials minted in one `secrets` reconcile per provider, the task set-up + run in the background (`background: true`), and landings checked in the box + before they merge (`checks: local`)). The product's own `ci.yml` pins its + lanes separately (v2.78.4), and that pin — or anything newer, as the floor + is — is what reads the per-edge `mode` rules the convergence order relies + on. - A **Cloudflare** account (the free plan is enough for one Worker with static assets) and its Account API token with the permission groups the console's Connect recipe lists — Workers Scripts Write among them: the @@ -88,8 +94,8 @@ phase whose files are present but branded derives as `drifted`, and | phase | what it lands | verified by | |---|---|---| -| `01-product` | the repository, created and linked; the four brokered credentials; then the whole product in one PR — intent, CI, tooling, identity, the Supabase Terraform root, the migrations, the app and its tests | the convergence green (supabase → db-migrate → web, per environment), the four published secrets on stage and prod, `/` and `/api/health` answering on both workers.dev URLs | -| `02-docs` | `ai/context/deployment.md` from probed facts (Stripe's state included); prod's promotion gate and dev's push lanes restored | the final probe | +| `01-product` | the repository, created and linked; the four brokered credentials; then the whole product in one PR — intent, CI, tooling, identity, the Supabase Terraform root, the migrations, the app and its tests | its commit validated and planned in the box (as the PR and as the merge), then merged; the convergence green (supabase → db-migrate → web, per environment — each resolving what the apply before it published); `/` and `/api/health` answering on both workers.dev URLs | +| `02-docs` | `ai/context/deployment.md` from probed facts (Stripe's state included); prod's promotion gate and dev's push lanes restored | the render's own probes, recorded; the commit checked in the box and merged | ```bash orun new --blueprint repo-blueprint.yaml --out ~/products/acme-pay --run-hooks \ @@ -201,10 +207,10 @@ bash testing/e2e.test.sh # + network for pnpm and two pinned releases, p The offline bootstrap (`testing/lib/bootstrap.sh`) places both phases in order and finishes each with the blueprint's OWN `run:` hooks — read out of `repo-blueprint.yaml`, not transcribed — so the retouch marker, the rebrand, -the re-tenant, the deferrals and their restore, the lockfile and the -deployment record all run exactly as a real bootstrap runs them. Only the -platform's typed actions (task, repo, reconcile, land, watch, secrets, -probe) and the `link` step are stood in for, a landing becoming a commit. +the re-tenant, the deferrals and their restore and the deployment record +all run exactly as a real bootstrap runs them. Only the platform's typed +actions (task, repo, reconcile, land, watch, probe) and the `link` step are +stood in for, a landing becoming a commit. What no test here can do is the clouds' half: create a Supabase project, read its keys and write its Auth settings, mint a token, push the Worker @@ -248,14 +254,17 @@ at the tag and refuses the whole catalogue if it 404s. | supabase apply: project limit reached | the Supabase organization has no room for stage + prod (the free plan allows two active projects); pause or delete one, or upgrade, then re-run `01-product` | | supabase apply: forbidden reading the API keys or writing the Auth config | the brokered token's scopes do not reach those endpoints (untested before a live run — the epic's SP-M). Connect Supabase with a personal access token, or set the Auth values by hand and drop `supabase_settings` from the product's root | | db-migrate: `secret resolution failed … SUPABASE_*` | the supabase apply for that environment did not publish; its lane's log says why. db-migrate waits on it, enforced | +| web: `secret resolution failed … WIRING_SUPABASE` | that environment's supabase apply published no wiring: the root lost its `secretOutputs`, or its lane was not in the plan. Re-run the phase; its retouch marker re-plans the Supabase root | +| `land` stops: `the landing's own check failed — orun plan for …` | the product's tree does not plan — the line after it is orun's own error (an unknown component type, a composition that does not resolve). Nothing was pushed. Fix the tree (or the baseline) and re-run the phase | +| `land` waits on CI after all | the product's repository requires a status check on `main` (branch protection or a ruleset), so GitHub refused the early merge; the landing waits for the check as a `checks: ci` landing would, then merges | | db-migrate: `tables in public without row-level security …` | migration 020 refused: a table in `public` has no RLS, so the anon key could read it. Nothing deployed; enable RLS (and the policies the app needs) in a new migration, then re-run `01-product` | | web `build-app`: `wrangler secret bulk failed` | the deploy token cannot write the Worker's secrets; reconnect Cloudflare with the recipe's permission groups (Workers Scripts Write) and re-run the phase | | web smoke: `/api/health` 503 | `supabase: unreachable` — the project is paused or the URL wrong; `schema: missing` — db-migrate did not run for that environment; `serviceRole: missing`/`invalid` — the secret push did not happen or the key is not the project's | | `build-app` fails: `Symlink apps/web/node_modules/next is invalid, it points out of the filesystem root` | the product's intent pins stack-tectonic ≥ 0.20.0, whose lane-scoped install links each job's node_modules out of its tree, which Next 16's Turbopack refuses. Pin 0.19.0 (`intent.yaml` says why) | | `verify-app-structure` fails: `test -f "wrangler.jsonc"` | the product's `apps/web/wrangler.jsonc` is not committed. It must be — the check runs before the build in a fresh checkout (`pnpm run wire:fixture` renders it) | | Convergence failed AFTER the PR merged; re-running lands nothing | expected on its own — the files are on main. Re-run the phase (`--phase 01-product`, `--redo 01-product`, or the console's Retry): its `retouch` hook gives the landing a diff and the components re-plan; the project is adopted, not recreated | -| The convergence reported green, then `verify` got 404 | a second workflow ran on the push to main and the watch took its run. Only `ci.yml` may run on a push to main; `checks.yml` runs on pull requests only | +| The convergence reported green, then `verify` got 404 | a second workflow ran on the push to main and the watch took its run. Only `ci.yml` may run on a push to main | | The product's `intent.yaml` says `workspace: ws_SET_ME` | `orunWorkspace` was empty and the build ran outside a workspace; set it and re-run `01-product` | | A bootstrap stopped before `02-docs`; prod no longer waits on stage | the gate is deferred, not dropped: run `02-docs`, or `node tooling/bootstrap/promotion.mjs --restore --file /intent.yaml` | | `✕ input "productname" is required` | all three required inputs (`reponame`, `productname`, `githuborg`) must be set on every invocation, single-phase ones included | -| `unknown flag: --phase` or a parse error in the blueprint | the CLI is below the v2.58.11 floor | +| `unknown flag: --phase`, `has no parameter "checks"`, `has no parameter "secrets"` or another parse error in the blueprint | the CLI is below the v2.88.0 floor | diff --git a/README.md b/README.md index 3d2481c..a3676bb 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,6 @@ carries. | Workflow | What it runs | Ships to a product | |---|---|---| -| `checks.yml` | install, wire fixture, typecheck, lint, test, build — every PR (not pushes: on main, `ci.yml` must be the only run a commit has, because the bootstrap's convergence watch takes the newest one) | yes | -| `ci.yml` | the Orun pipeline: `orun plan --changed`, then one job per lane; applies, migrates and deploys stage → prod on merge. It plans nothing while `intent.yaml` names the placeholder workspace `ws_CHANGE_ME`, as this repository does | yes | +| `ci.yml` | the Orun pipeline, and the only workflow a product carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (the app built and dry-deployed per environment, the Terraform root checked and planned, the migrations planned; the packages and the two test suites only installed and their structure checked), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone runs and nothing waits for it — the landing was checked in the build box; a merge applies, migrates and deploys stage → prod. Typecheck, lint and the tests run in `baseline.yml`'s e2e tier on the landing before every tag, and in a product as the `pnpm` scripts its developers run before they push. It plans nothing while `intent.yaml` names the placeholder workspace `ws_CHANGE_ME`, as this repository does | yes | | `baseline.yml` | the baseline's own tiers: contract tests; the blueprint read by the pinned orun, the leak gate, the offline bootstrap and the product's own plans; the product built, migrated into a local Supabase (its real Auth and Data API), dry-deployed, served and signed up, out and in on | no | | `tag.yml` | cuts a `baseline-vN` tag (manual) | no | diff --git a/ai/context/current.md b/ai/context/current.md index 7218889..1237431 100644 --- a/ai/context/current.md +++ b/ai/context/current.md @@ -25,7 +25,7 @@ afterwards; the app deploys and serves without it. | Latest tag | `baseline-v3` (SP7 — the domain is set later, [#9](https://github.com/sourceplane/subscription-payments/pull/9): the console asks for no domain, and a product is born with the placeholder `.example.com` for an owner to replace) | | Before it | `baseline-v2` (SP6 — the cirrus standard, [#7](https://github.com/sourceplane/subscription-payments/pull/7) and [#8](https://github.com/sourceplane/subscription-payments/pull/8): no kiox, generated component docs, this context pack, and the workers.dev subdomain read from the Cloudflare connection instead of asked) | | Before that | `baseline-v1` (SP5, [#6](https://github.com/sourceplane/subscription-payments/pull/6)) | -| Proven live | No. Everything short of the platform is proven offline in Baseline CI: the e2e tier migrates a local Postgres under the real Supabase Auth and Data API with the product's own runner, builds in orun's staged job tree, and signs a user up and in with no Stripe key. No bootstrap from a tag has run against a workspace: the Supabase root's apply through the brokered token (SP-M), db-migrate against a real project, the service-role push, a real deploy and the card's twenty minutes (SP-N) are unproven | +| Proven live | No. Everything short of the platform is proven offline in Baseline CI: the e2e tier migrates a local Postgres under the real Supabase Auth and Data API with the product's own runner, builds in orun's staged job tree, and signs a user up and in with no Stripe key. No bootstrap from a tag has run against a workspace: the Supabase root's apply through the brokered token (SP-M), db-migrate against a real project, the service-role push, a real deploy and the card's sixteen minutes (SP-N) are unproven | ## Where to read diff --git a/ai/context/deployment.md b/ai/context/deployment.md index c3276cb..8e5363c 100644 --- a/ai/context/deployment.md +++ b/ai/context/deployment.md @@ -2,6 +2,6 @@ > Not rendered yet. The bootstrap's `02-docs` phase probes every live URL and > regenerates this file from what answered — the workspace, the URLs and -> their status, whether Stripe is connected, and the secrets inventory by -> name. Until then, nothing here claims the product is live. The operating -> contract is [operations.md](operations.md). +> their status, whether Stripe is connected, and the secrets the product +> uses, by name. Until then, nothing here claims the product is live. The +> operating contract is [operations.md](operations.md). diff --git a/ai/context/open-risks.md b/ai/context/open-risks.md index 2b35d93..7380936 100644 --- a/ai/context/open-risks.md +++ b/ai/context/open-risks.md @@ -8,7 +8,7 @@ lists only what is still live, so it should be short. | ID | Risk | State | What closes it | |---|---|---|---| | SP-M | The supabase root reads the project's API keys and writes its Auth config with the brokered `management-access` token; whether that token's scopes reach those endpoints is untested, and a refusal fails the first apply | OPEN | The first live bootstrap's supabase apply | -| SP-N | No bootstrap has been timed (the card's twenty minutes is summed from estimates); the root has not been applied and db-migrate has not run against a real project | OPEN | One bootstrap from a tag against a workspace | +| SP-N | No bootstrap has been timed (the card's sixteen minutes is summed from estimates); the root has not been applied and db-migrate has not run against a real project | OPEN | One bootstrap from a tag against a workspace | Accepted, and worth knowing before you change them: SP-A (`init.sql` is not idempotent), SP-F (the `supabase` CLI devDependency under pnpm 10), SP-H diff --git a/ai/context/operations.md b/ai/context/operations.md index 0299478..93d9fd7 100644 --- a/ai/context/operations.md +++ b/ai/context/operations.md @@ -2,7 +2,7 @@ This is the standing guide to how this product is deployed and operated. Instance facts (live URLs, workspace, whether Stripe is connected, the -secrets inventory) live in [deployment.md](deployment.md), rendered from +secrets it uses) live in [deployment.md](deployment.md), rendered from probed reality by the bootstrap's `02-docs` phase; this file is the contract that stays true between deployments. It is written to give an agent with repository read access enough context to reason about and operate the product diff --git a/apps/web/component.yaml b/apps/web/component.yaml index e021721..6cfb60c 100644 --- a/apps/web/component.yaml +++ b/apps/web/component.yaml @@ -7,7 +7,17 @@ spec: type: cloudflare-workers-assets-turbo lifecycle: production owner: platform - domain: web + # Its pages, attached to it in the workspace's catalog: what the Docs + # library shows for it, and what the catalog's docs and runbook checks read. + # Generated from what this manifest and its sources declare. + docs: + overview: docs/overview.md + pages: + - { path: docs/architecture.md, role: architecture, title: Architecture } + - { path: docs/runbook.md, role: runbook, title: Runbook } + # `app`, not `web`: a domain and a component share one name space in the + # catalog, and a domain called `web` hid this component from it. + domain: app path: apps/web # Its own lane per environment: the Next.js build is the longest job in the # plan, and a shared lane would wait on it. diff --git a/apps/web/utils/supabase/admin.ts b/apps/web/utils/supabase/admin.ts index 0299e8c..f3b6d1b 100644 --- a/apps/web/utils/supabase/admin.ts +++ b/apps/web/utils/supabase/admin.ts @@ -15,8 +15,8 @@ const TRIAL_PERIOD_DAYS = 0; // // Built per call rather than at module scope: on Cloudflare Workers the // environment is populated per request, and a build without a Supabase -// project (Checks, a fresh clone) must not throw while Next collects the -// webhook route's page data. +// project (the landing's checks in the baseline's CI, a fresh clone) must +// not throw while Next collects the webhook route's page data. const supabaseAdmin = () => createClient( process.env.NEXT_PUBLIC_SUPABASE_URL || '', diff --git a/blueprint.yaml b/blueprint.yaml index 6d945cf..8ee9c8a 100644 --- a/blueprint.yaml +++ b/blueprint.yaml @@ -26,7 +26,7 @@ metadata: organization needs room for two projects (its free plan allows exactly two active ones) — db-migrate applies the schema with row-level security on every table, and CI deploys it all to stage and prod on merge, in that - order. Stripe connects after the build. Live in about twenty minutes. + order. Stripe connects after the build. Live in about sixteen minutes. tags: [subscriptions, stripe, supabase, cloudflare, nextjs] spec: source: @@ -111,14 +111,14 @@ spec: from: connection.cloudflare.workersSubdomain # ── PREVIEW ONLY. repo-blueprint.yaml's `orun.integrations/reconcile@v1` - # hooks mint these, brokered, during 01-product. ───────────────────────── - # Transcribed from those hooks' own `keys:` and `template:` values, so - # testing/manifest.test.sh compares this list to the document that mints - # them. The console renders them read-only: no credential is ever typed, - # shown or stored. Keys that already exist are kept. Four keys, four - # scopes; no Hyperdrive token, because the app reaches Supabase through - # its API, not as Postgres. Stripe's keys are not here: no connection mints - # them. + # hooks mint these, brokered, during 01-product — one hook per provider. ─ + # Transcribed from those hooks' own `provider:` and `secrets:` ({key, + # template}) values, in their order, so testing/manifest.test.sh compares + # this list to the document that mints them. The console renders them + # read-only: no credential is ever typed, shown or stored. Keys that + # already exist are kept. Four keys, four scopes; no Hyperdrive token, + # because the app reaches Supabase through its API, not as Postgres. + # Stripe's keys are not here: no connection mints them. secrets: - key: CLOUDFLARE_API_TOKEN provider: cloudflare @@ -154,11 +154,10 @@ spec: # THE BUILD DOCUMENT. There is no umbrella workflow and no agent brief: # every phase is declared in it and orun runs it. blueprint: repo-blueprint.yaml - # Summed from the phases' expectedMinutes (16 + 2), with room: an - # estimate until a bootstrap measures it. A Supabase project takes five to - # seven minutes to come up, and the app's deploy waits on it and on the - # migrations. - expectedMinutes: 20 + # Summed from the phases' expectedMinutes (15 + 1). An estimate until a + # bootstrap measures it: a Supabase project takes five to seven minutes to + # come up, and the app's deploy waits on it and on the migrations. + expectedMinutes: 16 tokenChannel: ORUN_TOKEN_FILE # how a runner hands over its refreshed token verify: urls: diff --git a/docs/phases/01-product.md b/docs/phases/01-product.md index a9ae679..586ea8a 100644 --- a/docs/phases/01-product.md +++ b/docs/phases/01-product.md @@ -31,9 +31,12 @@ push to main and reads the order off it: `supabase → db-migrate → web`. ## What runs +The run's task set-up — the epic, both milestones, both tasks — runs in the +background from the start (`background: true`), so every hook up to `task` +runs beside it; `task` is the first that waits for it. + | hook | what it does | |---|---| -| `task` (pre) | finds the phase's task and yields its key | | `retouch` | one trailing `# orun: redeploy 01-product ` line in each component `.baseline/tasks/01-product.TaskContract.yaml` names (supabase, db, db-migrate, web), so a RE-RUN has a diff to land | | `git-init`, `stage` | the tree becomes a git repository with a populated index (the rebrand enumerates `git ls-files`) | | `rebrand` | renames the baseline's identity to the product's: the slug (intent, worker, secret project, the `repo` the Supabase project is named after), the name seam, the domain, the workers.dev subdomain. The upstream template's own identity (`nextjs-subscription-payments`, its demo site) and every migration are left alone | @@ -41,13 +44,13 @@ push to main and reads the order off it: `supabase → db-migrate → web`. | `work-tree` | strips this repository's `work:` block from the product's intent | | `promotion`, `dev-lanes` | defer prod's wait on stage and dev's push lanes until `02-docs` | | `restage`, `rebrand-verify` | the sweep: no baseline identity left | -| `pnpm-lockfile` | confirms the complete lockfile `root-pnpm-lock` placed | | `repo` | `orun.repo/ensure@v1`: creates (or finds) `/` | | `link` | the repository becomes the workspace's (`orun cloud link`, best effort; `orun cloud check` is the gate). Every convergence lane authenticates over GitHub OIDC through that link | -| `secret-*` | four `orun.integrations/reconcile@v1` hooks, one key and one scope each: `CLOUDFLARE_API_TOKEN` (workers-deploy), `CLOUDFLARE_ACCOUNT_ID` (account-id), `SUPABASE_ACCESS_TOKEN` (management-access), `SUPABASE_ORG_ID` (org-id). Keys that exist are kept | -| `land` | one PR, checked (Checks, and `plan` alone on a bootstrap branch), then merged | -| `converge` (await) | `orun.run/watch@v1` on the merge commit's run; resumes it up to three times | -| `wiring` (await) | `orun.secrets/exists@v1`: `SUPABASE_PROJECT_REF`, `SUPABASE_DB_PASSWORD`, `SUPABASE_DB_URL` and `WIRING_SUPABASE` on stage and prod | +| `secrets-cloudflare` | `orun.integrations/reconcile@v1`, Cloudflare's two keys in one hook, each under its own scope, created side by side: `CLOUDFLARE_API_TOKEN` (workers-deploy — the app's deploy and its service-role secret), `CLOUDFLARE_ACCOUNT_ID` (account-id). Keys that exist are kept | +| `secrets-supabase` | the same for Supabase's two: `SUPABASE_ACCESS_TOKEN` (management-access — the project, its Auth settings and the migrations), `SUPABASE_ORG_ID` (org-id) | +| `task` | finds the phase's task and yields its key — waiting, if it must, for the background set-up | +| `land` | one PR bound to the task, its commit checked in the box first (`checks: local`: `orun validate`, then `orun plan` as the PR and as the merge would plan it, under a second); merged without waiting for the PR's CI (`plan` alone on a bootstrap branch) | +| `converge` (await) | `orun.run/watch@v1` on the merge commit's run, read every 5 s; resumes it up to three times | | `verify` (await) | `orun.http/probe@v1`: `/` and `/api/health` on both workers.dev URLs | ## What the convergence does, per environment @@ -82,8 +85,12 @@ Stripe"). ## Verify / done means -- The convergence for the merge commit is green on stage and prod. -- The four published secrets exist on stage and prod. +- The convergence for the merge commit is green on stage and prod — in it, + db-migrate resolved the Supabase project's `SUPABASE_PROJECT_REF`, + `SUPABASE_DB_PASSWORD` and `SUPABASE_DB_URL`, and the app's deploy + `WIRING_SUPABASE`, from stage and prod, where every later run reads them. + A missing one fails its lane, so there is no separate check that they + exist. - `/` and `/api/health` answer on both workers.dev URLs. ## Failure modes @@ -98,7 +105,9 @@ Stripe"). | db-migrate lane: secret resolution failed (`SUPABASE_*`) | the supabase apply for that environment did not publish — read its log; db-migrate waits on it, so it shows as not run | | db-migrate: checksum mismatch | an applied migration's file changed. Never edit one; add a new migration | | db-migrate: `tables in public without row-level security …` | migration 020's check: a table in `public` (named in the message) has no RLS, so the Data API would serve it to the anon key. Nothing deployed. Enable RLS on it (and add the policies the app needs) in a new migration, or drop it, then re-run the phase | -| web `build-app`: `wire: missing wiring documents … WIRING_SUPABASE_` | the supabase apply for that environment did not publish; web waits on it, so read that lane | +| web `build-app`: `wire: missing wiring documents … WIRING_SUPABASE_`, or the web lane's secret resolution failed (`WIRING_SUPABASE`) | the supabase apply for that environment did not publish (the root lost its `secretOutputs`, or its lane was not in the plan); web waits on it, so read that lane — re-run the phase and its retouch marker re-plans the root | +| `land`: `the landing's own check failed — orun plan for …` | the placed tree does not plan; the next line is orun's own error. Nothing was pushed. Fix it (or the baseline) and re-run the phase | +| `land` waits on CI after all | the product's repository requires a status check on `main` (branch protection or a ruleset), so GitHub refused the early merge; the landing waits for the check as a `checks: ci` landing would, then merges | | web `build-app`: `wrangler secret bulk failed` | the deploy token cannot write the Worker's secrets — reconnect Cloudflare with the recipe's permission groups (Workers Scripts Write) and re-run the phase | | web smoke: `/api/health` 503 | `supabase: unreachable` — the project is paused or the URL is wrong; `schema: missing` — db-migrate did not run for that environment; `serviceRole: missing` or `invalid` — the secret push did not happen or the key is not the project's (the build-app log says which) | | `build-app` fails: `Symlink apps/web/node_modules/next is invalid, it points out of the filesystem root` | the product's intent pins stack-tectonic ≥ 0.20.0 (lane-scoped install), which Next 16's Turbopack refuses. Pin 0.19.0 — `intent.yaml` says why | diff --git a/docs/phases/02-docs.md b/docs/phases/02-docs.md index 2982c0a..a51c804 100644 --- a/docs/phases/02-docs.md +++ b/docs/phases/02-docs.md @@ -11,12 +11,11 @@ no phase may require this one.) | hook | what it does | |---|---| -| `task` (pre) | finds the phase's task and yields its key | | `promotion` | restores `environments.prod.promotion` — from now on prod deploys only after stage | | `dev-lanes` | restores dev's activation on pushes to main | -| `render` | `hooks/render-deployment-docs.sh`: probes `/` and `/api/health` on both environments, reads whether the pricing page still says Stripe is not connected, lists the secrets by name and the workspace's integrations, and regenerates `ai/context/deployment.md` and the README's live-deployment section | -| `land` | one PR, waited for and merged. It touches no component, so it deploys nothing | -| `verify` (await) | the same probe `01-product` ended on | +| `render` | `hooks/render-deployment-docs.sh`: probes `/` and `/api/health` on both environments, reads whether the pricing page still says Stripe is not connected, and regenerates `ai/context/deployment.md` — the identity, the probed URLs, the secrets the product uses by name and where each lives — and the README's live-deployment section. It asks the platform nothing: what the workspace holds right now is on the console's Secrets and Integrations pages, which the record points to | +| `task` | finds the phase's task and yields its key | +| `land` | one PR, its commit checked in the box (`checks: local`) and merged. It touches no component, so it deploys nothing — and there is nothing after it to wait for: the render's probes are the phase's check | ## Re-running it diff --git a/docs/phases/README.md b/docs/phases/README.md index 378c518..2fcd3d1 100644 --- a/docs/phases/README.md +++ b/docs/phases/README.md @@ -9,8 +9,13 @@ container the same operation as running them all. Each phase follows the same contract: -> **place its modules → brand them → land them as one pull request → watch -> the convergence that merge triggers (auto-resumed) → verify the outcome.** +> **place its modules → brand them → check them in the box and land them as +> one pull request → watch the convergence that merge triggers +> (auto-resumed) → verify the outcome.** + +The run's task set-up — the epic, a milestone per phase, a task per landing +— runs in the background from the start; the first hook that needs it, the +phase's `task`, waits for it. Run from the baseline checkout (the blueprint's source is `path: .`); the product's repository is wherever `--out` points. @@ -19,7 +24,7 @@ product's repository is wherever `--out` points. | phase | lands | verified by | |---|---|---| -| [`01-product`](01-product.md) | **the GitHub repo created**, then the WHOLE product in one PR: intent, CI, tooling, the Supabase Terraform root, the migrations, the app and its tests — one convergence provisions and deploys it in dependency order | convergence green; `SUPABASE_*` and `WIRING_SUPABASE` published on stage and prod; `/` and `/api/health` answer on both | +| [`01-product`](01-product.md) | **the GitHub repo created**, then the WHOLE product in one PR: intent, CI, tooling, the Supabase Terraform root, the migrations, the app and its tests — one convergence provisions and deploys it in dependency order | convergence green (each component resolving what the apply before it published); `/` and `/api/health` answer on both | | [`02-docs`](02-docs.md) | the live-deployment record; the promotion gate and dev's lanes put back | committed manifest matches probed reality | **One landing builds the product.** The order the data plane needs — the @@ -38,14 +43,20 @@ service-role key it hands the Worker as a secret. There is no Hyperdrive: the app reaches Supabase through supabase-js (Auth and the Data API), never as raw Postgres. `testing/placement.test.sh` reads that order off the product's own -`orun plan --trigger github-push-main`. +`orun plan --trigger github-push-main`. Each job reads them from the place +every later run looks, and a missing one fails its lane, so a green +convergence already says all of it is there — there is no separate check. Every landing is a pull request on a branch named for its task -(`orun/BASE--`). On those branches `ci.yml` runs `plan` only — the -intent, every component and every composition resolve — and skips the lanes, +(`orun/BASE--`), checked before it is pushed: `orun validate`, then +`orun plan` as the pull request and as the merge would plan it, in the box, +in under a second (`checks: local`). Then it merges; nothing waits for the +PR's CI. On those branches `ci.yml` runs `plan` only and skips the lanes, because the merge runs them on main a minute later, for real, and that -convergence is what the phase watches. `checks.yml` (install, typecheck, -lint, test, build) runs on every pull request regardless. +convergence is what the phase watches. The product carries no other +workflow: the baseline's own CI (Tier 2) installs, renders the fixture, +type-checks, lints, tests and builds this landing before a tag is cut, and +every later pull request in the product runs `ci.yml`'s verify lanes. There is no custom-domain phase: the app answers on workers.dev. Attaching a domain needs zone permissions the brokered `workers-deploy` token does not diff --git a/hooks/render-deployment-docs.sh b/hooks/render-deployment-docs.sh index c960b36..4ea666a 100755 --- a/hooks/render-deployment-docs.sh +++ b/hooks/render-deployment-docs.sh @@ -10,15 +10,22 @@ # What it writes (in ): # ai/context/deployment.md — REGENERATED: URLs with live probe results # (the app, its Supabase check, whether Stripe -# is connected yet), identity, secrets -# inventory BY NAME, integrations +# is connected yet), identity, and the secrets +# the deployment uses BY NAME # ai/context/operations.md — healed from the baseline's copy if absent # (the static operating contract; never rewritten) # README.md — the section between # is replaced (appended after the title if the # README predates the markers) # -# No secret VALUE is ever read or written here — inventories are names only. +# No secret VALUE is ever read or written here — secrets are named, not read. +# +# IT ASKS THE PLATFORM NOTHING. The record used to carry the workspace's slug, +# its secrets listed per rung and its integrations — five CLI calls, one after +# another, from the build box — and all of it is what the console shows live +# and this file could only show as it was the day it was written. The record +# keeps what the repository is the right place for: the identity the code +# names, what answered at the URLs, and where to look for the rest. set -euo pipefail out="${1:?usage: render-deployment-docs.sh }" @@ -36,10 +43,6 @@ sub="$(val subdomain)"; [ -n "$sub" ] || sub="your-workers-subdomain" [ -n "$ws" ] || ws="$(sed -n 's/^[[:space:]]*workspace:[[:space:]]*\([^[:space:]#]*\).*/\1/p' intent.yaml | head -1)" [ -n "$ws" ] || ws="?" -# Workspace slug via the direct backend read; tolerate failure. -slug="$( { orun workspace "$ws" 2>/dev/null || true; } | sed -n 's/^ *slug: *//p' | head -1)" -[ -n "$slug" ] || slug="?" - # CI lane pin (what version the deploy lanes run). lanepin="$(sed -n 's/^ *version: *\(v[0-9.]*\) *$/\1/p' .github/workflows/ci.yml 2>/dev/null | head -1)" [ -n "$lanepin" ] || lanepin="?" @@ -76,17 +79,6 @@ for pair in "stage|$stage_url" "prod|$prod_url"; do done stripe_stage="$(stripe_state "$stage_url")"; stripe_prod="$(stripe_state "$prod_url")" -secrets_list() { { orun secrets list --org "$ws" "$@" 2>/dev/null || true; } | awk 'NR>1 && NF {print " - "$1}'; } -secrets_proj="$(secrets_list --project)"; [ -n "$secrets_proj" ] || secrets_proj=" - (listing unavailable to this credential)" -secrets_stage="$(secrets_list --env stage)"; [ -n "$secrets_stage" ] || secrets_stage=" - (listing unavailable to this credential)" -secrets_prod="$(secrets_list --env prod)"; [ -n "$secrets_prod" ] || secrets_prod=" - (listing unavailable to this credential)" -integrations="$( { orun integrations list --org "$ws" --json 2>/dev/null || true; } | python3 -c " -import json,sys -try: rows=json.load(sys.stdin) -except Exception: rows=[] -out=[f\" - {r.get('provider','?')}: {r.get('status','?')}\" for r in rows] -print('\n'.join(out) if out else ' - (listing unavailable to this credential)')" )" - now="$(date -u +%Y-%m-%dT%H:%M:%SZ)" # Heal the static operating contract when the product predates it. @@ -103,15 +95,14 @@ cat > ai/context/deployment.md < GENERATED by the \`02-docs\` phase on ${now}; re-run it to refresh > (idempotent; see [operations.md](operations.md)). Hand-edits here are -> overwritten. No secret values appear in this file — inventories are names -> only. +> overwritten. No secret values appear in this file — secrets are named only. ## Identity | | | |---|---| | repository / project slug | \`${repo}\` | -| Orun workspace | \`${ws}\` (slug \`${slug}\`) | +| Orun workspace | \`${ws}\` | | declared in | \`intent.yaml\` → \`execution.state.workspace\` | | Workers | \`${brand}-web-stage\`, \`${brand}-web-prod\` on \`${sub}.workers.dev\` | | CI lane CLI pin | orun \`${lanepin}\` (\`.github/workflows/ci.yml\`) | @@ -138,27 +129,22 @@ the owner adds per environment (README, "Connect Stripe"). Everything else — sign-up, sign-in, the account page — works without them, and the pricing page shows the template's sample plans until then. -## Secrets inventory (names only) - -Project rung: -${secrets_proj} - -Environment \`stage\`: -${secrets_stage} +## Secrets (names only) -Environment \`prod\`: -${secrets_prod} - -Provider secrets are BROKERED (minted per run from the workspace's Cloudflare -and Supabase connections; no long-lived values at rest). The Supabase -project's ref, password and URL, and the app's wiring document (its URL and -API keys), are published by the Terraform apply onto the stage and prod -rungs; every deploy hands the service-role key to the Worker as a Worker -secret. - -## Workspace integrations - -${integrations} +| secret | where | what it is | +|---|---|---| +| \`CLOUDFLARE_API_TOKEN\` | the workspace | BROKERED from its Cloudflare connection (\`workers-deploy\`): deploys the app's Worker, its static assets and its service-role secret | +| \`CLOUDFLARE_ACCOUNT_ID\` | the workspace | the Cloudflare connection's account id — a fact, not a credential | +| \`SUPABASE_ACCESS_TOKEN\` | the workspace | BROKERED from its Supabase connection (\`management-access\`): creates the project, sets its Auth, and runs the migrations | +| \`SUPABASE_ORG_ID\` | the workspace | the Supabase connection's organization id — a fact, not a credential | +| \`SUPABASE_PROJECT_REF\`, \`SUPABASE_DB_PASSWORD\`, \`SUPABASE_DB_URL\` | \`${repo}\` on stage and on prod | written by the Supabase root's apply: the project's ref, its database password and its connection URL, read by the migrations | +| \`WIRING_SUPABASE\` | \`${repo}\` on stage and on prod | written by the Supabase root's apply: the project's URL, anon key and service-role key. Every deploy renders the public half into the Worker's config and hands the service-role key to the Worker as a Worker secret | + +Brokered secrets are minted per run, so no long-lived value is at rest. +Stripe's keys are Worker secrets, not workspace secrets (above). What the +workspace holds right now (every secret by name, and its integrations and +their health) is on the console's Secrets and Integrations pages for +\`${ws}\`. ## How this deployment changes @@ -173,7 +159,7 @@ import re begin, end = "", "" body = f"""{begin} This product is **live**. Verified URLs, identity, whether Stripe is connected -and the secrets inventory are recorded in +and the secrets it uses are recorded in [ai/context/deployment.md](ai/context/deployment.md) (re-rendered by the `02-docs` phase); how it deploys and how to operate it: [ai/context/operations.md](ai/context/operations.md). diff --git a/infra/db-migrate/component.yaml b/infra/db-migrate/component.yaml index 6837324..abe71eb 100644 --- a/infra/db-migrate/component.yaml +++ b/infra/db-migrate/component.yaml @@ -13,6 +13,14 @@ spec: type: db-migrate lifecycle: production owner: platform + # Its pages, attached to it in the workspace's catalog: what the Docs + # library shows for it, and what the catalog's docs and runbook checks read. + # Generated from what this manifest and its sources declare. + docs: + overview: docs/overview.md + pages: + - { path: docs/architecture.md, role: architecture, title: Architecture } + - { path: docs/runbook.md, role: runbook, title: Runbook } domain: infra # Migrations read the Supabase connection from the orun secrets the diff --git a/infra/terraform/supabase/component.yaml b/infra/terraform/supabase/component.yaml index 9248bdc..2dcfd02 100644 --- a/infra/terraform/supabase/component.yaml +++ b/infra/terraform/supabase/component.yaml @@ -12,6 +12,14 @@ spec: type: terraform lifecycle: production owner: platform + # Its pages, attached to it in the workspace's catalog: what the Docs + # library shows for it, and what the catalog's docs and runbook checks read. + # Generated from what this manifest and its sources declare. + docs: + overview: docs/overview.md + pages: + - { path: docs/architecture.md, role: architecture, title: Architecture } + - { path: docs/runbook.md, role: runbook, title: Runbook } domain: infra parameters: diff --git a/packages/db/component.yaml b/packages/db/component.yaml index d6bf94c..68d3add 100644 --- a/packages/db/component.yaml +++ b/packages/db/component.yaml @@ -7,6 +7,14 @@ spec: type: turbo-package lifecycle: production owner: platform + # Its pages, attached to it in the workspace's catalog: what the Docs + # library shows for it, and what the catalog's docs and runbook checks read. + # Generated from what this manifest and its sources declare. + docs: + overview: docs/overview.md + pages: + - { path: docs/architecture.md, role: architecture, title: Architecture } + - { path: docs/runbook.md, role: runbook, title: Runbook } domain: data subscribe: environments: diff --git a/repo-blueprint.yaml b/repo-blueprint.yaml index df72473..17ae4c2 100644 --- a/repo-blueprint.yaml +++ b/repo-blueprint.yaml @@ -193,6 +193,10 @@ modules: source: baseline from: pnpm-workspace.yaml to: pnpm-workspace.yaml + # The baseline's complete lockfile, as it is: the whole tree lands at once + # and the lockfile carries no identity, so there is nothing to re-resolve — + # the lanes install it with --frozen-lockfile, and the baseline's own CI + # (testing/e2e.test.sh) does the same on this exact tree before a tag. - name: root-pnpm-lock mode: copy source: baseline @@ -325,15 +329,23 @@ modules: # new milestone after the last, and a task naming a milestone the epic does # not have yet would create it out of order. # -# Each phase's own `pre` hook runs `orun.task/ensure@v1` on its task again. -# Same identity, so it finds rather than creates, and it is how the phase gets -# the task's KEY for its landing. (Under an orun older than v2.60, which has -# no run-level list, that hook is what creates the task — same identity, same -# result, one phase late.) +# IN THE BACKGROUND (orun >= v2.88.0, `background: true` on every hook here). +# Nothing a phase does before its landing reads the task plane — the provider +# check, the placement, the rebrand, the repository, the secrets — so the +# whole list runs beside 01-product instead of before it, in order. A hook +# that works on the plane (`orun.task/ensure@v1`, `orun.pr/land@v1`) waits +# for it to finish; a failure here stops the build at the next hook. +# +# Each phase's own `task` hook runs `orun.task/ensure@v1` on its task again, +# just before its landing. Same identity, so it finds rather than creates, +# and it is how the phase gets the task's KEY for its landing; it sits in +# `post` rather than `pre` so that everything before it overlaps with this +# list. hooks: preInstantiate: - id: epic uses: orun.task/ensure@v1 + background: true with: kind: epic slug: "{{ .inputs.epicSlug }}" @@ -349,6 +361,7 @@ hooks: owner: me - id: m01 uses: orun.task/ensure@v1 + background: true with: kind: milestone epic: "{{ .inputs.epicSlug }}" @@ -359,6 +372,7 @@ hooks: - the home page and /api/health answer on both workers.dev URLs - id: m02 uses: orun.task/ensure@v1 + background: true with: kind: milestone epic: "{{ .inputs.epicSlug }}" @@ -368,6 +382,7 @@ hooks: - prod waits on stage again, and dev verifies every merge to main again - id: t01 uses: orun.task/ensure@v1 + background: true with: kind: task epic: "{{ .inputs.epicSlug }}" @@ -384,6 +399,7 @@ hooks: contract: .baseline/tasks/01-product.TaskContract.yaml - id: t02 uses: orun.task/ensure@v1 + background: true with: kind: task epic: "{{ .inputs.epicSlug }}" @@ -420,7 +436,15 @@ phases: - name: 01-product title: The product, built in one landing description: The whole tree — manifests, CI, tooling, the Supabase root, the migrations, the app and its tests — branded, landed as one pull request, and provisioned and deployed by one convergence. - expectedMinutes: 16 + # An estimate, not a measurement: no bootstrap of this baseline has been + # timed. The convergence is most of it — a Supabase project takes five to + # seven minutes to come up, then the migrations and the app's build, + # deploy and smoke, stage and prod side by side. One minute less than + # before the v2.88.0 shape: on turso-starter's measured build that shape + # takes about a minute out of the same steps — the task set-up in the + # background, the landing checked in the box instead of by a runner, the + # watch reading every 5 s instead of 40. + expectedMinutes: 15 narrate: start: "Creating the repository and landing the whole product in one pull request — the app, its migrations, and the Terraform for a Supabase project per environment. Then one convergence provisions and deploys it in order. Usually about {{ .meta.expectedMinutes }} minutes." await: "One convergence is running per environment: the Supabase project first (five to seven minutes to come up), then the migrations, then the app. Nothing is stuck." @@ -444,19 +468,6 @@ phases: waitSeconds: 600 pollSeconds: 20 hooks: - pre: - # The epic, every milestone and every task already exist (the - # run-level list above). This finds the task and yields its key, which - # the landing binds the pull request to. - - id: task - uses: orun.task/ensure@v1 - with: - kind: task - epic: "{{ .inputs.epicSlug }}" - milestone: "{{ .phase.name }}" - name: "Build the product in one landing" - prefix: BASE - contract: .baseline/tasks/01-product.TaskContract.yaml post: # A RE-RUN MUST HAVE SOMETHING TO LAND. A convergence can fail AFTER # its PR merged, and the merge has already put every file on main; @@ -530,11 +541,6 @@ phases: run: ["git", "add", "-A"] - id: rebrand-verify run: ["node", "{{ .baseline.dir }}/tooling/rebrand/rebrand.mjs", "--verify", "--values", ".rebrand/values.json"] - # root-pnpm-lock placed the baseline's complete lockfile and the whole - # tree is here, so this only confirms it — the Checks and every lane - # install with --frozen-lockfile. - - id: pnpm-lockfile - run: ["pnpm", "install", "--lockfile-only"] # The repo has to exist before there is anywhere to land. - id: repo uses: orun.repo/ensure@v1 @@ -563,11 +569,14 @@ phases: - link - "{{ .inputs.orunWorkspace }}" - "{{ .inputs.githuborg }}/{{ .inputs.reponame }}" - # The provider credentials, brokered, one hook per template: - # `integrations/reconcile` mints from ONE connection with ONE scope - # template, so these four keys are four hooks. Keys that already exist - # are kept. After the link, before the landing whose convergence uses - # them: + # The provider credentials, brokered, in ONE hook PER PROVIDER (orun + # >= v2.87.0): `secrets` mints each key under its own scope template + # from the one connection of that provider the build is bound to, + # reading the connections and the existing secrets once and creating + # the missing keys side by side. Two hooks, because a reconcile reads + # one connection: Cloudflare's two keys, then Supabase's two. Keys that + # already exist are kept. After the link, before the landing whose + # convergence uses them: # CLOUDFLARE_API_TOKEN web's deploy (the composition's binding), # and the Worker secret it pushes # CLOUDFLARE_ACCOUNT_ID web's deploy @@ -577,36 +586,44 @@ phases: # as Postgres. Stripe's keys are not minted: no connection brokers # them, and the product deploys without them (its README, "Connect # Stripe"). - - id: secret-workers-deploy - uses: orun.integrations/reconcile@v1 - with: - provider: cloudflare - keys: [CLOUDFLARE_API_TOKEN] - template: workers-deploy - - id: secret-account-id + - id: secrets-cloudflare uses: orun.integrations/reconcile@v1 with: provider: cloudflare - keys: [CLOUDFLARE_ACCOUNT_ID] - template: account-id - - id: secret-supabase-access + secrets: + - { key: CLOUDFLARE_API_TOKEN, template: workers-deploy } + - { key: CLOUDFLARE_ACCOUNT_ID, template: account-id } + - id: secrets-supabase uses: orun.integrations/reconcile@v1 with: provider: supabase - keys: [SUPABASE_ACCESS_TOKEN] - template: management-access - - id: secret-supabase-org - uses: orun.integrations/reconcile@v1 + secrets: + - { key: SUPABASE_ACCESS_TOKEN, template: management-access } + - { key: SUPABASE_ORG_ID, template: org-id } + # The task this landing closes, and its key. The run-level list above + # opens it in the background; this is the first hook that needs it, + # so it is the one that waits for that list (orun >= v2.88.0) — every + # hook before it ran while the task plane was still being set up. + - id: task + uses: orun.task/ensure@v1 with: - provider: supabase - keys: [SUPABASE_ORG_ID] - template: org-id - # THE PRODUCT IS A PULL REQUEST THAT IS CHECKED, THEN MERGED. This - # landing waits for its PR's whole CI run (orun >= v2.58.6): Checks - # (install, typecheck, lint, test, build) and `plan` — on a bootstrap - # branch (`orun/BASE-…`) the lanes are skipped (ci.yml), because the - # merge runs every one of them on main a minute later, for real, and - # the convergence after the merge is what this phase watches to green. + kind: task + epic: "{{ .inputs.epicSlug }}" + milestone: "{{ .phase.name }}" + name: "Build the product in one landing" + prefix: BASE + contract: .baseline/tasks/01-product.TaskContract.yaml + # THE PRODUCT IS A PULL REQUEST THAT IS CHECKED, THEN MERGED — checked + # HERE (`checks: local`, orun >= v2.88.0): `orun validate`, then + # `orun plan` as the pull request and as the merge to main plan it, + # on the commit, before it is pushed. That is what the PR's `plan` + # job checks (the intent, every component and every composition + # resolve), plus the merge's own plan, in under a second instead of a + # runner's ~25 s. A tree that fails is never pushed. The PR's CI still + # runs (`plan` alone on a bootstrap branch, `orun/BASE-…`, ci.yml); + # nothing waits for it. The merge runs every lane on main a minute + # later, for real, and the convergence after it is what this phase + # watches to green. - id: land uses: orun.pr/land@v1 narrate: "The product is merged into main." @@ -615,6 +632,7 @@ phases: epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "feat: {{ .inputs.productname }}, the whole product from the subscription-payments baseline" + checks: local await: - id: converge uses: orun.run/watch@v1 @@ -628,18 +646,23 @@ phases: repo: "{{ .inputs.githuborg }}/{{ .inputs.reponame }}" resumeBudget: 3 waitSeconds: 3600 - # WHERE THE OUTPUTS ARE PUBLISHED: each apply lease-publishes its - # outputs to the project's ENVIRONMENT rungs (stage and prod), not to - # the workspace. The Supabase project's three, which db-migrate reads, - # and WIRING_SUPABASE — its URL, anon key and service-role key — which - # the app's deploy renders and pushes. - - id: wiring - uses: orun.secrets/exists@v1 - narrate: "The Supabase credentials and the app's Supabase wiring are published on stage and prod." - with: - keys: [SUPABASE_PROJECT_REF, SUPABASE_DB_PASSWORD, SUPABASE_DB_URL, WIRING_SUPABASE] - project: "{{ .inputs.reponame }}" - environments: [stage, prod] + # Read every 5 s, not the action's 40: the build goes on the + # moment the run is green instead of up to 40 s after it. + pollSeconds: 5 + # NO SEPARATE CHECK OF WHAT THE APPLY PUBLISHES. The supabase apply + # lease-publishes its outputs to the project's stage and prod rungs, + # and every one of the four is resolved IN THIS CONVERGENCE, from the + # place every later run looks (the readers' component.yaml + # `secretEnv`, fail-closed when a job starts), by a job that waits for + # the supabase apply on main (`mode: enforced`): + # SUPABASE_PROJECT_REF, SUPABASE_DB_PASSWORD, SUPABASE_DB_URL + # db-migrate, per environment + # WIRING_SUPABASE web's deploy — its URL, anon key and + # service-role key — each environment's own + # A missing document fails that lane, so a green run already says all + # four are there. testing/phases.test.sh fails if one of them loses + # its reader, and asks for an `orun.secrets/exists@v1` await again for + # any key nothing in the convergence reads. - id: verify uses: orun.http/probe@v1 narrate: "The app and its Supabase check answered on stage and prod." @@ -651,31 +674,22 @@ phases: - "https://{{ .inputs.reponame }}-web-prod.{{ .inputs.subdomain }}.workers.dev/api/health" # Places nothing. It records what 01-product built, from PROBED facts rather - # than from what the blueprint intended — which is why it runs last and why - # its verify is the probe 01-product ends on. + # than from what the blueprint intended — which is why it runs last. Its + # render probes every URL as it writes the record, and this landing + # redeploys nothing, so there is no probe after it to wait for. - name: 02-docs title: The deployment, recorded description: The live-deployment manifest, rendered from probed reality, and the promotion gate and dev's lanes put back. - expectedMinutes: 2 + # An estimate: the render's probes, a landing checked in the box, a merge. + expectedMinutes: 1 narrate: start: "Now recording what was actually built — probing every URL, noting whether Stripe is connected yet, and writing the deployment manifest into the repository." - await: "Probing the live endpoints one last time." done: "ai/context/deployment.md now records the live deployment, written from probed facts, and prod waits on stage again. {{ .meta.elapsed }}." failed: "The deployment record did not land. The product is still live; only the write-up is missing." modules: [] requires: phases: [01-product] hooks: - pre: - - id: task - uses: orun.task/ensure@v1 - with: - kind: task - epic: "{{ .inputs.epicSlug }}" - milestone: "{{ .phase.name }}" - name: "Record the live deployment" - prefix: BASE - contract: .baseline/tasks/02-docs.TaskContract.yaml post: # THE PRODUCT GOES LIVE WITH ITS PROMOTION GATE. 01-product deferred # `prod.promotion.dependsOn: [stage]`; this, the last landing, puts it @@ -690,6 +704,16 @@ phases: run: ["node", "{{ .baseline.dir }}/tooling/bootstrap/dev-lanes.mjs", "--restore"] - id: render run: ["bash", "{{ .baseline.dir }}/hooks/render-deployment-docs.sh", ".", "{{ .inputs.orunWorkspace }}", "{{ .baseline.dir }}"] + - id: task + uses: orun.task/ensure@v1 + with: + kind: task + epic: "{{ .inputs.epicSlug }}" + milestone: "{{ .phase.name }}" + name: "Record the live deployment" + prefix: BASE + contract: .baseline/tasks/02-docs.TaskContract.yaml + # Checked here and merged, as 01-product's landing is. - id: land uses: orun.pr/land@v1 narrate: "The deployment record is merged into main." @@ -698,13 +722,4 @@ phases: epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "docs(deployment): record the live deployment state" - await: - - id: verify - uses: orun.http/probe@v1 - narrate: "Every live URL answered on the final probe." - with: - urls: - - "https://{{ .inputs.reponame }}-web-stage.{{ .inputs.subdomain }}.workers.dev" - - "https://{{ .inputs.reponame }}-web-stage.{{ .inputs.subdomain }}.workers.dev/api/health" - - "https://{{ .inputs.reponame }}-web-prod.{{ .inputs.subdomain }}.workers.dev" - - "https://{{ .inputs.reponame }}-web-prod.{{ .inputs.subdomain }}.workers.dev/api/health" + checks: local diff --git a/testing/coverage.test.sh b/testing/coverage.test.sh index 1ee1577..6b1cd50 100755 --- a/testing/coverage.test.sh +++ b/testing/coverage.test.sh @@ -95,6 +95,46 @@ for comp in BASELINE_ONLY: if not (root / comp).exists(): bad(f"{comp} is declared baseline-only and does not exist — drop the entry") +# ── WHAT THE CATALOG SEES OF EACH COMPONENT ─────────────────────────────── +# +# Every component ships its generated pages (overview, architecture, runbook) +# and must ATTACH them in `spec.docs`: a `docs/` folder no manifest declares is +# never attached, so a fresh product's Docs library showed nothing for any +# component and the catalog failed every one of them on docs and on runbook. +# A component also needs a description: it is the catalog's one-line answer to +# "what is this", and the two test suites had none. +# +# And a domain may not share a component's name. The catalog keys entities by +# name, so the `web` domain (`spec.domain: web`) took the `web` component's +# place, and the product's one deployable was missing from its own catalog. +WANT_DOCS = {"overview": "docs/overview.md", "architecture": "docs/architecture.md", "runbook": "docs/runbook.md"} +names, domains = {}, {} +for comp in components: + if comp in BASELINE_ONLY: + continue + doc = yaml.safe_load((root / comp / "component.yaml").read_text()) or {} + meta, spec = doc.get("metadata") or {}, doc.get("spec") or {} + names[meta.get("name")] = comp + for domain in (spec.get("domain"), (meta.get("labels") or {}).get("domain")): + if domain: + domains.setdefault(domain, comp) + if not (meta.get("description") or "").strip(): + bad(f"{comp}/component.yaml has no metadata.description — the catalog shows the component with nothing to say") + docs = spec.get("docs") or {} + got = {"overview": docs.get("overview")} + for page in docs.get("pages") or []: + got[page.get("role")] = page.get("path") + for role, path in WANT_DOCS.items(): + if got.get(role) != path: + bad(f"{comp}/component.yaml does not attach {path} as its {role} " + f"(spec.docs) — the page ships and the catalog never sees it") + elif not (root / comp / path).is_file(): + bad(f"{comp}/component.yaml attaches {path}, which does not exist") +for domain, comp in sorted(domains.items()): + if domain in names: + bad(f"{comp} declares domain `{domain}`, which is also the name of the " + f"component in {names[domain]} — the catalog keeps one of the two") + # ── WHAT `ignore` ACTUALLY EXCLUDES (BE6) ────────────────────────────────── # # orun matches an ignore entry two ways, and WHICH ONE depends on the entry: diff --git a/testing/e2e.test.sh b/testing/e2e.test.sh index 66d374b..54ad6a4 100644 --- a/testing/e2e.test.sh +++ b/testing/e2e.test.sh @@ -8,11 +8,13 @@ # and that its own plan converges in the right order. This proves it WORKS, # by doing to it what its own pipelines will: # -# 1. at the 01-product landing (the commit its PR merges), run what -# `checks.yml` runs on that PR — install with the lockfile the phase -# placed, render the wrangler fixture (which must change nothing: the -# render is committed), typecheck, lint, test, build. That landing WAITS -# on its checks; +# 1. at the 01-product landing (the commit its PR merges), install with the +# lockfile the product ships, render the wrangler fixture (which must +# change nothing: the render is committed), typecheck, lint, test, build. +# The landing itself is checked in the build box with `orun validate` +# and `orun plan` alone (`checks: local`), and its PR runs `plan` alone +# (an `orun/BASE-*` branch), so THIS is where a product those steps +# refuse is caught: before the tag, not after a build has merged it; # 2. a Supabase project's API on this machine: a Postgres of its own on a # random port with Supabase's roles (testing/lib/local-postgres.sh), and # on it the REAL Supabase Auth (GoTrue) and Data API (PostgREST) — pinned @@ -117,24 +119,25 @@ repo="$(python3 -c "import json,sys;print(json.load(open(sys.argv[1]))['reponame sub="$(python3 -c "import json,sys;print(json.load(open(sys.argv[1]))['subdomain'])" "$values")" export CI=1 WRANGLER_SEND_METRICS=false NEXT_TELEMETRY_DISABLED=1 TURBO_TELEMETRY_DISABLED=1 -# What checks.yml runs, step for step, read out of the workflow the product -# carries so the two cannot drift: every `run:` of its one job, in order. +# The landing's own checks, step for step — what the product's Checks +# workflow ran on a pull request before the product carried ci.yml alone — +# run here at once on the whole tree. +LANDING_CHECKS=( + "pnpm install --frozen-lockfile" + "pnpm run wire:fixture" + "pnpm typecheck" + "pnpm lint" + "pnpm test" + "pnpm build" +) checks() { # DIR LOG local dir="$1" log="$2" cmd - while IFS= read -r cmd; do + for cmd in "${LANDING_CHECKS[@]}"; do echo " \$ $cmd" | tee -a "$log" if ! (cd "$dir" && bash -c "$cmd") >> "$log" 2>&1; then echo "FAIL: \`$cmd\` failed in $dir" >&2; tail -40 "$log" >&2; return 1 fi - done < <(python3 - "$dir/.github/workflows/checks.yml" <<'PY' -import sys, yaml -wf = yaml.safe_load(open(sys.argv[1])) -for job in wf["jobs"].values(): - for step in job["steps"]: - if "run" in step: - print(step["run"].strip()) -PY -) + done } # One job of a plan, written out as the runner would run it: each `run:` step @@ -184,7 +187,7 @@ bootstrap_offline "$root" "$tree" "$values" "$scratch/logs" > "$scratch/bootstra echo " 2 phases placed and landed" # ── 1. the product's own pull request ────────────────────────────────────── -echo "── 01-product's landing, under the checks its PR waits on" +echo "── 01-product's landing: install, the fixture render, typecheck, lint, test, build" s01="$(git -C "$tree" rev-parse HEAD~1)" at01="$scratch/at-01/$repo" git -C "$tree" worktree add -q "$at01" "$s01" @@ -233,10 +236,11 @@ git -C "$prtree" checkout -q main (cd "$prtree" && orun plan --intent intent.yaml --trigger github-pull-request --base empty --head HEAD --env stage \ --output "$scratch/plan-pr.json") > "$scratch/plan-pr.log" 2>&1 \ || { echo "FAIL: orun plan (pull request)" >&2; tail -15 "$scratch/plan-pr.log" >&2; exit 1; } -# This tier runs the orun the product's CI pins, which reads the per-edge -# `modeRules`: on a pull request — which applies and deploys nothing — the -# infrastructure edges that order a push to main are advisory, so no lane -# waits on another. (placement.test.sh checks the push to main's order.) +# This tier runs the bootstrap floor, newer than the orun the product's CI +# pins, and both read the per-edge `modeRules`: on a pull request — which +# applies and deploys nothing — the infrastructure edges that order a push to +# main are advisory, so no lane waits on another. (placement.test.sh checks +# the push to main's order.) python3 - "$scratch/plan-pr.json" <<'PY' import json, sys jobs = {j["component"]: j for j in json.load(open(sys.argv[1]))["jobs"] if j["environment"] == "stage"} diff --git a/testing/leak.test.sh b/testing/leak.test.sh index e292459..6b6d98f 100755 --- a/testing/leak.test.sh +++ b/testing/leak.test.sh @@ -93,7 +93,7 @@ for p in placed: if "README.md" not in placed: bad("README.md would not ship") MUST = ( - ".github/workflows/ci.yml", ".github/workflows/checks.yml", ".rebrand/values.json", + ".github/workflows/ci.yml", ".rebrand/values.json", "apps/web/component.yaml", "apps/web/utils/site.ts", "apps/web/utils/stripe/config.ts", "apps/web/utils/stripe/sample-plans.ts", "apps/web/next.config.mjs", # COMMITTED, because the composition checks it exists before the build: diff --git a/testing/lib/bootstrap.sh b/testing/lib/bootstrap.sh index b4a75f7..9ecb534 100755 --- a/testing/lib/bootstrap.sh +++ b/testing/lib/bootstrap.sh @@ -14,8 +14,8 @@ # workspace; # - `{{ .inputs.* }}` render from the fixture. # Everything else — the retouch marker, the rebrand, the re-tenant, the -# work-tree strip, the deferrals and their restore, the lockfile, the -# deployment-docs render — runs exactly as declared. +# work-tree strip, the deferrals and their restore, the deployment-docs +# render — runs exactly as declared. # # The output directory starts EMPTY, as a real one does: no discovery root is # made here, so a phase that leaves orun's repo-scale gate one to find (apps/, diff --git a/testing/manifest.test.sh b/testing/manifest.test.sh index 5374cb5..64f04c8 100755 --- a/testing/manifest.test.sh +++ b/testing/manifest.test.sh @@ -83,13 +83,16 @@ def uses(phase, action): yield hook # THE SECRETS THE BOOTSTRAP MINTS. `orun.integrations/reconcile@v1` is what -# `create-secrets.sh` was written out longhand as: one connection, one scope -# template, the keys it ensures. Read per key so a hook minting two keys under -# one template is three facts rather than one. +# `create-secrets.sh` was written out longhand as: one connection, and per key +# the scope template it is minted under — `secrets: [{key, template}]`, or +# `keys` sharing one `template`. Read per key so a hook minting three keys is +# three facts rather than one. blueprint_secrets = {} for phase in bp_phases: for hook in uses(phase, "orun.integrations/reconcile@v1"): w = hook.get("with") or {} + for item in (w.get("secrets") or []): + blueprint_secrets[item.get("key")] = (w.get("provider"), item.get("template")) for key in (w.get("keys") or []): blueprint_secrets[key] = (w.get("provider"), w.get("template")) diff --git a/testing/phases.test.sh b/testing/phases.test.sh index 121cb86..405a7e3 100755 --- a/testing/phases.test.sh +++ b/testing/phases.test.sh @@ -19,6 +19,17 @@ # reads the restaged tree, the credentials are minted after the link and # before the landing whose convergence uses them), and a reorder fails live. # +# What the applies publish is not checked by a separate await: every key is +# resolved in the convergence, when a job starts, by a component that waits +# for its publisher on main — so a green convergence says the key is there, +# from the place every later run looks. This file holds that for each key, +# and asks for an `orun.secrets/exists@v1` await for any key nothing reads. +# +# And the shape that keeps a bootstrap fast (orun >= v2.88.0): the run-level +# task set-up runs in the background, each phase finds its task just before +# its landing, each landing checks its commit here (`checks: local`), and the +# convergence watch reads every few seconds. +# # Adapted from sourceplane/cirrus-baseline's testing/phases.test.sh: the # narration rules and the hook-only rule are Cirrus's, unchanged. # @@ -56,16 +67,20 @@ HOOK_ONLY = {"02-docs"} # The phase that DEPLOYS, and so must give a re-run something to land. DEPLOYS = {"01-product"} +# No phase has a `pre` hook: the task is found in `post`, just before the +# landing, so that everything before it runs beside the background task +# set-up. +PRE = {"01-product": [], "02-docs": []} # The post hooks, in the order they must run (the brief's chain): the # re-run marker and the git index; the rebrand and the re-tenant; the three # rewrites a product needs before it lands; the restage and the verify; the -# lockfile; the repository and its link; one brokered reconcile per key; -# the landing. `secret-*` stands for the reconcile hooks, checked below. +# repository and its link; one brokered `secrets` reconcile per provider +# (checked below); the task, then the landing. POST_ORDER = { "01-product": ["retouch", "git-init", "stage", "rebrand", "orun-workspace", "work-tree", "promotion", "dev-lanes", "restage", "rebrand-verify", - "pnpm-lockfile", "repo", "link", "secret-*", "land"], - "02-docs": ["promotion", "dev-lanes", "render", "land"], + "repo", "link", "secrets-cloudflare", "secrets-supabase", "task", "land"], + "02-docs": ["promotion", "dev-lanes", "render", "task", "land"], } # The scripts behind the run: hooks that rewrite intent.yaml, with the mode # each must be called in. @@ -77,8 +92,12 @@ RUNS = { ("02-docs", "dev-lanes"): ("tooling/bootstrap/dev-lanes.mjs", "--restore"), ("02-docs", "render"): ("hooks/render-deployment-docs.sh", None), } -AWAIT_ORDER = {"01-product": ["orun.run/watch@", "orun.secrets/exists@", "orun.http/probe@"], - "02-docs": ["orun.http/probe@"]} +# 01-product watches its convergence and probes the app; it awaits nothing +# the convergence already proved (below — a published key nothing reads puts +# an `orun.secrets/exists@` between the two). 02-docs awaits nothing: its +# render probes as it writes, and its landing redeploys nothing. +AWAIT_ORDER = {"01-product": ["orun.run/watch@", "orun.http/probe@"], + "02-docs": []} by_name = {p["name"]: p for p in phases} names = [p["name"] for p in phases] @@ -144,26 +163,41 @@ def hooks_of(p): run_hooks = list((bp.get("hooks") or {}).get("preInstantiate") or []) # ── the hook chain, in order ────────────────────────────────────────────── +for name, want in PRE.items(): + got = [h.get("id") for h in ((by_name.get(name, {}).get("hooks") or {}).get("pre") or [])] + if got != want: + bad(f"phase {name}'s pre hooks are {got}; want {want} — a task found in `pre` waits " + f"for the background task set-up before the phase has done anything") for name, want in POST_ORDER.items(): p = by_name.get(name) if not p: continue post = (p.get("hooks") or {}).get("post") or [] ids = [h.get("id") for h in post] - folded = [] - for i in ids: - tok = "secret-*" if (i or "").startswith("secret-") else i - if not folded or folded[-1] != tok: - folded.append(tok) - if folded != want: + if ids != want: bad(f"phase {name}'s post hooks run {ids}; the chain is {want}") + # THE BROKERED KEYS, ONE `secrets` RECONCILE PER PROVIDER (orun >= v2.87.0): + # each key under its own scope template, the connections and the existing + # secrets read once per hook, the missing keys created side by side. A + # reconcile reads one connection, so two providers are two hooks; two + # hooks whose other parameters are the same are one hook written twice. + shared = {} for h in post: - if (h.get("id") or "").startswith("secret-") and not (h.get("uses") or "").startswith("orun.integrations/reconcile@"): + if (h.get("id") or "").startswith("secrets") and not (h.get("uses") or "").startswith("orun.integrations/reconcile@"): bad(f"phase {name} hook {h.get('id')} is not an orun.integrations/reconcile@v1") - if (h.get("uses") or "").startswith("orun.integrations/reconcile@"): - keys = (h.get("with") or {}).get("keys") or [] - if len(keys) != 1: - bad(f"phase {name} hook {h.get('id')} reconciles {keys} — one key per hook, one scope per key") + if not (h.get("uses") or "").startswith("orun.integrations/reconcile@"): + continue + w = h.get("with") or {} + if "keys" in w or "template" in w or not w.get("secrets"): + bad(f"phase {name} hook {h.get('id')} does not use the `secrets: [{{key, template}}]` form — " + f"one template per hook reads the connections and the secrets once per key") + if h.get("id") != f"secrets-{w.get('provider')}": + bad(f"phase {name} hook {h.get('id')} mints from {w.get('provider')}; name it secrets-{w.get('provider')}") + same = tuple(sorted((k, str(v)) for k, v in w.items() if k != "secrets")) + if same in shared: + bad(f"phase {name} hooks {shared[same]} and {h.get('id')} take the same parameters {dict(same)} — " + f"merge them into one `secrets` list") + shared.setdefault(same, h.get("id")) for (ph, hid), (script, mode) in RUNS.items(): if ph != name: continue @@ -171,36 +205,87 @@ for name, want in POST_ORDER.items(): argv = " ".join((hook or {}).get("run") or []) if script not in argv or (mode and mode not in argv): bad(f"phase {name} hook {hid} must run {script} {mode or ''}".rstrip()) -for name, want in AWAIT_ORDER.items(): - awaits = ((by_name.get(name) or {}).get("hooks") or {}).get("await") or [] - got = [h.get("uses") or "" for h in awaits] - if len(got) != len(want) or not all(g.startswith(w) for g, w in zip(got, want)): - bad(f"phase {name}'s await hooks are {got}; they must be {want} (in that order)") -# ── the await checks what the infrastructure publishes, on stage and prod ─ -# Each infra component's `secretOutputs` is what its apply lease-publishes; -# the landing's `orun.secrets/exists@v1` must ask for exactly those keys — -# every WIRING_* document and the Supabase project's credentials — on the -# environments that apply them. -published = set() -for comp in sorted(root.glob("infra/**/component.yaml")): - params = ((yaml.safe_load(comp.read_text()) or {}).get("spec") or {}).get("parameters") or {} - for pair in str(params.get("secretOutputs") or "").split(","): +# ── what the infrastructure publishes is read in the convergence ────────── +# Each infra component's `secretOutputs` is what its apply lease-publishes to +# the project's stage and prod rungs. A key is PROVED by the convergence when +# a component resolves it from that place as its job starts (a `secretEnv` +# reference, fail-closed: a missing document fails the lane) and waits for +# the publisher on a merge to main (`mode: enforced`, advisory on a pull +# request), on both stage and prod. Such a key needs no await; a key nothing +# reads that way must be awaited with `orun.secrets/exists@v1` on stage and +# prod in 01-product — and a key the convergence already proves must not be, +# because that await is a platform round trip that can only agree. +comps = {} +for f in root.rglob("component.yaml"): + if "node_modules" in f.parts: + continue + d = yaml.safe_load(f.read_text()) or {} + comps[(d.get("metadata") or {}).get("name")] = (f.relative_to(root).as_posix(), d.get("spec") or {}) +def enforced_on_main(spec, target): + edge = next((d for d in spec.get("dependsOn") or [] if d.get("component") == target), None) + rules = (edge or {}).get("modeRules") or [] + return bool(edge) and edge.get("mode") == "enforced" and any( + r.get("mode") == "advisory" and (r.get("when") or {}).get("triggerRef") == "github-pull-request" + for r in rules) +published = {} +for name, (rel, spec) in comps.items(): + for pair in str((spec.get("parameters") or {}).get("secretOutputs") or "").split(","): if "=" in pair: - published.add(pair.split("=", 1)[0].strip()) + published[pair.split("=", 1)[0].strip()] = name if not published: bad("no infra component declares secretOutputs — this check has gone blind") +proved, readers_of = set(), {} +for key, pub in sorted(published.items()): + covered = set() + for name, (rel, spec) in comps.items(): + if name == pub: + continue + subs = (spec.get("subscribe") or {}).get("environments") or [] + subscribed = {e.get("name") for e in subs} + # A reference in the component's own `secretEnv` is resolved by the job + # of every environment it subscribes; one under a subscription (the + # app's WIRING_SUPABASE, each environment its own) only by that + # environment's job. orun merges both into the job's secrets. + refs = [(ref, subscribed) for ref in (spec.get("secretEnv") or {}).values()] + refs += [(ref, {e.get("name")}) for e in subs for ref in (e.get("secretEnv") or {}).values()] + for ref, jobs in refs: + m = re.fullmatch(r"secret://[^/]+/[^/]+/([^/]+)/([A-Z0-9_]+)", str(ref)) + if not m or m.group(2) != key: + continue + readers_of.setdefault(key, set()).add(name) + if not enforced_on_main(spec, pub): + bad(f"{rel} resolves {key} and does not wait for {pub} on a merge to main — declare " + f"dependsOn {pub} with mode: enforced and a modeRules advisory on github-pull-request") + continue + env = m.group(1) + on = jobs & {"stage", "prod"} + covered |= on if "{{" in env else ({env} if on and env in ("stage", "prod") else set()) + if covered >= {"stage", "prod"}: + proved.add(key) awaits = ((by_name.get("01-product") or {}).get("hooks") or {}).get("await") or [] exists = [h for h in awaits if (h.get("uses") or "").startswith("orun.secrets/exists@")] -if exists: - w = exists[0].get("with") or {} - if set(w.get("keys") or []) != published: - bad(f"01-product awaits secrets {sorted(w.get('keys') or [])}; the infrastructure " - f"publishes {sorted(published)}") +awaited = {k for h in exists for k in ((h.get("with") or {}).get("keys") or [])} +if set(published) - proved - awaited: + bad(f"01-product neither reads nor awaits {sorted(set(published) - proved - awaited)} — nothing in " + f"the convergence resolves it on stage and prod, so await it with orun.secrets/exists@v1") +if awaited & proved: + bad(f"01-product awaits {sorted(awaited & proved)}, which the convergence already resolves " + f"({', '.join(sorted({r for k in awaited & proved for r in readers_of.get(k, ())}))}) — drop them") +for h in exists: + w = h.get("with") or {} if sorted(w.get("environments") or []) != ["prod", "stage"]: bad(f"01-product awaits the published secrets on {w.get('environments')}, not stage and prod") if w.get("project") != "{{ .inputs.reponame }}": bad("01-product awaits the published secrets in another project than the product's") +# A key nothing reads is awaited between the watch and the probe. +if set(published) - proved: + AWAIT_ORDER["01-product"] = ["orun.run/watch@", "orun.secrets/exists@", "orun.http/probe@"] +for name, want in AWAIT_ORDER.items(): + awaits = ((by_name.get(name) or {}).get("hooks") or {}).get("await") or [] + got = [h.get("uses") or "" for h in awaits] + if len(got) != len(want) or not all(g.startswith(w) for g, w in zip(got, want)): + bad(f"phase {name}'s await hooks are {got}; they must be {want} (in that order)") for name in names: for h in ((by_name[name].get("hooks") or {}).get("await") or []): if (h.get("uses") or "").startswith("orun.http/probe@"): @@ -233,6 +318,43 @@ for p in phases: bad(f"phase {p['name']} deploys and does not watch the convergence of the " f"commit it merged (orun.run/watch@v1 with sha: mergeSha)") +# ── THE FAST SHAPE (orun >= v2.88.0) ────────────────────────────────────── +# The run-level list is the task set-up, all of it in the background: the +# first phase's provider check, placement, rebrand, repository and secrets +# run while it opens the epic, the milestones and the tasks. +for h in run_hooks: + if not h.get("background"): + bad(f"hooks.preInstantiate {h.get('id')} is not `background: true` — the first phase " + f"waits for it before doing anything, though nothing before its landing reads it") +# No phase reaches the task plane in `pre`: that waits for the background at +# once, before the phase has placed a file — the old order. +for p in phases: + for h in ((p.get("hooks") or {}).get("pre") or []): + if (h.get("uses") or "").startswith(("orun.task/", "orun.pr/")): + bad(f"phase {p['name']} pre hook {h.get('id')} uses {h['uses']} — find the task in " + f"`post`, just before the landing") +# Every landing checks its commit here and merges, instead of waiting ~25 s +# for a runner to plan the tree this box just wrote. +for p in phases: + for h in hooks_of(p): + if (h.get("uses") or "").startswith("orun.pr/land@") and (h.get("with") or {}).get("checks") != "local": + bad(f"phase {p['name']} lands with checks {(h.get('with') or {}).get('checks', 'ci')!r}, " + f"not 'local' — it waits for a runner to plan a tree that is here") +# The convergence watch reads every few seconds, not the action's default 40. +for p in phases: + for h in ((p.get("hooks") or {}).get("await") or []): + if (h.get("uses") or "").startswith("orun.run/watch@"): + every = (h.get("with") or {}).get("pollSeconds") + if not isinstance(every, int) or every > 10: + bad(f"phase {p['name']} watches its convergence every {every or 40} s; at most 10 — " + f"the build goes on that much after the run is green") +# The shipped lockfile is installed frozen by the lanes and by the baseline's +# e2e tier; a hook re-resolving it is a minute of network for nothing. +for p in phases: + for h in hooks_of(p): + if "--lockfile-only" in (h.get("run") or []): + bad(f"phase {p['name']} hook {h.get('id')} re-resolves the lockfile the baseline ships") + # ── every phase's task is one the run-level list opens, in the same order ─ def task_names(hooks): return [(h.get("with") or {}).get("name") for h in hooks @@ -329,8 +451,15 @@ def check_line(where, line, slot, hook_ids): for p in phases: n = p.get("narrate") or {} ids = {h.get("id") for h in hooks_of(p)} + awaits = bool((p.get("hooks") or {}).get("await")) for slot in ("start", "await", "done", "failed"): line = n.get(slot) + if slot == "await" and not awaits: + # A phase that waits on nothing never says its await line. + if line: + bad(f"phase {p['name']} declares narrate.await and has no await hooks — " + f"nobody would ever read it") + continue if not line: bad(f"phase {p['name']} declares no narrate.{slot}") continue @@ -361,7 +490,9 @@ placed_n = sum(len(p.get("modules") or []) for p in phases) narrated = sum(len(p.get("narrate") or {}) for p in phases) narrated += sum(1 for p in phases for h in hooks_of(p) if h.get("narrate")) print(f" {len(phases)} phases, {placed_n} modules (all in 01-product), {len(HOOK_ONLY)} hook-only — in execution order") -print(f" the hook chain in order; 01-product awaits {sorted(published)} on stage and prod") +print(f" the hook chain in order; the convergence resolves {sorted(proved)} on stage and prod, " + f"each from a job that waits for its publisher" + (f"; 01-product awaits {sorted(awaited)}" if awaited else "")) +print(f" the fast shape: the task set-up in the background, no `pre` hook, every landing checks: local") print(f" {narrated} authored narration lines, every reference resolving") PY diff --git a/testing/placement.test.sh b/testing/placement.test.sh index 838b353..20ace6c 100644 --- a/testing/placement.test.sh +++ b/testing/placement.test.sh @@ -12,7 +12,7 @@ # 2. THE OFFLINE BOOTSTRAP (testing/lib/bootstrap.sh) — both phases placed in # order, each finished by the blueprint's OWN `run:` hooks (the retouch # marker, rebrand, re-tenant, work-tree strip, the deferrals and their -# restore, the lockfile, the deployment record), each landing a commit; +# restore, the deployment record), each landing a commit; # 3. the product it ends with: branded with no residue, carrying nothing of # the factory and naming none of it, re-tenanted, its gates restored, its # record rendered, its wrangler config committed; @@ -30,9 +30,8 @@ # testing/e2e.test.sh goes on from here: it installs, migrates, builds and # serves the product over a local Supabase API, and signs a user up on it. # -# Needs: orun, node, pnpm, python3 (+PyYAML), git. No credential. The pnpm -# lockfile confirmation and the deployment-record probes reach the network if -# they can, and pass without it. +# Needs: orun, node, pnpm, python3 (+PyYAML), git. No credential. The +# deployment-record probes reach the network if they can, and pass without it. set -euo pipefail here="$(cd "$(dirname "$0")" && pwd)" root="$(cd "$here/.." && pwd)" @@ -247,10 +246,10 @@ git -C "$at01" checkout -q "$s01" # The PRODUCT's CI plans with its own lane pin (ci.yml), not with the orun # that places the blueprint: per-edge `modeRules` — advisory on a pull -# request — are read by that pin, and the bootstrap floor (v2.58.11) plans -# them enforced everywhere. So the pull-request half below holds only when -# this orun is at least the product's pin; e2e.test.sh, pinned at the lane -# version, asserts it again. +# request — are read by that pin, and an orun older than it (v2.58.11, the +# bootstrap's floor before v2.88.0) plans them enforced everywhere. So the +# pull-request half below holds only when this orun is at least the +# product's pin — which the floor now is; e2e.test.sh asserts it again. lane_pin="$(sed -n 's/^ *version: *v\([0-9.]*\) *$/\1/p' "$tree/.github/workflows/ci.yml" | head -1)" this_orun="$(orun --version | sed -n 's/.*version v\{0,1\}\([0-9.]*\).*/\1/p' | head -1)" @@ -337,8 +336,10 @@ else: # from the product's own plan (component secretEnv AND the compositions' # bindings), the blueprint's reconcile hooks and the components' secretOutputs. bp = yaml.safe_load((root / "repo-blueprint.yaml").read_text()) +# Either form a reconcile takes: `secrets: [{key, template}]`, or `keys`. minted = {k for p in bp["phases"] for slot in (p.get("hooks") or {}).values() for h in slot - if (h.get("uses") or "").startswith("orun.integrations/reconcile@") for k in h["with"]["keys"]} + if (h.get("uses") or "").startswith("orun.integrations/reconcile@") + for k in [s["key"] for s in h["with"].get("secrets") or []] + list(h["with"].get("keys") or [])} published = set() for comp in tree.glob("infra/**/component.yaml"): so = str(((yaml.safe_load(comp.read_text()) or {}).get("spec") or {}).get("parameters", {}).get("secretOutputs") or "") diff --git a/tests/db/component.yaml b/tests/db/component.yaml index 7f6c72e..6508def 100644 --- a/tests/db/component.yaml +++ b/tests/db/component.yaml @@ -2,10 +2,19 @@ apiVersion: sourceplane.io/v1 kind: Component metadata: name: db-tests + description: The migrations' tests (the manifest and its checksums, and row-level security on every table in public after every migration, on an in-process Postgres) spec: type: turbo-package lifecycle: production owner: platform + # Its pages, attached to it in the workspace's catalog: what the Docs + # library shows for it, and what the catalog's docs and runbook checks read. + # Generated from what this manifest and its sources declare. + docs: + overview: docs/overview.md + pages: + - { path: docs/architecture.md, role: architecture, title: Architecture } + - { path: docs/runbook.md, role: runbook, title: Runbook } domain: tests subscribe: environments: diff --git a/tests/db/docs/overview.md b/tests/db/docs/overview.md index ea4ef3f..7196014 100644 --- a/tests/db/docs/overview.md +++ b/tests/db/docs/overview.md @@ -1,5 +1,7 @@ # db-tests +The migrations' tests (the manifest and its checksums, and row-level security on every table in public after every migration, on an in-process Postgres) + The test suite for **db**. It deploys nothing: its lane installs, builds and runs the tests. | | | diff --git a/tests/web/component.yaml b/tests/web/component.yaml index 352f7ad..800bda5 100644 --- a/tests/web/component.yaml +++ b/tests/web/component.yaml @@ -2,10 +2,19 @@ apiVersion: sourceplane.io/v1 kind: Component metadata: name: web-tests + description: The app's tests (the auth settings and helpers, /api/health, Stripe before and after it is connected, the webhook, the committed wrangler config) spec: type: turbo-package lifecycle: production owner: platform + # Its pages, attached to it in the workspace's catalog: what the Docs + # library shows for it, and what the catalog's docs and runbook checks read. + # Generated from what this manifest and its sources declare. + docs: + overview: docs/overview.md + pages: + - { path: docs/architecture.md, role: architecture, title: Architecture } + - { path: docs/runbook.md, role: runbook, title: Runbook } domain: tests subscribe: environments: diff --git a/tests/web/docs/overview.md b/tests/web/docs/overview.md index 3534e6b..c94550e 100644 --- a/tests/web/docs/overview.md +++ b/tests/web/docs/overview.md @@ -1,5 +1,7 @@ # web-tests +The app's tests (the auth settings and helpers, /api/health, Stripe before and after it is connected, the webhook, the committed wrangler config) + The test suite for **web**. It deploys nothing: its lane installs, builds and runs the tests. | | | diff --git a/tooling/catalog/gen-component-docs.py b/tooling/catalog/gen-component-docs.py index 9a39931..743782b 100644 --- a/tooling/catalog/gen-component-docs.py +++ b/tooling/catalog/gen-component-docs.py @@ -4,8 +4,11 @@ python3 tooling/catalog/gen-component-docs.py # write python3 tooling/catalog/gen-component-docs.py --check # fail on drift (CI) -The Orun workspace's Docs library renders the `docs/` folder next to every -`component.yaml`. These pages are generated, not hand-written, because almost +Every `component.yaml` attaches its `docs/` folder in `spec.docs` (overview, +architecture, runbook), which is what the Orun workspace's Docs library shows +and what the catalog's docs and runbook checks read; a folder nothing declares +is never attached (testing/coverage.test.sh holds the rule). These pages are +generated, not hand-written, because almost everything in them is already declared somewhere CI validates: the component's manifest (type, description, dependencies, environments, the secrets a lane resolves, the smoke), its Worker config (bindings, triggers, the wiring the