From 131bd4d40aa51cb4b5b63655c786d05f9a29b581 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 21 Oct 2026 12:06:36 +0000 Subject: [PATCH 1/2] =?UTF-8?q?SA6:=20the=20cirrus=20standard=20=E2=80=94?= =?UTF-8?q?=20no=20kiox,=20generated=20component=20docs,=20the=20context?= =?UTF-8?q?=20pack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove kiox.yaml/kiox.lock and their two blueprint modules: nothing ran the kiox pin (v2.15.0); every workflow pins orun through orun-action. - Generate docs/{overview,architecture,runbook}.md for all seven components from what each declares (tooling/catalog/gen-component-docs.py), and fail Baseline CI when they drift (--check). - Add ai/context/{current,decisions,open-risks}.md (this repository's own; nothing places them). - Close out SA5 (shipped, tagged baseline-v1), bring design.md's migration list and supabase root line up to SA5, and record SA6 (SA-7). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha --- .github/workflows/baseline.yml | 6 + ai/context/current.md | 46 ++ ai/context/decisions.md | 20 + ai/context/open-risks.md | 17 + apps/web/docs/architecture.md | 31 + apps/web/docs/overview.md | 21 + apps/web/docs/runbook.md | 40 ++ infra/db-migrate/docs/architecture.md | 19 + infra/db-migrate/docs/overview.md | 21 + infra/db-migrate/docs/runbook.md | 19 + .../docs/architecture.md | 31 + .../cloudflare-hyperdrive/docs/overview.md | 20 + .../cloudflare-hyperdrive/docs/runbook.md | 20 + infra/terraform/supabase/docs/architecture.md | 31 + infra/terraform/supabase/docs/overview.md | 20 + infra/terraform/supabase/docs/runbook.md | 20 + kiox.lock | 11 - kiox.yaml | 6 - packages/db/docs/architecture.md | 11 + packages/db/docs/overview.md | 20 + packages/db/docs/runbook.md | 25 + repo-blueprint.yaml | 12 +- specs/epics/README.md | 2 +- .../saas-starter/IMPLEMENTATION-STATUS.md | 43 +- specs/epics/saas-starter/README.md | 7 +- specs/epics/saas-starter/design.md | 8 +- specs/epics/saas-starter/epic.yaml | 7 + .../epics/saas-starter/implementation-plan.md | 26 +- tasks/SA-7.TaskContract.yaml | 32 + testing/phases.test.sh | 2 +- tests/db/docs/architecture.md | 8 + tests/db/docs/overview.md | 18 + tests/db/docs/runbook.md | 26 + tests/web/docs/architecture.md | 12 + tests/web/docs/overview.md | 18 + tests/web/docs/runbook.md | 26 + tooling/catalog/gen-component-docs.py | 547 ++++++++++++++++++ tooling/rebrand/rebrand.mjs | 1 - 38 files changed, 1210 insertions(+), 40 deletions(-) create mode 100644 ai/context/current.md create mode 100644 ai/context/decisions.md create mode 100644 ai/context/open-risks.md create mode 100644 apps/web/docs/architecture.md create mode 100644 apps/web/docs/overview.md create mode 100644 apps/web/docs/runbook.md create mode 100644 infra/db-migrate/docs/architecture.md create mode 100644 infra/db-migrate/docs/overview.md create mode 100644 infra/db-migrate/docs/runbook.md create mode 100644 infra/terraform/cloudflare-hyperdrive/docs/architecture.md create mode 100644 infra/terraform/cloudflare-hyperdrive/docs/overview.md create mode 100644 infra/terraform/cloudflare-hyperdrive/docs/runbook.md create mode 100644 infra/terraform/supabase/docs/architecture.md create mode 100644 infra/terraform/supabase/docs/overview.md create mode 100644 infra/terraform/supabase/docs/runbook.md delete mode 100644 kiox.lock delete mode 100644 kiox.yaml create mode 100644 packages/db/docs/architecture.md create mode 100644 packages/db/docs/overview.md create mode 100644 packages/db/docs/runbook.md create mode 100644 tasks/SA-7.TaskContract.yaml create mode 100644 tests/db/docs/architecture.md create mode 100644 tests/db/docs/overview.md create mode 100644 tests/db/docs/runbook.md create mode 100644 tests/web/docs/architecture.md create mode 100644 tests/web/docs/overview.md create mode 100644 tests/web/docs/runbook.md create mode 100644 tooling/catalog/gen-component-docs.py diff --git a/.github/workflows/baseline.yml b/.github/workflows/baseline.yml index 2060aef..cf7351d 100644 --- a/.github/workflows/baseline.yml +++ b/.github/workflows/baseline.yml @@ -51,6 +51,12 @@ jobs: echo "── $t" bash "testing/$t.test.sh" done + # Every component's docs/{overview,architecture,runbook}.md is generated + # from what the component declares (its manifest, Worker config, + # Terraform, migrations, package scripts). A pull request that changes + # one of those facts without regenerating the pages fails here. + - name: Component docs match their manifests + run: python3 tooling/catalog/gen-component-docs.py --check # Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS. # diff --git a/ai/context/current.md b/ai/context/current.md new file mode 100644 index 0000000..634d98f --- /dev/null +++ b/ai/context/current.md @@ -0,0 +1,46 @@ +# saas-starter — where this repository stands + +The entry page for anyone (or any agent) picking this repository up. It is +this repository's own state and does not ship to a product built from it; +the two pages that do are [operations.md](operations.md) and +[deployment.md](deployment.md). + +## What it is + +Vercel's Next.js SaaS Starter — Postgres through Drizzle, Stripe Checkout, +the Customer Portal and webhooks, email/password auth with a JWT cookie, +teams with roles, invitations and an activity log — on Cloudflare Workers + +Static Assets (through `@opennextjs/cloudflare`), its Postgres a Supabase +project's database reached through Cloudflare Hyperdrive, both from +Terraform, and its schema applied by db-migrate. It is packaged as an Orun +baseline: `orun new --blueprint repo-blueprint.yaml` builds a new product in +its own repository and takes it to live on stage and prod in one landing +(`01-product`: the Supabase project, then Hyperdrive over its database, then +the migrations, then the app), then records what went live (`02-docs`). +Stripe is the owner's to connect afterwards; the app deploys, signs users up +and serves without it. + +## Release + +| | | +|---|---| +| Latest tag | `baseline-v1` (SA5, [#6](https://github.com/sourceplane/saas-starter/pull/6)) | +| On `main` since | SA6 — the cirrus standard (no kiox, generated component docs, this context pack) | +| Proven live | No. Everything short of the platform is proven offline in Baseline CI: the e2e tier migrates a local Postgres with the product's own runner, builds in orun's staged job tree, and signs a user up and in with no Stripe key and no `AUTH_SECRET`. No bootstrap from a tag has run against a workspace: neither Terraform root has been applied, db-migrate has not run against a real project, nothing has deployed, and the card's twenty minutes is unmeasured (SA-M) | + +## Where to read + +| Question | Page | +|---|---| +| What shipped, and every departure from upstream | `specs/epics/saas-starter/IMPLEMENTATION-STATUS.md` | +| Why it is built this way | [decisions.md](decisions.md), then `specs/epics/saas-starter/design.md` | +| What could still go wrong | [open-risks.md](open-risks.md), then `specs/epics/saas-starter/risks-and-open-questions.md` | +| How to instantiate it | `BOOTSTRAP.md`, `docs/phases/` | +| What each component is | `/docs/` beside each `component.yaml` — `apps/web`, `packages/db`, `infra/db-migrate`, `infra/terraform/{supabase,cloudflare-hyperdrive}`, `tests/{web,db}` (generated; `python3 tooling/catalog/gen-component-docs.py`) | + +## Next + +1. Bootstrap one product from a tag against a workspace with Cloudflare and + Supabase connected, and record its timings (closes SA-M; settles SA-L's + table-owner check on a real project). +2. Cut the next `baseline-vN` with `tag.yml` so the registry can pin SA6. diff --git a/ai/context/decisions.md b/ai/context/decisions.md new file mode 100644 index 0000000..fc96920 --- /dev/null +++ b/ai/context/decisions.md @@ -0,0 +1,20 @@ +# saas-starter — decisions + +The choices that shape this repository, one line each, with where the full +reasoning lives. Superseded decisions stay listed, marked, so the history +reads in order. + +| # | Decision | Why | Source | +|---|---|---|---| +| 1 | OpenNext on Workers + Static Assets (Next 16.3.8, React 19) | `@opennextjs/cloudflare` needs a current Next; only what Next 16 and Workers force changes in the template | epic README (decisions locked), IMPLEMENTATION-STATUS (Versions) | +| 2 | Drizzle over a Postgres socket through Hyperdrive — not PostgREST, not D1 | The template's data access is SQL; Hyperdrive gives the Worker the socket the code already expects | design.md §6 | +| 3 | A `postgres` client per request (`getDb()` in `lib/db/drizzle.ts`), never a module-level pool | Workers refuse to reuse a socket another request opened; Hyperdrive is the pool | design.md §3, risk SA-A | +| 4 | `apps/web/wrangler.jsonc` is committed as the fixture render; stage and prod re-render it from `WIRING_CLOUDFLARE_HYPERDRIVE` | The composition checks the file exists before the build, in a fresh checkout | risk SA-K | +| 5 | The schema is applied by the `@saas/db` runner (db-migrate) through Supabase's Management API, from the drizzle-kit SQL; drizzle-kit stays for local development | The token is already brokered; no CLI binary and no direct Postgres connection on the runner | design.md §2, risk SA-E | +| 6 | A fresh product needs no hand-set secret: Stripe is optional (pricing says checkout is not connected, the webhook answers 503), and the session key defaults to one the database generates (`020_app_secrets`) unless `AUTH_SECRET` is set | A bootstrapped product is deployed by a convergence nobody attends, and no platform brokers Stripe | risk SA-J | +| 7 | Row-level security with no policy on every table in `public`; migration `030` refuses to run if `postgres` would be locked out | Supabase's Data API serves `public` to the anon key; the app connects as the tables' owner | risk SA-L | +| 8 | Infra before app on main: supabase → cloudflare-hyperdrive → db-migrate → web, enforced; advisory on a pull request | Each component reads what the one before it published; a migration is the one step a re-run cannot take back, so it runs last before the Worker | design.md §4, IMPLEMENTATION-STATUS (SA5) | +| 9 | One landing (`01-product`) then the record (`02-docs`); `ci.yml` plans nothing while `intent.yaml` names `ws_CHANGE_ME`; `checks.yml` on pull requests only | A landing has a fixed cost; a bootstrap cannot set a repository variable (replaced the `ORUN_CI` gate); a push to main must start `ci.yml` alone | `repo-blueprint.yaml`, IMPLEMENTATION-STATUS (SA5) | +| 10 | stack-tectonic 0.19.0, not 0.20.0 | 0.20.0's lane-scoped install is refused by Turbopack | `intent.yaml`, IMPLEMENTATION-STATUS (SA5) | +| 11 | orun is pinned only where it runs (the `orun-action` `version:` in each workflow); no kiox | `kiox.yaml` pinned a version (v2.15.0) nothing ran | IMPLEMENTATION-STATUS (SA6) | +| 12 | Component docs are generated from the manifests and checked in CI | A hand-written copy of the dependency graph and bindings drifts silently | `tooling/catalog/gen-component-docs.py` | diff --git a/ai/context/open-risks.md b/ai/context/open-risks.md new file mode 100644 index 0000000..7c5b3aa --- /dev/null +++ b/ai/context/open-risks.md @@ -0,0 +1,17 @@ +# saas-starter — open risks + +What is not yet proven or not yet decided. The full write-up of every risk, +including the accepted and resolved ones, is +`specs/epics/saas-starter/risks-and-open-questions.md`; this page lists only +what is still live, so it should be short. + +| ID | Risk | State | What closes it | +|---|---|---|---| +| SA-M | No bootstrap has been timed (the card's twenty minutes is summed from estimates); neither Terraform root has been applied from this repository and db-migrate has not run against a real project — so whether `postgres` owns the tables there, which migration `030`'s guard checks before it enables RLS (SA-L), is also unobserved | OPEN | One bootstrap from a tag against a workspace with Cloudflare and Supabase connected | + +Accepted, and worth knowing before you change them: SA-A (a `postgres` +client per request), SA-D (the deploy sets no Worker secret; Stripe's keys +are the owner's), SA-E (migrations through the Management API, autocommit), +SA-F (Stripe products come from the seed, test mode), SA-G (local +development needs a Postgres on 54322), SA-N (the bootstrap floor plans +`modeRules` as enforced). diff --git a/apps/web/docs/architecture.md b/apps/web/docs/architecture.md new file mode 100644 index 0000000..219fbab --- /dev/null +++ b/apps/web/docs/architecture.md @@ -0,0 +1,31 @@ +# web — architecture + +Built by the turbo pipeline from `apps/web` and deployed with wrangler. + +| | | +| ------------------- | ----------------------------------------------- | +| Worker config | `apps/web/wrangler.template.jsonc` | +| Entry | `.open-next/worker.js` | +| Compatibility date | `2026-10-01` | +| Compatibility flags | `nodejs_compat`, `global_fetch_strictly_public` | + +## Bindings + +| Binding | Kind | Source | +| ------------ | ---------------------------- | -------------------------------------------- | +| `HYPERDRIVE` | Hyperdrive (pooled Postgres) | `hyperdrive_id` from `cloudflare-hyperdrive` | +| `ASSETS` | Static assets | `.open-next/assets` | + +Identifiers marked _from_ a component are filled in at deploy time from +that component's published outputs for the environment being deployed. + +## Variables + +`BASE_URL`. + +## Wiring + +Resolved at deploy time from secrets the infrastructure lanes publish (names only): + +- `WIRING_CLOUDFLARE_HYPERDRIVE_PROD` +- `WIRING_CLOUDFLARE_HYPERDRIVE_STAGE` diff --git a/apps/web/docs/overview.md b/apps/web/docs/overview.md new file mode 100644 index 0000000..0e20b14 --- /dev/null +++ b/apps/web/docs/overview.md @@ -0,0 +1,21 @@ +# web + +The Next.js SaaS Starter — Postgres + Drizzle, Stripe subscriptions, JWT auth, teams (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment) + +A Cloudflare Worker with Static Assets (server rendering plus static files), deployed per environment by its CI lane. + +| | | +| ------------ | ------------------------------------------------------------------------------------------------------------------ | +| Type | `cloudflare-workers-assets-turbo` | +| Source | `apps/web` | +| Package | `@app/web` | +| Environments | `dev`: `verify` · `stage`: `verify`, `deploy` on a push to `main` · `prod`: `verify`, `deploy` on a push to `main` | + +## Depends on + +- **cloudflare-hyperdrive** — Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases +- **db-migrate** — Applies database migrations to stage and prod Supabase instances + +## Depended on by + +- (none) diff --git a/apps/web/docs/runbook.md b/apps/web/docs/runbook.md new file mode 100644 index 0000000..832c504 --- /dev/null +++ b/apps/web/docs/runbook.md @@ -0,0 +1,40 @@ +# web — runbook + +## How it runs + +Pull requests verify it; a merge to `main` deploys it to `stage`, `prod`. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Local commands + +```bash +pnpm --filter @app/web dev +pnpm --filter @app/web build +pnpm --filter @app/web typecheck +pnpm --filter @app/web lint +pnpm --filter @app/web preview +``` + +## Verify + +After a deploy the lane runs this smoke against the environment it +deployed (`ORUN_ENVIRONMENT`); `DEPLOYED_URL` overrides the URL: + +```bash +html=$(curl -sfL "${DEPLOYED_URL}/") && echo "${html}" | grep -q 'href="/pricing"' && health=$(curl -sf "${DEPLOYED_URL}/api/health") && echo "${health}" | grep -q '"ok":true' +``` + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **A `WIRING_*` secret is missing at deploy**: an infrastructure lane upstream + has not applied for this environment yet. Within one convergence the plan + runs it first; on its own, re-run that lane. +- **The smoke fails right after a first deploy**: a new workers.dev route can + answer 4xx for a few seconds and the lane retries. A failure that persists + is a regression in the deployed code. diff --git a/infra/db-migrate/docs/architecture.md b/infra/db-migrate/docs/architecture.md new file mode 100644 index 0000000..0411bdc --- /dev/null +++ b/infra/db-migrate/docs/architecture.md @@ -0,0 +1,19 @@ +# db-migrate — architecture + +Applies the migrations under `packages/db/src/migrations` in order, recording each one +it applies so a run only ever applies what is new. An already-applied migration +is never edited: a change is a new, later migration. + +## Migrations + +- `000_control` +- `010_saas_starter_schema` +- `020_app_secrets` +- `030_row_level_security` + +## Resolved at run time (names only) + +- `SUPABASE_ACCESS_TOKEN` +- `SUPABASE_DB_PASSWORD` +- `SUPABASE_DB_URL` +- `SUPABASE_PROJECT_REF` diff --git a/infra/db-migrate/docs/overview.md b/infra/db-migrate/docs/overview.md new file mode 100644 index 0000000..779fab1 --- /dev/null +++ b/infra/db-migrate/docs/overview.md @@ -0,0 +1,21 @@ +# db-migrate + +Applies database migrations to stage and prod Supabase instances + +Applies this repository's ordered database migrations per environment: plan on pull requests, apply on merge to `main`. + +| | | +| ------------ | ------------------------------------------------------------------------------------------ | +| Type | `db-migrate` | +| Source | `infra/db-migrate` | +| Environments | `stage`: `plan`, `apply` on a push to `main` · `prod`: `plan`, `apply` on a push to `main` | + +## Depends on + +- **db** — The database migrations and their runner (built by the db-migrate component before it plans or applies) +- **supabase** — Provisions Supabase projects for stage and prod and wires credentials into orun secrets +- **cloudflare-hyperdrive** — Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases + +## Depended on by + +- **web** — The Next.js SaaS Starter — Postgres + Drizzle, Stripe subscriptions, JWT auth, teams (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment) diff --git a/infra/db-migrate/docs/runbook.md b/infra/db-migrate/docs/runbook.md new file mode 100644 index 0000000..04a50d1 --- /dev/null +++ b/infra/db-migrate/docs/runbook.md @@ -0,0 +1,19 @@ +# db-migrate — runbook + +## How it runs + +Pull requests plan it; a merge to `main` applies it to `stage`, `prod`. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **An applied migration's file changed**: the run stops rather than guess. + Restore the file and write the change as a new migration. +- **The database is unreachable**: the infrastructure lane it depends on has + not applied for this environment; that lane runs first in a convergence. diff --git a/infra/terraform/cloudflare-hyperdrive/docs/architecture.md b/infra/terraform/cloudflare-hyperdrive/docs/architecture.md new file mode 100644 index 0000000..4cb812f --- /dev/null +++ b/infra/terraform/cloudflare-hyperdrive/docs/architecture.md @@ -0,0 +1,31 @@ +# cloudflare-hyperdrive — architecture + +A `terraform` root at `infra/terraform/cloudflare-hyperdrive/terraform`. + +- **State** lives in the Orun Cloud HTTP state backend — no local state and + no state bucket to manage. +- **Credentials are brokered per run** from the workspace's provider + connections and resolved by name; none is stored in this repository. +- **Adoption** (`adopt.tf`): when state is empty but the resource already + exists, plan-time import adopts it instead of failing. + +## Resources + +- `cloudflare_hyperdrive_config.postgres` + +## Published outputs + +Written as job-output secrets on each environment after an apply; deploy +lanes downstream resolve them by name. + +| Secret | Terraform output | +| ------------------------------ | ---------------- | +| `WIRING_CLOUDFLARE_HYPERDRIVE` | `wiring` | + +## Resolved at run time (names only) + +- `CLOUDFLARE_ACCOUNT_ID` +- `CLOUDFLARE_API_TOKEN` +- `TF_VAR_cloudflare_account_id` +- `TF_VAR_supabase_db_password` +- `TF_VAR_supabase_project_ref` diff --git a/infra/terraform/cloudflare-hyperdrive/docs/overview.md b/infra/terraform/cloudflare-hyperdrive/docs/overview.md new file mode 100644 index 0000000..2e15867 --- /dev/null +++ b/infra/terraform/cloudflare-hyperdrive/docs/overview.md @@ -0,0 +1,20 @@ +# cloudflare-hyperdrive + +Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases + +Terraform-managed infrastructure, planned and applied per environment by its CI lane. + +| | | +| ------------ | ---------------------------------------------------------------------------------------------------- | +| Type | `terraform` | +| Source | `infra/terraform/cloudflare-hyperdrive` | +| Environments | `stage`: `plan-only`, `apply` on a push to `main` · `prod`: `plan-only`, `apply` on a push to `main` | + +## Depends on + +- **supabase** — Provisions Supabase projects for stage and prod and wires credentials into orun secrets + +## Depended on by + +- **db-migrate** — Applies database migrations to stage and prod Supabase instances +- **web** — The Next.js SaaS Starter — Postgres + Drizzle, Stripe subscriptions, JWT auth, teams (Next.js on Cloudflare Workers + Static Assets via @opennextjs/cloudflare, per environment) diff --git a/infra/terraform/cloudflare-hyperdrive/docs/runbook.md b/infra/terraform/cloudflare-hyperdrive/docs/runbook.md new file mode 100644 index 0000000..016c2b5 --- /dev/null +++ b/infra/terraform/cloudflare-hyperdrive/docs/runbook.md @@ -0,0 +1,20 @@ +# cloudflare-hyperdrive — runbook + +## How it runs + +Pull requests plan it; a merge to `main` applies it to `stage`, `prod`. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **Provider authentication fails**: the workspace's provider connection is + missing or revoked. Reconnect it in the console; credentials are brokered + from it per run. +- **"Already exists" on a first apply**: state is empty but the resource is + not. `adopt.tf` imports it at plan time; if it still fails, the resource was renamed outside Terraform. diff --git a/infra/terraform/supabase/docs/architecture.md b/infra/terraform/supabase/docs/architecture.md new file mode 100644 index 0000000..6ab1960 --- /dev/null +++ b/infra/terraform/supabase/docs/architecture.md @@ -0,0 +1,31 @@ +# supabase — architecture + +A `terraform` root at `infra/terraform/supabase/terraform`. + +- **State** lives in the Orun Cloud HTTP state backend — no local state and + no state bucket to manage. +- **Credentials are brokered per run** from the workspace's provider + connections and resolved by name; none is stored in this repository. +- **Adoption** (`adopt.tf`): when state is empty but the resource already + exists, plan-time import adopts it instead of failing. + +## Resources + +- `random_password.db_password` +- `supabase_project.this` + +## Published outputs + +Written as job-output secrets on each environment after an apply; deploy +lanes downstream resolve them by name. + +| Secret | Terraform output | +| ---------------------- | ------------------- | +| `SUPABASE_PROJECT_REF` | `project_ref` | +| `SUPABASE_DB_PASSWORD` | `database_password` | +| `SUPABASE_DB_URL` | `connection_uri` | + +## Resolved at run time (names only) + +- `SUPABASE_ACCESS_TOKEN` +- `TF_VAR_supabaseOrgId` diff --git a/infra/terraform/supabase/docs/overview.md b/infra/terraform/supabase/docs/overview.md new file mode 100644 index 0000000..d1bf765 --- /dev/null +++ b/infra/terraform/supabase/docs/overview.md @@ -0,0 +1,20 @@ +# supabase + +Provisions Supabase projects for stage and prod and wires credentials into orun secrets + +Terraform-managed infrastructure, planned and applied per environment by its CI lane. + +| | | +| ------------ | ---------------------------------------------------------------------------------------------------- | +| Type | `terraform` | +| Source | `infra/terraform/supabase` | +| Environments | `stage`: `plan-only`, `apply` on a push to `main` · `prod`: `plan-only`, `apply` on a push to `main` | + +## Depends on + +- (none) + +## Depended on by + +- **cloudflare-hyperdrive** — Provisions Cloudflare Hyperdrive resources for stage and prod Supabase Postgres databases +- **db-migrate** — Applies database migrations to stage and prod Supabase instances diff --git a/infra/terraform/supabase/docs/runbook.md b/infra/terraform/supabase/docs/runbook.md new file mode 100644 index 0000000..d240972 --- /dev/null +++ b/infra/terraform/supabase/docs/runbook.md @@ -0,0 +1,20 @@ +# supabase — runbook + +## How it runs + +Pull requests plan it; a merge to `main` applies it to `stage`, `prod`. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **Provider authentication fails**: the workspace's provider connection is + missing or revoked. Reconnect it in the console; credentials are brokered + from it per run. +- **"Already exists" on a first apply**: state is empty but the resource is + not. `adopt.tf` imports it at plan time; if it still fails, the resource was renamed outside Terraform. diff --git a/kiox.lock b/kiox.lock deleted file mode 100644 index 6e14690..0000000 --- a/kiox.lock +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: kiox.io/v1 -kind: WorkspaceLock -metadata: - name: example-platform -providers: - - alias: orun - provider: sourceplane/orun - source: ghcr.io/sourceplane/orun:v2.15.0 - version: v2.15.0 - resolved: ghcr.io/sourceplane/orun@sha256:1d28be8612dc8d8083b508f97cd71a24c090f6472c43c71f68455e3709a6a3c1 - store: e02472f57f2eb5fb5168b7d270ea547e5bffbf83824c4286abd7ba20f87cb9d1 diff --git a/kiox.yaml b/kiox.yaml deleted file mode 100644 index d654da0..0000000 --- a/kiox.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: kiox.io/v1 -kind: Workspace -metadata: - name: example-platform -providers: - orun: ghcr.io/sourceplane/orun:v2.15.0 diff --git a/packages/db/docs/architecture.md b/packages/db/docs/architecture.md new file mode 100644 index 0000000..3f9b079 --- /dev/null +++ b/packages/db/docs/architecture.md @@ -0,0 +1,11 @@ +# db — architecture + +A workspace package at `packages/db`, consumed by the components that depend +on it. It has no deployed surface of its own. + +## Exports + +- `.` +- `./manifest` +- `./runner` +- `./types` diff --git a/packages/db/docs/overview.md b/packages/db/docs/overview.md new file mode 100644 index 0000000..c0097af --- /dev/null +++ b/packages/db/docs/overview.md @@ -0,0 +1,20 @@ +# db + +The database migrations and their runner (built by the db-migrate component before it plans or applies) + +A workspace package built by the turbo pipeline. It deploys nothing itself: its lane type-checks, lints, tests and builds it. + +| | | +| ------------ | --------------------------------------------------------------------- | +| Type | `turbo-package` | +| Source | `packages/db` | +| Package | `@saas/db` | +| Environments | `dev`: `quick-check` · `stage`: `quick-check` · `prod`: `quick-check` | + +## Depends on + +- (none) + +## Depended on by + +- **db-migrate** — Applies database migrations to stage and prod Supabase instances diff --git a/packages/db/docs/runbook.md b/packages/db/docs/runbook.md new file mode 100644 index 0000000..3fa7445 --- /dev/null +++ b/packages/db/docs/runbook.md @@ -0,0 +1,25 @@ +# db — runbook + +## How it runs + +Its lane runs on every pull request that changes it; it has no deployed surface. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Local commands + +```bash +pnpm --filter @saas/db build +pnpm --filter @saas/db typecheck +pnpm --filter @saas/db lint +``` + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **A dependent fails to build after a change here**: run `pnpm typecheck` + across the workspace before merging. diff --git a/repo-blueprint.yaml b/repo-blueprint.yaml index 65ce8ac..d4a430c 100644 --- a/repo-blueprint.yaml +++ b/repo-blueprint.yaml @@ -191,16 +191,6 @@ modules: source: baseline from: turbo.json to: turbo.json - - name: root-kiox - mode: copy - source: baseline - from: kiox.yaml - to: kiox.yaml - - name: root-kiox-lock - mode: copy - source: baseline - from: kiox.lock - to: kiox.lock - name: root-gitignore mode: copy source: baseline @@ -428,7 +418,7 @@ phases: await: "One convergence is running per environment: the Supabase project first (five to seven minutes to come up), then Hyperdrive over its database, then the migrations, then the app. Nothing is stuck." done: "{{ .inputs.reponame }} is live on stage and prod — {{ .meta.files }} files on main, branded as {{ .inputs.productname }}, its database reachable through Hyperdrive. Stripe connects whenever you add its key. That took {{ .meta.elapsed }}." failed: "The product did not come up. The failing lane above names the component — supabase, cloudflare-hyperdrive, db-migrate or web — and the provider's own error is in its log; whatever was provisioned is still there." - modules: [ai-deployment, ai-operations, cloudflare-hyperdrive, db, db-migrate, db-tests, github-workflows, rebrand-values, root-gitignore, root-intent, root-kiox, root-kiox-lock, root-package-json, root-pnpm-lock, root-pnpm-workspace, root-readme, root-turbo, supabase, tooling-eslint, tooling-migrations, tooling-tsconfig, tooling-wire, vscode, web, web-tests] + modules: [ai-deployment, ai-operations, cloudflare-hyperdrive, db, db-migrate, db-tests, github-workflows, rebrand-values, root-gitignore, root-intent, root-package-json, root-pnpm-lock, root-pnpm-workspace, root-readme, root-turbo, supabase, tooling-eslint, tooling-migrations, tooling-tsconfig, tooling-wire, vscode, web, web-tests] # THE PLATFORM MUST BE ABLE TO SEE THE REPOSITORY BEFORE IT EXISTS. Every # phase lands a pull request that files under its task, and the platform # learns of a PR only through the GitHub App installation on the account diff --git a/specs/epics/README.md b/specs/epics/README.md index 73d0f7a..e46b3a2 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`saas-starter/`](./saas-starter/) | **SA** | 🔄 SA5 in review | Vercel's Next.js SaaS Starter, equivalent in code and function, on Cloudflare Workers with Supabase Postgres through Hyperdrive — and an Orun baseline that instantiates it in one landing (SA5) | +| [`saas-starter/`](./saas-starter/) | **SA** | ✅ Shipped (`baseline-v1`); live bootstrap pending | Vercel's Next.js SaaS Starter, equivalent in code and function, on Cloudflare Workers with Supabase Postgres through Hyperdrive — and an Orun baseline that instantiates it in one landing (SA5) | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/saas-starter/IMPLEMENTATION-STATUS.md b/specs/epics/saas-starter/IMPLEMENTATION-STATUS.md index 59b041a..d1c95b8 100644 --- a/specs/epics/saas-starter/IMPLEMENTATION-STATUS.md +++ b/specs/epics/saas-starter/IMPLEMENTATION-STATUS.md @@ -10,7 +10,8 @@ the code departed from `design.md` or from the upstream template. | SA2 — the schema through db-migrate | ✅ Shipped (planned offline; apply gated on a linked workspace) | [#3](https://github.com/sourceplane/saas-starter/pull/3) | | SA3 — Supabase and Hyperdrive from Terraform | ✅ Shipped (validated; apply gated on a linked workspace) | [#4](https://github.com/sourceplane/saas-starter/pull/4) | | SA4 — ready to instantiate | ✅ Shipped | [#5](https://github.com/sourceplane/saas-starter/pull/5) | -| SA5 — a baseline | 🔄 In review (SA-6) | this branch, `claude/blissful-ptolemy-c5ajf8` | +| SA5 — a baseline | ✅ Shipped | [#6](https://github.com/sourceplane/saas-starter/pull/6) (SA-6), tagged `baseline-v1` | +| SA6 — the cirrus standard | ✅ Shipped | SA-7 — on `main` after `baseline-v1`, not yet tagged | ## Departures from the upstream template @@ -217,3 +218,43 @@ See the pull request for the run log. In short: the repository's checks and `validate` on both roots. Not verified: a Terraform apply, a db-migrate apply against a real Supabase project, a live deploy, a live bootstrap, and checkout against a real Stripe account (SA-M). + +## The cirrus standard (SA6) + +Nothing about the app changed. What changed is the baseline around it: + +| What | Before | After | Why | +|---|---|---|---| +| orun pin | `kiox.yaml` (v2.15.0) + `kiox.lock`, shipped to every product | gone; orun is pinned where it runs, the `orun-action` `version:` in each workflow | nothing ran the kiox pin, and it disagreed with the lanes (v2.78.4) | +| `root-kiox`, `root-kiox-lock` modules | in `01-product` | removed (`testing/phases.test.sh` and the rebrand's skip list follow) | a product is placed with 159 files: 140 − 2 kiox + 21 docs pages | +| component docs | none | `docs/overview.md`, `architecture.md`, `runbook.md` beside each of the seven `component.yaml` | cirrus-baseline documents every component; the workspace Docs library renders `docs/` beside each manifest | +| how the docs stay true | — | `tooling/catalog/gen-component-docs.py` derives them from the manifest, the Worker config, Terraform, migrations and package scripts; Baseline CI runs it with `--check` | a hand-written copy of a manifest drifts silently | +| context pack | `operations.md`, `deployment.md` | plus `current.md`, `decisions.md`, `open-risks.md` | cirrus-baseline's shape; the three new pages are this repository's own and no module places them (the leak gate still allows exactly two) | +| status | SA5 "in review", on a branch | SA5 shipped and tagged `baseline-v1`; `design.md` §3/§5 list the four migrations and the supabase root as SA5 left them | the tag existed; the documents had not caught up | + +## Verified (SA6) + +- `testing/{manifest,phases,coverage,rebrand,retouch,bootstrap-defer}.test.sh` + green; `gen-component-docs.py --check` green (7 components, 21 pages). +- `orun new --status` at v2.58.11: `01-product` 159 files (140 on + `baseline-v1`), `02-docs` hook-only. +- `testing/leak.test.sh` at v2.58.11: 159 files derived, 157 text files + read; ai/context still exactly the two declared pages; the generated pages + name no factory path. +- `testing/placement.test.sh` at v2.58.11: 159 files placed, both landings, + branded, re-tenanted, record rendered; the product's own plan orders + supabase → cloudflare-hyperdrive → db-migrate → web on stage and prod, + enforced; `--resume` changes nothing. +- `pnpm install --frozen-lockfile`, `wire:fixture` (the tree unchanged), + `typecheck`, `lint` (0 errors, upstream's 4 warnings), `test` (37 tests: + 27 in `tests/web`, 10 in `tests/db`), `build` green. +- `testing/e2e.test.sh` at v2.78.4 green: the finished product passes the + Checks sequence; the stage db-migrate lane applies all four migrations to + a local Postgres with Supabase's roles and a second apply applies nothing; + the stage web lane's install, `verify-app-structure`, `build-app`, + `verify-build-output` and `deploy-dry-run` pass in the staged job tree; + under `wrangler dev` with no Stripe key and no `AUTH_SECRET` the + component's own smoke passes and a sign-up, the dashboard and a sign-in + work; 0 of 5 public tables without RLS, and `anon`/`authenticated` read + and write none of the rows. +- `orun task check SA-7` complete. diff --git a/specs/epics/saas-starter/README.md b/specs/epics/saas-starter/README.md index 5114051..89ccd2d 100644 --- a/specs/epics/saas-starter/README.md +++ b/specs/epics/saas-starter/README.md @@ -8,15 +8,15 @@ The upstream code stays the code: the Drizzle schema and queries, the server act | Field | Value | |-------|-------| -| Status | ✅ SA0–SA4 shipped (#1–#5) · 🔄 SA5 — a baseline (SA-6) in review. The Supabase and Hyperdrive applies, a live db-migrate apply and a live deploy are gated on a linked workspace | -| Cluster | **SA** (SA0–SA5) | +| Status | ✅ SA0–SA5 shipped (#1–#6), tagged `baseline-v1`; SA6 (the cirrus standard, SA-7) on `main`, not yet tagged. Not yet proven by a live bootstrap: the Supabase and Hyperdrive applies, a live db-migrate apply and a live deploy (risk SA-M) | +| Cluster | **SA** (SA0–SA6) | | Owner(s) | `apps/web` (the app) · `packages/db` (the migrations and their runner) · `tests/web`, `tests/db` · `infra/terraform/supabase`, `infra/terraform/cloudflare-hyperdrive`, `infra/db-migrate` | | Builds on | `lumen` conventions — the `supabase` and `cloudflare-hyperdrive` Terraform roots, `@saas/db` + `db-migrate`, the per-request `postgres` client; `cirrus-baseline` conventions for the repository shape | | Upstream | [nextjs/saas-starter](https://github.com/nextjs/saas-starter) (`6e33e58`, Next 15.6 canary) | | Changes | Adds the Workers build, the monorepo wrapper, tests, the migrations package, the three infra components and the deploy contract; in the template's code: `lib/db/drizzle.ts` (per-request client), `middleware.ts` → `proxy.ts`, the Stripe client's fetch transport and the webhook's async signature check | | Decisions locked | (1) OpenNext on Workers + Static Assets. (2) Drizzle over a Postgres socket through Hyperdrive, not PostgREST and not D1. (3) A `postgres` client per request — never a module-level pool. (4) `wrangler.jsonc` rendered from the template: committed as the fixture render (the composition checks it exists before the build), re-rendered per environment from the Hyperdrive wiring document by the deploy lanes (SA5; it was never committed before). (5) drizzle-kit stays for local development; the runner applies in CI. (6) `STRIPE_SECRET_KEY` and `STRIPE_WEBHOOK_SECRET` are Worker secrets the owner adds when ready — the app deploys and serves without them (SA5); `AUTH_SECRET` is optional, the database generating the session key otherwise (SA5); `BASE_URL` is a wrangler var. (7) Infra before app on main: supabase → cloudflare-hyperdrive → db-migrate → web, enforced; advisory on pull requests (SA5). | | Gate | SA1 is the first user-visible rung. SA2 and SA3 need a workspace with Supabase and Cloudflare connections to apply; they are verified by `plan` and `terraform validate`. | -| Shipped as | `main` after [#5](https://github.com/sourceplane/saas-starter/pull/5); verified locally under `wrangler dev` with the fixture config and a throwaway `.dev.vars` | +| Shipped as | `baseline-v1` ([#6](https://github.com/sourceplane/saas-starter/pull/6)), then SA6 on `main`; proven offline (Baseline CI: contract, leak, placement and the e2e tier over a local Postgres), deploy gated until a workspace is linked | ## Read order @@ -35,3 +35,4 @@ The upstream code stays the code: the Drizzle schema and queries, the server act | SA3 — Supabase and Hyperdrive from Terraform | `infra/terraform/supabase`, `infra/terraform/cloudflare-hyperdrive` | both roots validate; the wiring keys match the template's tokens | | SA4 — ready to instantiate | README, as-built status | a reader can run, seed, test, preview and deploy it | | SA5 — a baseline | card, build document, rename, bootstrap tooling, the product's README and context pack, tests | a new product goes from nothing to live on stage and prod in one landing, with no Stripe key; Baseline CI green | +| SA6 — the cirrus standard | no kiox, generated component docs, the context pack, status that agrees with the tags | Baseline CI green with the docs check | diff --git a/specs/epics/saas-starter/design.md b/specs/epics/saas-starter/design.md index 35649fb..8b3b584 100644 --- a/specs/epics/saas-starter/design.md +++ b/specs/epics/saas-starter/design.md @@ -45,7 +45,7 @@ browser ──HTTPS──► saas-starter-web- (one Worker: proxy + pages ▼ Supabase Postgres db..supabase.co:5432 ▲ - db-migrate ── packages/db/src/migrations/{000_control,010_saas_starter_schema}/up.sql + db-migrate ── packages/db/src/migrations/{000_control,010_saas_starter_schema,020_app_secrets,030_row_level_security}/up.sql through the Management API, before the Worker deploys Stripe ──POST /api/stripe/webhook──► Worker: constructEventAsync (SubtleCrypto) → handleSubscriptionChange → getDb() → teams @@ -114,12 +114,12 @@ apps/web the template (app/, components/, lib/, proxy.ts) + wiring.fixture.json offline values for the verify lane .dev.vars.example the Worker secrets, for wrangler dev open-next.config.ts static-assets incremental cache (nothing revalidates for real) -packages/db @saas/db: the migrations (000_control, 010_saas_starter_schema) + Lumen's runner +packages/db @saas/db: the migrations (000_control, 010_saas_starter_schema, 020_app_secrets, 030_row_level_security — SA5) + Lumen's runner infra/db-migrate applies them per environment through the Management API (after supabase) -infra/terraform/supabase the Supabase project per environment (Lumen's root + API keys) +infra/terraform/supabase the Supabase project per environment (Lumen's root; since SA5 it no longer reads the API keys) infra/terraform/cloudflare-hyperdrive the Hyperdrive config per environment, fronting that database tests/web vitest: session sign/verify, bcrypt, the proxy's decisions, the webhook route (mocked Stripe) -tests/db vitest: manifest checksums, offline plan +tests/db vitest: manifest checksums, offline plan, row-level security on every table (PGlite) ``` ## 6. Alternatives rejected diff --git a/specs/epics/saas-starter/epic.yaml b/specs/epics/saas-starter/epic.yaml index 61b4a8f..e217fef 100644 --- a/specs/epics/saas-starter/epic.yaml +++ b/specs/epics/saas-starter/epic.yaml @@ -46,3 +46,10 @@ spec: - "every table in public has row-level security and no policy: Supabase's Data API (anon, authenticated) reads and writes nothing, the app, as the tables' owner, everything" - "Baseline CI is green: contract tests, the blueprint read by the pinned orun, the leak gate, the offline bootstrap and the product's plans, and the end-to-end tier" tasks: [SA-6] + - name: "SA6 — the cirrus standard" + exitCriteria: + - "nothing outside this milestone's own record names kiox: orun is pinned where CI runs it (the orun-action `version:` in each workflow)" + - "every component carries generated docs/{overview,architecture,runbook}.md, and Baseline CI fails a pull request whose manifests and pages disagree" + - "ai/context carries this repository's current.md, decisions.md and open-risks.md, and none of them ships to a product" + - "every milestone's status row agrees with the tags" + tasks: [SA-7] diff --git a/specs/epics/saas-starter/implementation-plan.md b/specs/epics/saas-starter/implementation-plan.md index 8ea5f5d..116c996 100644 --- a/specs/epics/saas-starter/implementation-plan.md +++ b/specs/epics/saas-starter/implementation-plan.md @@ -65,7 +65,7 @@ with PRs and departures, epic `completed`. - the README quick start works from a fresh clone - the status file lists every PR and departure -## SA5 — a baseline +## SA5 — a baseline (SA-6) ✅ The repository becomes an Orun baseline on the Lumen conventions, built the way cirrus-baseline v22 builds a product — in ONE landing: @@ -93,6 +93,30 @@ way cirrus-baseline v22 builds a product — in ONE landing: - the e2e tier migrates a local Postgres with the product's own runner, builds in the job tree orun stages, and signs a user up with no Stripe key +## SA6 — the cirrus standard (SA-7) ✅ + +Bring the baseline to cirrus-baseline's standard, with nothing about the app +itself changing. + +- **No kiox.** `kiox.yaml`/`kiox.lock` pinned an orun (v2.15.0) that nothing + ran: every workflow installs orun itself through `orun-action` with its own + `version:`. The files, their two modules and the rebrand's skip entry go. +- **Component docs.** `tooling/catalog/gen-component-docs.py` writes each of + the seven components' `docs/overview.md`, `docs/architecture.md` and + `docs/runbook.md` from what the component declares, as cirrus-baseline's + do; the pages ship with the component. Baseline CI runs it with `--check`. +- **The context pack.** `ai/context/current.md`, `decisions.md` and + `open-risks.md` beside the two pages a product ships with — this + repository's own, so no module places them. +- **Status that agrees with the tags.** SA5 is shipped and tagged. + +**Done when** +- nothing outside this milestone's own record names kiox (`git grep -i + kiox`), and the leak gate and the offline bootstrap pass without the two + modules +- the docs check is green in Baseline CI +- this file, the status file and `epic.yaml` agree + ## Sequencing note SA1's component already names `cloudflare-hyperdrive` and `db-migrate` and diff --git a/tasks/SA-7.TaskContract.yaml b/tasks/SA-7.TaskContract.yaml new file mode 100644 index 0000000..1c449cb --- /dev/null +++ b/tasks/SA-7.TaskContract.yaml @@ -0,0 +1,32 @@ +apiVersion: orun.io/v1 +kind: TaskContract +metadata: + name: SA-7 + title: "The cirrus standard" +spec: + goal: The baseline meets cirrus-baseline's standard — no kiox pin (orun is pinned where CI runs it), every component documented by generated overview/architecture/runbook pages that CI keeps in step with the manifests, the agent context pack, and status documents that agree with the tags + affects: + - kiox.yaml + - kiox.lock + - repo-blueprint.yaml + - testing/phases.test.sh + - tooling/rebrand/** + - tooling/catalog/** + - .github/workflows/baseline.yml + - apps/web/docs/** + - packages/db/docs/** + - infra/db-migrate/docs/** + - infra/terraform/supabase/docs/** + - infra/terraform/cloudflare-hyperdrive/docs/** + - tests/web/docs/** + - tests/db/docs/** + - ai/context/** + - specs/** + - tasks/** + doneWhen: + - nothing outside this milestone's own record names kiox, and the leak gate and the offline bootstrap place a product without it + - every component has docs/overview.md, docs/architecture.md and docs/runbook.md, and `python3 tooling/catalog/gen-component-docs.py --check` is green in Baseline CI + - ai/context carries current.md, decisions.md and open-risks.md for this repository (none of them ships) + - every milestone's status row agrees with the tags + gates: + - checks diff --git a/testing/phases.test.sh b/testing/phases.test.sh index 7a62c7b..871ea83 100755 --- a/testing/phases.test.sh +++ b/testing/phases.test.sh @@ -47,7 +47,7 @@ if not phases: PRODUCT = ["ai-deployment", "ai-operations", "cloudflare-hyperdrive", "db", "db-migrate", "db-tests", "github-workflows", "rebrand-values", "root-gitignore", "root-intent", - "root-kiox", "root-kiox-lock", "root-package-json", "root-pnpm-lock", + "root-package-json", "root-pnpm-lock", "root-pnpm-workspace", "root-readme", "root-turbo", "supabase", "tooling-eslint", "tooling-migrations", "tooling-tsconfig", "tooling-wire", "vscode", "web", "web-tests"] diff --git a/tests/db/docs/architecture.md b/tests/db/docs/architecture.md new file mode 100644 index 0000000..40a7e32 --- /dev/null +++ b/tests/db/docs/architecture.md @@ -0,0 +1,8 @@ +# db-tests — architecture + +A test package at `tests/db`. Its lane runs the suite before it builds. + +## Suites (2) + +- `migrations.test.ts` +- `row-level-security.test.ts` diff --git a/tests/db/docs/overview.md b/tests/db/docs/overview.md new file mode 100644 index 0000000..ea4ef3f --- /dev/null +++ b/tests/db/docs/overview.md @@ -0,0 +1,18 @@ +# db-tests + +The test suite for **db**. It deploys nothing: its lane installs, builds and runs the tests. + +| | | +| ------------ | -------------------- | +| Type | `turbo-package` | +| Source | `tests/db` | +| Package | `@app/db-tests` | +| Environments | `dev`: `quick-check` | + +## Depends on + +- (none) + +## Depended on by + +- (none) diff --git a/tests/db/docs/runbook.md b/tests/db/docs/runbook.md new file mode 100644 index 0000000..aa64499 --- /dev/null +++ b/tests/db/docs/runbook.md @@ -0,0 +1,26 @@ +# db-tests — runbook + +## How it runs + +Its lane runs on every pull request that changes it; it has no deployed surface. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Local commands + +```bash +pnpm --filter @app/db-tests build +pnpm --filter @app/db-tests test +pnpm --filter @app/db-tests typecheck +pnpm --filter @app/db-tests lint +``` + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **A dependent fails to build after a change here**: run `pnpm typecheck` + across the workspace before merging. diff --git a/tests/web/docs/architecture.md b/tests/web/docs/architecture.md new file mode 100644 index 0000000..679f9a6 --- /dev/null +++ b/tests/web/docs/architecture.md @@ -0,0 +1,12 @@ +# web-tests — architecture + +A test package at `tests/web`. Its lane runs the suite before it builds. + +## Suites (6) + +- `auth-secret.test.ts` +- `proxy.test.ts` +- `session.test.ts` +- `stripe-not-connected.test.ts` +- `stripe-webhook.test.ts` +- `wrangler-config.test.ts` diff --git a/tests/web/docs/overview.md b/tests/web/docs/overview.md new file mode 100644 index 0000000..3534e6b --- /dev/null +++ b/tests/web/docs/overview.md @@ -0,0 +1,18 @@ +# web-tests + +The test suite for **web**. It deploys nothing: its lane installs, builds and runs the tests. + +| | | +| ------------ | -------------------- | +| Type | `turbo-package` | +| Source | `tests/web` | +| Package | `@app/web-tests` | +| Environments | `dev`: `quick-check` | + +## Depends on + +- (none) + +## Depended on by + +- (none) diff --git a/tests/web/docs/runbook.md b/tests/web/docs/runbook.md new file mode 100644 index 0000000..c687de2 --- /dev/null +++ b/tests/web/docs/runbook.md @@ -0,0 +1,26 @@ +# web-tests — runbook + +## How it runs + +Its lane runs on every pull request that changes it; it has no deployed surface. +CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`; +the plan orders a component after everything it depends on. + +## Local commands + +```bash +pnpm --filter @app/web-tests build +pnpm --filter @app/web-tests test +pnpm --filter @app/web-tests typecheck +pnpm --filter @app/web-tests lint +``` + +## Rollback + +Revert the commit on `main`. The next convergence applies the previous desired +state; nothing was changed out of band, so there is nothing else to undo. + +## Common failures + +- **A dependent fails to build after a change here**: run `pnpm typecheck` + across the workspace before merging. diff --git a/tooling/catalog/gen-component-docs.py b/tooling/catalog/gen-component-docs.py new file mode 100644 index 0000000..9a39931 --- /dev/null +++ b/tooling/catalog/gen-component-docs.py @@ -0,0 +1,547 @@ +#!/usr/bin/env python3 +"""Generate each component's docs (overview / architecture / runbook). + + 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 +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 +deploy fills in), its Terraform (resources and outputs), its migrations and its +package scripts. A hand-written copy of those facts drifts the first time one +changes; a generated one cannot, because `--check` fails the pull request that +changes the fact without the page. + +What is NOT derivable (why a component exists, what a failure means for this +product in particular) belongs in the component's `description` and in the +product's own docs, not here. + +The pages ship with the component into every product built from this tree, so +they say nothing about where they came from: no factory paths, no generator +path, no provenance. Zero dependencies beyond PyYAML. +""" + +from __future__ import annotations + +import json +import pathlib +import re +import sys + +try: + import yaml +except ImportError: # pragma: no cover - the contract job installs it + sys.exit("gen-component-docs needs PyYAML (pip install pyyaml)") + +ROOT = pathlib.Path(__file__).resolve().parents[2] +ROOTS = ("apps", "packages", "infra", "tests") +SKIP_DIRS = {"node_modules", "dist", ".turbo", "docs", ".next", ".open-next", + ".wrangler", ".svelte-kit", ".nuxt", ".output", ".astro", "coverage"} + +# Paths a shipped page must never name: products are not placed with them. +FACTORY = re.compile( + r"repo-blueprint|BOOTSTRAP\.md|(? str: + """JSONC → JSON: drop comments outside strings, then trailing commas.""" + out, i, n, in_str = [], 0, len(text), False + while i < n: + c = text[i] + if in_str: + out.append(c) + if c == "\\" and i + 1 < n: + out.append(text[i + 1]) + i += 2 + continue + if c == '"': + in_str = False + i += 1 + continue + if c == '"': + in_str = True + out.append(c) + i += 1 + elif text.startswith("//", i): + j = text.find("\n", i) + i = n if j < 0 else j + elif text.startswith("/*", i): + j = text.find("*/", i + 2) + i = n if j < 0 else j + 2 + else: + out.append(c) + i += 1 + return re.sub(r",(\s*[}\]])", r"\1", "".join(out)) + + +def read_json(path: pathlib.Path) -> dict | None: + try: + return json.loads(strip_jsonc(path.read_text(encoding="utf-8"))) + except (OSError, ValueError): + return None + + +def rel(p: pathlib.Path) -> str: + return p.relative_to(ROOT).as_posix() + + +def discover() -> list[dict]: + found = [] + for root in ROOTS: + base = ROOT / root + if not base.is_dir(): + continue + stack = [base] + while stack: + d = stack.pop() + for entry in sorted(d.iterdir()): + if entry.is_dir(): + if entry.name in SKIP_DIRS or entry.name.startswith("."): + continue + if (entry / "main.tf").exists() and not (entry / "component.yaml").exists(): + continue + if len(entry.relative_to(base).parts) <= 3: + stack.append(entry) + elif entry.name == "component.yaml": + found.append(read_component(entry)) + comps = [c for c in found if c["name"] and c["type"]] + return sorted(comps, key=lambda c: c["name"]) + + +def read_component(file: pathlib.Path) -> dict: + doc = yaml.safe_load(file.read_text(encoding="utf-8")) or {} + meta, spec = doc.get("metadata") or {}, doc.get("spec") or {} + params = spec.get("parameters") or {} + deps = [d.get("component") for d in (spec.get("dependsOn") or []) if isinstance(d, dict)] + envs = [] + # Secrets may be declared for the whole component or per environment + # (`subscribe.environments[].secretEnv`); a page lists both. + req_env = set((spec.get("secretEnv") or {}).keys()) + opt_env = set((spec.get("optionalSecretEnv") or {}).keys()) + for e in ((spec.get("subscribe") or {}).get("environments") or []): + req_env |= set((e.get("secretEnv") or {}).keys()) + opt_env |= set((e.get("optionalSecretEnv") or {}).keys()) + rules = [(r.get("profile"), ((r.get("when") or {}).get("triggerRef"))) + for r in (e.get("profileRules") or [])] + envs.append({"name": e.get("name"), "profile": e.get("profile"), "rules": rules}) + return { + "dir": file.parent, + "path": rel(file.parent), + "name": meta.get("name"), + "description": (meta.get("description") or "").strip(), + "type": spec.get("type"), + "deps": [d for d in deps if d], + "secret_env": sorted(req_env), + "optional_env": sorted(opt_env - req_env), + "envs": envs, + "params": params, + "migrations_path": spec.get("path") if spec.get("type") == "db-migrate" else None, + } + + +def package_of(c: dict) -> dict | None: + return read_json(c["dir"] / "package.json") + + +def worker_config(c: dict) -> tuple[str | None, dict | None]: + """The config a deploy uses: the template when wiring renders one.""" + names = ["wrangler.template.jsonc", c["params"].get("wranglerConfig") or "", + "wrangler.jsonc", "wrangler.json"] + for name in names: + if name and (c["dir"] / name).is_file(): + return name, read_json(c["dir"] / name) + return None, None + + +WIRING = re.compile(r"@@wiring\(([^/)]+)/__ENV__:([^)]+)\)@@") + + +def wired(value) -> str | None: + m = WIRING.search(str(value)) if value is not None else None + return f"`{m.group(2)}` from `{m.group(1)}`" if m else None + + +def bindings(cfg: dict) -> list[tuple[str, str, str]]: + rows = [] + for kv in cfg.get("kv_namespaces") or []: + rows.append((kv.get("binding"), "Workers KV namespace", wired(kv.get("id")) or "declared in the config")) + for b in cfg.get("r2_buckets") or []: + rows.append((b.get("binding"), "R2 bucket", wired(b.get("bucket_name")) or f"`{b.get('bucket_name')}`")) + for d in cfg.get("d1_databases") or []: + rows.append((d.get("binding"), "D1 database", wired(d.get("database_id")) or "declared in the config")) + for h in cfg.get("hyperdrive") or []: + rows.append((h.get("binding"), "Hyperdrive (pooled Postgres)", wired(h.get("id")) or "declared in the config")) + if isinstance(cfg.get("ai"), dict) and cfg["ai"].get("binding"): + rows.append((cfg["ai"]["binding"], "Workers AI", "account-level; no resource to provision")) + for d in ((cfg.get("durable_objects") or {}).get("bindings") or []): + rows.append((d.get("name"), "Durable Object", f"class `{d.get('class_name')}`")) + for s in cfg.get("services") or []: + rows.append((s.get("binding"), "Service binding", f"Worker `{s.get('service')}`")) + for q in ((cfg.get("queues") or {}).get("producers") or []): + rows.append((q.get("binding"), "Queue producer", f"queue `{q.get('queue')}`")) + for r in cfg.get("ratelimits") or []: + simple = r.get("simple") or {} + rows.append((r.get("name"), "Rate limiter", + f"{simple.get('limit')} requests / {simple.get('period')}s per location")) + assets = cfg.get("assets") or {} + if assets.get("binding"): + rows.append((assets["binding"], "Static assets", f"`{assets.get('directory')}`")) + return [r for r in rows if r[0]] + + +def tf_facts(c: dict) -> dict: + tf_dir = c["dir"] / (c["params"].get("terraformDir") or "terraform") + resources, outputs, variables, backend = [], [], [], None + for f in sorted(tf_dir.glob("*.tf")) if tf_dir.is_dir() else []: + text = f.read_text(encoding="utf-8") + resources += [f"{t}.{n}" for t, n in re.findall(r'^resource\s+"([^"]+)"\s+"([^"]+)"', text, re.M)] + outputs += re.findall(r'^output\s+"([^"]+)"', text, re.M) + variables += re.findall(r'^variable\s+"([^"]+)"', text, re.M) + m = re.search(r'backend\s+"([^"]+)"', text) + backend = backend or (m.group(1) if m else None) + imports = (tf_dir / "adopt.tf").is_file() if tf_dir.is_dir() else False + return {"dir": rel(tf_dir) if tf_dir.is_dir() else None, "resources": resources, + "outputs": outputs, "variables": variables, "backend": backend, "adopt": imports} + + +def published(c: dict) -> list[tuple[str, str]]: + spec = c["params"].get("secretOutputs") or "" + pairs = [] + for part in str(spec).split(","): + if "=" in part: + k, v = part.split("=", 1) + pairs.append((k.strip(), v.strip())) + return pairs + + +def test_files(c: dict) -> list[str]: + out = [] + for p in sorted(c["dir"].rglob("*")): + if any(part in SKIP_DIRS for part in p.relative_to(c["dir"]).parts): + continue + if p.is_file() and re.search(r"\.(test|spec)\.(ts|tsx|js|mjs|cjs)$", p.name): + out.append(p.name) + return out + + +def migrations(c: dict) -> list[str]: + path = c["migrations_path"] + if not path: + return [] + d = ROOT / path + if not d.is_dir(): + return [] + return sorted(p.name for p in d.iterdir() if p.is_dir() or p.suffix == ".sql") + + +# ── markdown ───────────────────────────────────────────────────────────── + +def md_table(header: list[str], rows: list[list[str]]) -> list[str]: + """A table laid out the way prettier lays it out, so a repo whose lint is + `prettier --check` accepts the page as written.""" + cols = len(header) + width = [max(3, len(header[i]), *(len(r[i]) for r in rows)) for i in range(cols)] + def line(cells): + return "| " + " | ".join(c.ljust(width[i]) for i, c in enumerate(cells)) + " |" + return [line(header), "| " + " | ".join("-" * w for w in width) + " |", *(line(r) for r in rows)] + + +# ── phrasing ───────────────────────────────────────────────────────────── + +KIND = { + "cloudflare-worker-turbo": "A Cloudflare Worker, deployed per environment by its CI lane.", + "cloudflare-workers-assets-turbo": "A Cloudflare Worker with Static Assets (server rendering plus " + "static files), deployed per environment by its CI lane.", + "terraform": "Terraform-managed infrastructure, planned and applied per environment by its CI lane.", + "db-migrate": "Applies this repository's ordered database migrations per environment: " + "plan on pull requests, apply on merge to `main`.", + "turbo-package": "A workspace package built by the turbo pipeline. It deploys nothing itself: " + "its lane type-checks, lints, tests and builds it.", +} + +TRIGGER = {"github-push-main": "a push to `main`", "github-pull-request": "a pull request"} + + +def env_line(e: dict) -> str: + s = f"`{e['name']}`: `{e['profile']}`" + for profile, ref in e["rules"]: + s += f", `{profile}` on {TRIGGER.get(ref, f'`{ref}`')}" + return s + + +def is_tests(c: dict) -> bool: + return c["name"].endswith("-tests") or c["path"].startswith("tests/") + + +def subject_of(c: dict, by_name: dict) -> str | None: + if c["name"].endswith("-tests"): + s = c["name"][: -len("-tests")] + return s if s in by_name else None + return None + + +def names_list(c: dict, keep) -> list[str]: + """Secret names a lane resolves, required first; an optional one (from + `optionalSecretEnv`) is resolved when it exists and skipped when not.""" + req = [f"- `{k}`" for k in c["secret_env"] if keep(k)] + opt = [f"- `{k}` (optional)" for k in c["optional_env"] if keep(k)] + return req + opt + + +def bullet_list(names: list[str], by_name: dict) -> list[str]: + if not names: + return ["- (none)"] + out = [] + for n in names: + d = by_name.get(n) + out.append(f"- **{n}** — {d['description']}" if d and d["description"] else f"- **{n}**") + return out + + +# ── pages ──────────────────────────────────────────────────────────────── + +def overview(c: dict, by_name: dict, dependents: list[str]) -> str: + pkg = package_of(c) + kind = KIND.get(c["type"], f"A `{c['type']}` component.") + subject = subject_of(c, by_name) + if is_tests(c): + kind = (f"The test suite for **{subject}**. " if subject else "A test suite. ") + \ + "It deploys nothing: its lane installs, builds and runs the tests." + lines = [f"# {c['name']}", ""] + if c["description"]: + lines += [c["description"], ""] + facts = [["Type", f"`{c['type']}`"], ["Source", f"`{c['path']}`"]] + if pkg and pkg.get("name"): + facts.append(["Package", f"`{pkg['name']}`"]) + if c["envs"]: + facts.append(["Environments", " · ".join(env_line(e) for e in c["envs"])]) + lines += [kind, "", *md_table(["", ""], facts)] + lines += ["", "## Depends on", "", *bullet_list(c["deps"], by_name), + "", "## Depended on by", "", *bullet_list(dependents, by_name), ""] + return "\n".join(lines) + + +def architecture(c: dict, by_name: dict) -> str: + lines = [f"# {c['name']} — architecture", ""] + t = c["type"] + + if t == "terraform": + f = tf_facts(c) + lines += [f"A `terraform` root at `{f['dir'] or c['path']}`.", ""] + if f["backend"] == "http": + lines += ["- **State** lives in the Orun Cloud HTTP state backend — no local state and", + " no state bucket to manage."] + lines += ["- **Credentials are brokered per run** from the workspace's provider", + " connections and resolved by name; none is stored in this repository."] + if f["adopt"]: + lines += ["- **Adoption** (`adopt.tf`): when state is empty but the resource already", + " exists, plan-time import adopts it instead of failing."] + lines.append("") + if f["resources"]: + lines += ["## Resources", "", *[f"- `{r}`" for r in f["resources"]], ""] + pub = published(c) + if pub: + lines += ["## Published outputs", "", + "Written as job-output secrets on each environment after an apply; deploy", + "lanes downstream resolve them by name.", "", + *md_table(["Secret", "Terraform output"], [[f"`{k}`", f"`{v}`"] for k, v in pub]), ""] + elif f["outputs"]: + lines += ["## Outputs", "", *[f"- `{o}`" for o in f["outputs"]], ""] + if c["secret_env"] or c["optional_env"]: + lines += ["## Resolved at run time (names only)", "", *names_list(c, lambda k: True), ""] + return "\n".join(lines) + + if t == "db-migrate": + migs = migrations(c) + lines += [f"Applies the migrations under `{c['migrations_path']}` in order, recording each one", + "it applies so a run only ever applies what is new. An already-applied migration", + "is never edited: a change is a new, later migration.", ""] + if migs: + lines += ["## Migrations", "", *[f"- `{m}`" for m in migs], ""] + if c["secret_env"] or c["optional_env"]: + lines += ["## Resolved at run time (names only)", "", *names_list(c, lambda k: True), ""] + return "\n".join(lines) + + pkg = package_of(c) + if t.startswith("cloudflare-"): + cfg_name, cfg = worker_config(c) + lines += [f"Built by the turbo pipeline from `{c['path']}` and deployed with wrangler.", ""] + if cfg: + facts = [["Worker config", f"`{c['path']}/{cfg_name}`"]] + if cfg.get("main"): + facts.append(["Entry", f"`{cfg['main']}`"]) + if cfg.get("compatibility_date"): + facts.append(["Compatibility date", f"`{cfg['compatibility_date']}`"]) + if cfg.get("compatibility_flags"): + facts.append(["Compatibility flags", ", ".join(f"`{x}`" for x in cfg["compatibility_flags"])]) + lines += [*md_table(["", ""], facts), ""] + rows = bindings(cfg) + lines += ["## Bindings", ""] + if rows: + lines += [*md_table(["Binding", "Kind", "Source"], [[f"`{b}`", k, s] for b, k, s in rows]), ""] + if any("from `" in s for _, _, s in rows): + lines += ["Identifiers marked _from_ a component are filled in at deploy time from", + "that component's published outputs for the environment being deployed.", ""] + else: + lines += ["None: the Worker binds no storage or service.", ""] + crons = (cfg.get("triggers") or {}).get("crons") or [] + if crons: + lines += ["## Scheduled triggers", "", *[f"- `{x}`" for x in crons], ""] + env_names = sorted((cfg.get("env") or {}).keys()) + var_names = sorted((cfg.get("vars") or {}).keys()) + if var_names: + lines += ["## Variables", "", ", ".join(f"`{v}`" for v in var_names) + + (f" — overridden per environment ({', '.join(f'`{e}`' for e in env_names)})." + if env_names else "."), ""] + wiring = names_list(c, lambda k: k.startswith("WIRING_")) + others = names_list(c, lambda k: not k.startswith("WIRING_")) + if wiring: + lines += ["## Wiring", "", + "Resolved at deploy time from secrets the infrastructure lanes publish (names only):", + "", *wiring, ""] + if others: + lines += ["## Secrets resolved by the lane (names only)", "", *others, ""] + return "\n".join(lines) + + # turbo-package + if is_tests(c): + files = test_files(c) + lines += [f"A test package at `{c['path']}`. Its lane runs the suite before it builds.", ""] + if files: + lines += [f"## Suites ({len(files)})", "", *[f"- `{f}`" for f in files], ""] + return "\n".join(lines) + lines += [f"A workspace package at `{c['path']}`, consumed by the components that depend", + "on it. It has no deployed surface of its own.", ""] + if pkg and pkg.get("exports"): + ex = pkg["exports"] + keys = sorted(ex.keys()) if isinstance(ex, dict) else ["."] + lines += ["## Exports", "", *[f"- `{k}`" for k in keys], ""] + return "\n".join(lines) + + +def runbook(c: dict, by_name: dict) -> str: + t = c["type"] + pkg = package_of(c) + lines = [f"# {c['name']} — runbook", "", "## How it runs", ""] + deploys = [e["name"] for e in c["envs"] + if any(ref == "github-push-main" for _, ref in e["rules"])] + if deploys and t in ("terraform", "db-migrate"): + lines += [f"Pull requests plan it; a merge to `main` applies it to " + f"{', '.join(f'`{e}`' for e in deploys)}."] + elif deploys: + lines += [f"Pull requests verify it; a merge to `main` deploys it to " + f"{', '.join(f'`{e}`' for e in deploys)}."] + else: + lines += ["Its lane runs on every pull request that changes it; it has no deployed surface."] + lines += ["CI plans what changed (`orun plan --changed`) and runs each lane with `orun run`;", + "the plan orders a component after everything it depends on.", ""] + + if pkg and pkg.get("scripts"): + name = pkg.get("name") + wanted = [s for s in ("dev", "build", "test", "typecheck", "lint", "preview") if s in pkg["scripts"]] + if name and wanted: + lines += ["## Local commands", "", "```bash", + *[f"pnpm --filter {name} {s}" for s in wanted], "```", ""] + + smoke = c["params"].get("smokeCommand") + if smoke and "No smoke" not in str(smoke): + lines += ["## Verify", "", "After a deploy the lane runs this smoke against the environment it", + "deployed (`ORUN_ENVIRONMENT`); `DEPLOYED_URL` overrides the URL:", "", + "```bash", str(smoke).strip(), "```", ""] + + lines += ["## Rollback", "", + "Revert the commit on `main`. The next convergence applies the previous desired", + "state; nothing was changed out of band, so there is nothing else to undo.", "", + "## Common failures", ""] + if t == "terraform": + lines += ["- **Provider authentication fails**: the workspace's provider connection is", + " missing or revoked. Reconnect it in the console; credentials are brokered", + " from it per run.", + "- **\"Already exists\" on a first apply**: state is empty but the resource is", + " not." + (" `adopt.tf` imports it at plan time; if it still fails, the resource" + " was renamed outside Terraform." if tf_facts(c)["adopt"] else + " Import it, or delete the stray resource, then re-run."), ""] + elif t == "db-migrate": + lines += ["- **An applied migration's file changed**: the run stops rather than guess.", + " Restore the file and write the change as a new migration.", + "- **The database is unreachable**: the infrastructure lane it depends on has", + " not applied for this environment; that lane runs first in a convergence.", ""] + elif t.startswith("cloudflare-"): + _, cfg = worker_config(c) + takes_wiring = any(k.startswith("WIRING_") for k in c["secret_env"] + c["optional_env"]) or \ + bool(cfg and WIRING.search(json.dumps(cfg))) + if takes_wiring: + lines += ["- **A `WIRING_*` secret is missing at deploy**: an infrastructure lane upstream", + " has not applied for this environment yet. Within one convergence the plan", + " runs it first; on its own, re-run that lane."] + lines += ["- **The smoke fails right after a first deploy**: a new workers.dev route can", + " answer 4xx for a few seconds and the lane retries. A failure that persists", + " is a regression in the deployed code.", ""] + else: + lines += ["- **A dependent fails to build after a change here**: run `pnpm typecheck`", + " across the workspace before merging.", ""] + return "\n".join(lines) + + +# ── main ───────────────────────────────────────────────────────────────── + +def main() -> int: + check = "--check" in sys.argv[1:] + comps = discover() + if not comps: + print("no component.yaml found", file=sys.stderr) + return 1 + by_name = {c["name"]: c for c in comps} + dependents: dict[str, list[str]] = {c["name"]: [] for c in comps} + for c in comps: + for d in c["deps"]: + dependents.setdefault(d, []).append(c["name"]) + + drifted, written, leaks = [], 0, [] + for c in comps: + pages = { + "overview.md": overview(c, by_name, sorted(dependents.get(c["name"], []))), + "architecture.md": architecture(c, by_name), + "runbook.md": runbook(c, by_name), + } + for fname, body in pages.items(): + target = c["dir"] / "docs" / fname + for n, line in enumerate(body.splitlines(), 1): + m = FACTORY.search(line) + if m: + leaks.append(f"{rel(target)}:{n} would name {m.group(0)!r}") + current = target.read_text(encoding="utf-8") if target.exists() else None + if current == body: + continue + if check: + drifted.append(rel(target)) + continue + target.parent.mkdir(parents=True, exist_ok=True) + target.write_text(body, encoding="utf-8") + written += 1 + + if leaks: + print("✗ a generated page would name a path products do not have:", file=sys.stderr) + for l in leaks: + print(f" {l}", file=sys.stderr) + return 1 + if check: + if drifted: + print(f"✗ {len(drifted)} component doc(s) differ from what the manifests say:", file=sys.stderr) + for f in drifted: + print(f" {f}", file=sys.stderr) + print("\nRun: python3 tooling/catalog/gen-component-docs.py", file=sys.stderr) + return 1 + print(f"✓ component docs match {len(comps)} component.yaml file(s)") + return 0 + print(f"✓ wrote {written} page(s) for {len(comps)} component(s)") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tooling/rebrand/rebrand.mjs b/tooling/rebrand/rebrand.mjs index 331874d..fa0f6d6 100644 --- a/tooling/rebrand/rebrand.mjs +++ b/tooling/rebrand/rebrand.mjs @@ -180,7 +180,6 @@ const EXCLUDE_RE = new RegExp( // product claim to be a baseline called by the product's own name. "^\\.baseline/", "^pnpm-lock\\.yaml$", - "^kiox\\.lock$", // Migrations are immutable once applied: db-migrate compares each file's // sha256 to packages/db/src/manifest.ts and to the database's ledger, so // a byte renamed here would stop every later deploy. (None names this From 5501942dfc90b21390a2de11dc06bdba9bc99cab Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 21 Oct 2026 12:08:23 +0000 Subject: [PATCH 2/2] SA6: read the workers.dev subdomain from the Cloudflare connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - blueprint.yaml: `subdomain` is `from: connection.cloudflare.workersSubdomain`, as cirrus-baseline since baseline-v23 — the console renders no field for it; the bootstrap door fills it from the connection the build is bound to. - testing/manifest.test.sh takes cirrus-baseline's rule verbatim: the source is accepted only when spec.requires.integrations lists its provider (mutation-checked). - repo-blueprint.yaml, BOOTSTRAP.md and docs/phases/README.md say only a hand-run build passes --set subdomain. - Record it as SA-8, SA6's second task; SA6 ships as baseline-v2 (#7). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01D8AmgTwmnp4M8mgmnS9aha --- BOOTSTRAP.md | 6 +++ ai/context/current.md | 11 +++-- ai/context/decisions.md | 1 + blueprint.yaml | 12 ++++++ docs/phases/README.md | 6 ++- repo-blueprint.yaml | 6 ++- specs/epics/README.md | 2 +- .../saas-starter/IMPLEMENTATION-STATUS.md | 40 ++++++++++++++++++- specs/epics/saas-starter/README.md | 6 +-- specs/epics/saas-starter/design.md | 3 +- specs/epics/saas-starter/epic.yaml | 3 +- .../epics/saas-starter/implementation-plan.md | 7 ++++ tasks/SA-8.TaskContract.yaml | 25 ++++++++++++ testing/manifest.test.sh | 15 ++++++- 14 files changed, 125 insertions(+), 18 deletions(-) create mode 100644 tasks/SA-8.TaskContract.yaml diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index 74cd8ae..2e338d0 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -62,6 +62,12 @@ orun new --blueprint repo-blueprint.yaml \ --set subdomain= ``` +`subdomain` is the workers.dev subdomain of the Cloudflare account you deploy +into (Workers & Pages → your subdomain). A build started from the console, or +with `orun baseline new --from bst_…`, never asks for it: the platform reads +it from the workspace's Cloudflare connection, the same one the deploy tokens +mint from. Only a hand-run build like this one passes it. + **`--run-hooks` is the difference between placing files and bootstrapping a product.** Without it `orun new` writes the tree and stops: no repository, no landing, no convergence watch, no probe. That is deliberate — it is what diff --git a/ai/context/current.md b/ai/context/current.md index 634d98f..73edf89 100644 --- a/ai/context/current.md +++ b/ai/context/current.md @@ -24,8 +24,8 @@ and serves without it. | | | |---|---| -| Latest tag | `baseline-v1` (SA5, [#6](https://github.com/sourceplane/saas-starter/pull/6)) | -| On `main` since | SA6 — the cirrus standard (no kiox, generated component docs, this context pack) | +| Latest tag | `baseline-v2` (SA6, [#7](https://github.com/sourceplane/saas-starter/pull/7) — the cirrus standard: no kiox, generated component docs, this context pack, and the workers.dev subdomain read from the Cloudflare connection instead of asked) | +| Before it | `baseline-v1` (SA5, [#6](https://github.com/sourceplane/saas-starter/pull/6) — the baseline) | | Proven live | No. Everything short of the platform is proven offline in Baseline CI: the e2e tier migrates a local Postgres with the product's own runner, builds in orun's staged job tree, and signs a user up and in with no Stripe key and no `AUTH_SECRET`. No bootstrap from a tag has run against a workspace: neither Terraform root has been applied, db-migrate has not run against a real project, nothing has deployed, and the card's twenty minutes is unmeasured (SA-M) | ## Where to read @@ -40,7 +40,6 @@ and serves without it. ## Next -1. Bootstrap one product from a tag against a workspace with Cloudflare and - Supabase connected, and record its timings (closes SA-M; settles SA-L's - table-owner check on a real project). -2. Cut the next `baseline-vN` with `tag.yml` so the registry can pin SA6. +1. Bootstrap one product from `baseline-v2` against a workspace with + Cloudflare and Supabase connected, and record its timings (closes SA-M; + settles SA-L's table-owner check on a real project). diff --git a/ai/context/decisions.md b/ai/context/decisions.md index fc96920..c7765e7 100644 --- a/ai/context/decisions.md +++ b/ai/context/decisions.md @@ -18,3 +18,4 @@ reads in order. | 10 | stack-tectonic 0.19.0, not 0.20.0 | 0.20.0's lane-scoped install is refused by Turbopack | `intent.yaml`, IMPLEMENTATION-STATUS (SA5) | | 11 | orun is pinned only where it runs (the `orun-action` `version:` in each workflow); no kiox | `kiox.yaml` pinned a version (v2.15.0) nothing ran | IMPLEMENTATION-STATUS (SA6) | | 12 | Component docs are generated from the manifests and checked in CI | A hand-written copy of the dependency graph and bindings drifts silently | `tooling/catalog/gen-component-docs.py` | +| 13 | `subdomain` is read from the Cloudflare connection (`from: connection.cloudflare.workersSubdomain`), never asked | It belongs to the account like its id and has one right answer; a typed one could only be wrong, and showed up after deploy in `BASE_URL`, the smoke and the probes | `blueprint.yaml`, IMPLEMENTATION-STATUS (SA-8) | diff --git a/blueprint.yaml b/blueprint.yaml index 864434b..1419d30 100644 --- a/blueprint.yaml +++ b/blueprint.yaml @@ -93,6 +93,18 @@ spec: pattern: "^[a-z0-9][a-z0-9-]{0,62}$" help: The workers.dev subdomain of the Cloudflare account the app deploys into. example: acme + # READ FROM THE CLOUDFLARE CONNECTION, not asked. The subdomain belongs + # to the account the same way its id does, and there is exactly one + # right answer — a typed one could only be wrong, and wrong showed up + # after deploy, in the BASE_URL Stripe returns to, the deploy's smoke, + # the phase probes and the verify URLs below. The integration reads it + # from Cloudflare at connect and on its hourly health check; the + # bootstrap door fills this input from the connection the build is + # BOUND to, the same one CLOUDFLARE_ACCOUNT_ID and the deploy tokens + # mint from, so all three name one account. The console renders no + # field for it. An account with no workers.dev subdomain refuses the + # build at the door, naming the fix, before anything is created. + from: connection.cloudflare.workersSubdomain # ── PREVIEW ONLY. repo-blueprint.yaml's `orun.integrations/reconcile@v1` # hooks mint these, brokered, during 01-product. ───────────────────────── diff --git a/docs/phases/README.md b/docs/phases/README.md index 1d6c69c..77b0f4f 100644 --- a/docs/phases/README.md +++ b/docs/phases/README.md @@ -59,8 +59,10 @@ the blueprint's **required** inputs — `reponame`, `productname`, must be supplied on every invocation, single-phase ones included. A `--values` file is easier than repeating `--set`. -- `subdomain` — the workers.dev subdomain of the Cloudflare account. It is - in every URL the phases probe and in the `BASE_URL` Stripe returns to. +- `subdomain` — the workers.dev subdomain of the Cloudflare account you + deploy into. It is in every URL the phases probe and in the `BASE_URL` + Stripe returns to. A console or `--from bst_…` build reads it from the + Cloudflare connection; pass it only for a hand-run build. - `orunWorkspace` — workspace id (`ws_…`). Unset, it is the workspace the build runs in (`from: workspace`); with none anywhere, a placeholder that fails loudly rather than silently claiming another tenant's workspace. diff --git a/repo-blueprint.yaml b/repo-blueprint.yaml index d4a430c..360e253 100644 --- a/repo-blueprint.yaml +++ b/repo-blueprint.yaml @@ -55,7 +55,11 @@ inputs: default: "your-workers-subdomain" description: >- The workers.dev subdomain of the Cloudflare account the app deploys - into — its URLs, the BASE_URL Stripe returns to, the probes. + into — its URLs, the BASE_URL Stripe returns to, the probes. A console + or `--from bst_…` build gets it from the workspace's Cloudflare + connection (blueprint.yaml declares + `from: connection.cloudflare.workersSubdomain`); pass it with --set + only for a hand-run build. repoPrivate: type: boolean default: true diff --git a/specs/epics/README.md b/specs/epics/README.md index e46b3a2..12563b6 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`saas-starter/`](./saas-starter/) | **SA** | ✅ Shipped (`baseline-v1`); live bootstrap pending | Vercel's Next.js SaaS Starter, equivalent in code and function, on Cloudflare Workers with Supabase Postgres through Hyperdrive — and an Orun baseline that instantiates it in one landing (SA5) | +| [`saas-starter/`](./saas-starter/) | **SA** | ✅ Shipped (`baseline-v2`); live bootstrap pending | Vercel's Next.js SaaS Starter, equivalent in code and function, on Cloudflare Workers with Supabase Postgres through Hyperdrive — and an Orun baseline that instantiates it in one landing (SA5) | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/saas-starter/IMPLEMENTATION-STATUS.md b/specs/epics/saas-starter/IMPLEMENTATION-STATUS.md index d1c95b8..eb54802 100644 --- a/specs/epics/saas-starter/IMPLEMENTATION-STATUS.md +++ b/specs/epics/saas-starter/IMPLEMENTATION-STATUS.md @@ -11,7 +11,7 @@ the code departed from `design.md` or from the upstream template. | SA3 — Supabase and Hyperdrive from Terraform | ✅ Shipped (validated; apply gated on a linked workspace) | [#4](https://github.com/sourceplane/saas-starter/pull/4) | | SA4 — ready to instantiate | ✅ Shipped | [#5](https://github.com/sourceplane/saas-starter/pull/5) | | SA5 — a baseline | ✅ Shipped | [#6](https://github.com/sourceplane/saas-starter/pull/6) (SA-6), tagged `baseline-v1` | -| SA6 — the cirrus standard | ✅ Shipped | SA-7 — on `main` after `baseline-v1`, not yet tagged | +| SA6 — the cirrus standard | ✅ Shipped | [#7](https://github.com/sourceplane/saas-starter/pull/7) (SA-7, SA-8), tagged `baseline-v2` | ## Departures from the upstream template @@ -232,6 +232,44 @@ Nothing about the app changed. What changed is the baseline around it: | context pack | `operations.md`, `deployment.md` | plus `current.md`, `decisions.md`, `open-risks.md` | cirrus-baseline's shape; the three new pages are this repository's own and no module places them (the leak gate still allows exactly two) | | status | SA5 "in review", on a branch | SA5 shipped and tagged `baseline-v1`; `design.md` §3/§5 list the four migrations and the supabase root as SA5 left them | the tag existed; the documents had not caught up | +### The subdomain from the Cloudflare connection (SA-8) + +`subdomain` was the one input an operator typed that the platform could +answer itself: it belongs to the Cloudflare account the same way its id does, +and it has exactly one right answer. A typed one could only be wrong, and +wrong showed up after deploy — in the `BASE_URL` Stripe returns to, the +deploy's smoke, the phase probes and the console's verify URLs. +`blueprint.yaml` now declares `from: connection.cloudflare.workersSubdomain`, +as cirrus-baseline does since baseline-v23: the Cloudflare integration reads +the subdomain at connect and on its hourly health check, and the bootstrap +door fills the input from the connection the build is bound to — the same one +`CLOUDFLARE_ACCOUNT_ID` and the deploy tokens mint from. The console renders +no field for it, and an account with no workers.dev subdomain is refused at +the door with the fix named. + +- `testing/manifest.test.sh` takes cirrus-baseline's rule verbatim (the file + is now byte-identical to cirrus-baseline's): the source is accepted, and + only when `spec.requires.integrations` lists its provider. +- `repo-blueprint.yaml` keeps the input and its default; it, `BOOTSTRAP.md` + and `docs/phases/README.md` say only a hand-run build passes + `--set subdomain`. +- Nothing a product carries changes: the rename, `BASE_URL`, the smoke and + the probes read the value exactly as before. + +Verified: + +- `testing/{manifest,phases,coverage,rebrand,retouch,bootstrap-defer}.test.sh` + green; `gen-component-docs.py --check` green (7 components). +- Mutation: with `cloudflare` dropped from `spec.requires.integrations`, + `manifest.test.sh` fails with exactly one finding, naming + `inputs[subdomain]`; restored, it passes. +- At v2.58.11 (the blueprint job's pin): `orun new --status` reads the + document (`01-product` pending, 159 files); `testing/leak.test.sh` 159 + files derived, 157 text files read; `testing/placement.test.sh` 159 files + placed, both landings, the product's own plan orders supabase → + cloudflare-hyperdrive → db-migrate → web on stage and prod, enforced. +- `orun task check SA-8` complete. + ## Verified (SA6) - `testing/{manifest,phases,coverage,rebrand,retouch,bootstrap-defer}.test.sh` diff --git a/specs/epics/saas-starter/README.md b/specs/epics/saas-starter/README.md index 89ccd2d..9762aef 100644 --- a/specs/epics/saas-starter/README.md +++ b/specs/epics/saas-starter/README.md @@ -8,7 +8,7 @@ The upstream code stays the code: the Drizzle schema and queries, the server act | Field | Value | |-------|-------| -| Status | ✅ SA0–SA5 shipped (#1–#6), tagged `baseline-v1`; SA6 (the cirrus standard, SA-7) on `main`, not yet tagged. Not yet proven by a live bootstrap: the Supabase and Hyperdrive applies, a live db-migrate apply and a live deploy (risk SA-M) | +| Status | ✅ SA0–SA5 shipped (#1–#6), tagged `baseline-v1`; SA6 (the cirrus standard, SA-7 and SA-8, #7) tagged `baseline-v2`. Not yet proven by a live bootstrap: the Supabase and Hyperdrive applies, a live db-migrate apply and a live deploy (risk SA-M) | | Cluster | **SA** (SA0–SA6) | | Owner(s) | `apps/web` (the app) · `packages/db` (the migrations and their runner) · `tests/web`, `tests/db` · `infra/terraform/supabase`, `infra/terraform/cloudflare-hyperdrive`, `infra/db-migrate` | | Builds on | `lumen` conventions — the `supabase` and `cloudflare-hyperdrive` Terraform roots, `@saas/db` + `db-migrate`, the per-request `postgres` client; `cirrus-baseline` conventions for the repository shape | @@ -16,7 +16,7 @@ The upstream code stays the code: the Drizzle schema and queries, the server act | Changes | Adds the Workers build, the monorepo wrapper, tests, the migrations package, the three infra components and the deploy contract; in the template's code: `lib/db/drizzle.ts` (per-request client), `middleware.ts` → `proxy.ts`, the Stripe client's fetch transport and the webhook's async signature check | | Decisions locked | (1) OpenNext on Workers + Static Assets. (2) Drizzle over a Postgres socket through Hyperdrive, not PostgREST and not D1. (3) A `postgres` client per request — never a module-level pool. (4) `wrangler.jsonc` rendered from the template: committed as the fixture render (the composition checks it exists before the build), re-rendered per environment from the Hyperdrive wiring document by the deploy lanes (SA5; it was never committed before). (5) drizzle-kit stays for local development; the runner applies in CI. (6) `STRIPE_SECRET_KEY` and `STRIPE_WEBHOOK_SECRET` are Worker secrets the owner adds when ready — the app deploys and serves without them (SA5); `AUTH_SECRET` is optional, the database generating the session key otherwise (SA5); `BASE_URL` is a wrangler var. (7) Infra before app on main: supabase → cloudflare-hyperdrive → db-migrate → web, enforced; advisory on pull requests (SA5). | | Gate | SA1 is the first user-visible rung. SA2 and SA3 need a workspace with Supabase and Cloudflare connections to apply; they are verified by `plan` and `terraform validate`. | -| Shipped as | `baseline-v1` ([#6](https://github.com/sourceplane/saas-starter/pull/6)), then SA6 on `main`; proven offline (Baseline CI: contract, leak, placement and the e2e tier over a local Postgres), deploy gated until a workspace is linked | +| Shipped as | `baseline-v1` ([#6](https://github.com/sourceplane/saas-starter/pull/6)), then `baseline-v2` (SA6: [#7](https://github.com/sourceplane/saas-starter/pull/7)); proven offline (Baseline CI: contract, leak, placement and the e2e tier over a local Postgres), deploy gated until a workspace is linked | ## Read order @@ -35,4 +35,4 @@ The upstream code stays the code: the Drizzle schema and queries, the server act | SA3 — Supabase and Hyperdrive from Terraform | `infra/terraform/supabase`, `infra/terraform/cloudflare-hyperdrive` | both roots validate; the wiring keys match the template's tokens | | SA4 — ready to instantiate | README, as-built status | a reader can run, seed, test, preview and deploy it | | SA5 — a baseline | card, build document, rename, bootstrap tooling, the product's README and context pack, tests | a new product goes from nothing to live on stage and prod in one landing, with no Stripe key; Baseline CI green | -| SA6 — the cirrus standard | no kiox, generated component docs, the context pack, status that agrees with the tags | Baseline CI green with the docs check | +| SA6 — the cirrus standard | no kiox, generated component docs, the context pack, status that agrees with the tags; the subdomain read from the Cloudflare connection | Baseline CI green with the docs check; the card asks for no subdomain | diff --git a/specs/epics/saas-starter/design.md b/specs/epics/saas-starter/design.md index 8b3b584..0296656 100644 --- a/specs/epics/saas-starter/design.md +++ b/specs/epics/saas-starter/design.md @@ -95,7 +95,8 @@ for `$ORUN_ENVIRONMENT` before they build (SA5; it was git-ignored before). `BASE_URL` is a var, not a secret, and not wired: no root knows the account's workers.dev subdomain. The template carries the same subdomain as `component.yaml` and `intent.yaml` (`your-workers-subdomain` here; a -bootstrap writes the product's own), or a custom domain. +bootstrap writes the product's own, which a console build reads from the +workspace's Cloudflare connection — SA-8), or a custom domain. On a push to main the four components converge in one run, per environment, in the order the arrows above imply — `supabase → cloudflare-hyperdrive → diff --git a/specs/epics/saas-starter/epic.yaml b/specs/epics/saas-starter/epic.yaml index e217fef..f7f0c99 100644 --- a/specs/epics/saas-starter/epic.yaml +++ b/specs/epics/saas-starter/epic.yaml @@ -52,4 +52,5 @@ spec: - "every component carries generated docs/{overview,architecture,runbook}.md, and Baseline CI fails a pull request whose manifests and pages disagree" - "ai/context carries this repository's current.md, decisions.md and open-risks.md, and none of them ships to a product" - "every milestone's status row agrees with the tags" - tasks: [SA-7] + - "the console card reads subdomain from the Cloudflare connection (from: connection.cloudflare.workersSubdomain), as cirrus-baseline since baseline-v23" + tasks: [SA-7, SA-8] diff --git a/specs/epics/saas-starter/implementation-plan.md b/specs/epics/saas-starter/implementation-plan.md index 116c996..161bc18 100644 --- a/specs/epics/saas-starter/implementation-plan.md +++ b/specs/epics/saas-starter/implementation-plan.md @@ -109,12 +109,19 @@ itself changing. `open-risks.md` beside the two pages a product ships with — this repository's own, so no module places them. - **Status that agrees with the tags.** SA5 is shipped and tagged. +- **The subdomain from the Cloudflare connection (SA-8).** The card declares + `subdomain` as `from: connection.cloudflare.workersSubdomain`, as + cirrus-baseline does since baseline-v23, so the console asks for nothing the + connection already knows; `testing/manifest.test.sh` requires the source's + provider in `spec.requires.integrations`. **Done when** - nothing outside this milestone's own record names kiox (`git grep -i kiox`), and the leak gate and the offline bootstrap pass without the two modules - the docs check is green in Baseline CI +- the card renders no subdomain field, and the manifest gate fails a + `connection.` source whose provider the card does not require - this file, the status file and `epic.yaml` agree ## Sequencing note diff --git a/tasks/SA-8.TaskContract.yaml b/tasks/SA-8.TaskContract.yaml new file mode 100644 index 0000000..380cc0c --- /dev/null +++ b/tasks/SA-8.TaskContract.yaml @@ -0,0 +1,25 @@ +apiVersion: orun.io/v1 +kind: TaskContract +metadata: + name: SA-8 + title: "The subdomain from the Cloudflare connection" +spec: + goal: "The console card reads the workers.dev subdomain from the workspace's Cloudflare connection (`from: connection.cloudflare.workersSubdomain`) instead of asking for it, as cirrus-baseline does since baseline-v23, and the manifest gate holds that source to a connection the card requires" + affects: + - blueprint.yaml + - repo-blueprint.yaml + - testing/manifest.test.sh + - BOOTSTRAP.md + - docs/phases/README.md + - ai/context/current.md + - ai/context/decisions.md + - specs/epics/README.md + - specs/epics/saas-starter/** + - tasks/SA-8.TaskContract.yaml + doneWhen: + - "blueprint.yaml declares `from: connection.cloudflare.workersSubdomain` on `subdomain`, so the console renders no field for it" + - testing/manifest.test.sh accepts that source only when spec.requires.integrations lists its provider, and fails naming the input when it does not (mutation-checked) + - BOOTSTRAP.md, docs/phases and repo-blueprint.yaml say only a hand-run build passes `--set subdomain` + - the contract tests, the docs check, the leak gate and the offline bootstrap are green + gates: + - checks diff --git a/testing/manifest.test.sh b/testing/manifest.test.sh index 3fd6af8..5374cb5 100755 --- a/testing/manifest.test.sh +++ b/testing/manifest.test.sh @@ -217,9 +217,20 @@ for path in manifests: # field for it (saas-bootstrap-console BC-K5). Two ways to get it # wrong, and the platform refuses both — check them here too, so the # mistake is caught in this repo rather than at a live bootstrap. + # + # A `connection..` source is read from the connection + # the build is bound to, so the provider must be one the manifest + # requires — the platform's parser refuses it otherwise. + sources_known = ("repo.name", "repo.owner", "repo.fullName", + "connection.cloudflare.workersSubdomain") src = field.get("from") - if src is not None and src not in ("repo.name", "repo.owner", "repo.fullName"): - B(f"inputs[{key}].from is {src!r} — must be repo.name, repo.owner or repo.fullName") + if src is not None and src not in sources_known: + B(f"inputs[{key}].from is {src!r} — must be one of {', '.join(sources_known)}") + if isinstance(src, str) and src.startswith("connection."): + provider = src.split(".")[1] + if provider not in ((spec.get("requires") or {}).get("integrations") or []): + B(f"inputs[{key}].from is {src!r} but spec.requires.integrations " + f"does not list {provider} — there is no connection to read it from") # ── secrets: BOTH or NEITHER, checked both ways ─────────────────────── declared = {s.get("key"): (s.get("provider"), s.get("template")) for s in (spec.get("secrets") or [])}