diff --git a/.baseline/product/AGENTS.md b/.baseline/product/AGENTS.md new file mode 100644 index 0000000..eed1542 --- /dev/null +++ b/.baseline/product/AGENTS.md @@ -0,0 +1,73 @@ +# AGENTS.md — {{ .productname }} + +How to work in `{{ .githuborg }}/{{ .reponame }}`, for coding agents and +the people running them. + +## What this is + +{{ .productname }} is a multi-tenant SaaS on Cloudflare alone. +`apps/api-edge` is the only public Worker; it reaches twelve bounded-context +Workers (`apps/*-worker`: identity, membership, projects, policy, events, +config, metering, billing, notifications, webhooks, integrations, admin) +over service bindings. `apps/web-console-next` is the console, and it talks +only to the edge. The data plane is a D1 database per environment and a KV +namespace for the edge's idempotency store. `stage` and `prod` deploy; `dev` +only verifies. + +## Read first, in this order + +1. [ai/context/operations.md](ai/context/operations.md) — the operating + contract: tenancy, how a merge deploys, the secrets model, how to verify. +2. [ai/context/deployment.md](ai/context/deployment.md) — the live URLs, the + workspace and the secrets by name. It reads "Not rendered yet" until the + bootstrap's last phase has written it. +3. [intent.yaml](intent.yaml) — environments, lanes, the pinned composition + stack and the workspace CI runs against. +4. [apps/api-edge/docs/overview.md](apps/api-edge/docs/overview.md) — the + edge and what it depends on. Every component carries the same three pages + in its `docs/`: overview, architecture, runbook. +5. `apps/web-console-next` — the console. +6. `packages/contracts` — the API, tenancy, event and error types the + Workers and the console share. A change to an API's shape starts here. + +## How a change lands + +- Everything deployable is an Orun component: a directory under `apps/`, + `infra/`, `packages/` or `tests/` with a `component.yaml`. Orun discovers + it, and `intent.yaml` says where it deploys. +- Before a pull request: `pnpm install`, `pnpm typecheck`, `pnpm lint`, + `pnpm test`; then `orun validate --intent intent.yaml` and + `orun plan --changed --intent intent.yaml` to see what CI will run. +- One task, one pull request. CI plans the changed components and verifies + them; the merge to `main` deploys them, `stage` first and then `prod`. +- A green run that planned no lanes deployed nothing. Check the outcome — + the URLs, the published secrets — as operations.md shows. +- A schema change is a new numbered directory with an `up.sql` under + `packages/db/src/migrations/`, registered with its checksum in + `packages/db/src/manifest.ts`. Never edit one that has been applied. + `infra/db-migrate` applies them on merge. D1 has no interactive + transactions: see the README. + +## Do not hand-edit + +- `ai/context/deployment.md`, and the README section between + `` and ``: both are regenerated + from probed state. +- `apps/*/wrangler.jsonc` of a Worker that has a `wrangler.template.jsonc`: + it is rendered at deploy time and gitignored. Edit the template. +- `pnpm-lock.yaml` (let pnpm write it), `.rebrand/values.json` (the record + of the inputs this product was built with) and, if present, + `apps/web-console-next/console-artifact.pin.json` (the prebuilt-console + pin). +- `execution.state.workspace` in `intent.yaml`: every remote operation, + CI's included, runs against that workspace. +- The last line of a `component.yaml` that reads `# orun: redeploy …` is a + deploy trigger, not configuration; nothing reads it back. + +## Secrets + +Never print or commit a secret value, and never put one in `ai/context/`. +The Cloudflare credentials are brokered per run from the workspace's +connection; runtime secrets are set with +`orun secrets set --org --env ` and inspected by +name only. diff --git a/.baseline/product/README.md b/.baseline/product/README.md new file mode 100644 index 0000000..5ddd11e --- /dev/null +++ b/.baseline/product/README.md @@ -0,0 +1,96 @@ +# {{ .productname }} + +A multi-tenant SaaS on Cloudflare alone, kept as an +[Orun](https://github.com/sourceplane/orun) desired-state repository: +twelve bounded-context Workers behind one public edge API, a Next.js console +on Workers + Static Assets, and Cloudflare D1 and KV as the data plane. +Merges to `main` deploy it to `stage` and `prod`. + +## Live deployment + + +Not recorded yet. The bootstrap's last phase probes every live URL and +writes the addresses, the workspace and the secrets inventory into +[ai/context/deployment.md](ai/context/deployment.md); how the product +deploys and how to operate it is in +[ai/context/operations.md](ai/context/operations.md). + + +## What is here + +| Surface | Where | +|---|---| +| The public HTTP API — the only Worker with a public route | `apps/api-edge` | +| Bounded-context Workers (identity, membership, projects, policy, events, config, metering, billing, notifications, webhooks, integrations, admin), reached only through the edge | `apps/*-worker` | +| The console | `apps/web-console-next` | +| API, tenancy, event and error types shared by every Worker and the console | `packages/contracts` | +| D1 executor, repositories and migrations | `packages/db` | +| SDK and CLI | `packages/sdk`, `packages/cli` | +| Data plane (D1 per environment, the edge's KV) and the parked custom domain | `infra/terraform/*` | +| Migration runner, applied on merge | `infra/db-migrate` | +| Tests, one suite per component | `tests/*` | +| Environments, lanes, the pinned composition stack, the workspace | `intent.yaml` | +| Each component's overview, architecture and runbook | `apps/*/docs`, `packages/*/docs` | + +Working with a coding agent? Start it at [AGENTS.md](AGENTS.md). + +## Getting started + +Node.js 20 or later and pnpm 10 or later. + +```bash +pnpm install +pnpm typecheck +pnpm lint +pnpm test +pnpm build +``` + +With the `orun` CLI at the version `.github/workflows/ci.yml` pins: + +```bash +orun validate --intent intent.yaml +orun plan --changed --intent intent.yaml --output plan.json +``` + +## How it deploys + +`.github/workflows/ci.yml` runs `orun plan --changed`, then one lane per +group of planned jobs with `orun run --remote-state` against the workspace +`intent.yaml` declares. A pull request plans and verifies; a merge to `main` +deploys the changed components to `stage` and then `prod`. `dev` only +verifies. The deploy credentials are brokered per run from the workspace's +Cloudflare connection, CI signs in over GitHub OIDC, and Terraform state is +kept by Orun Cloud — nothing provider-shaped is stored in this repository or +in GitHub. [ai/context/operations.md](ai/context/operations.md) is the full +operating contract. + +## Working with D1 + +D1 is SQLite, and the code is explicit about what that costs: + +- **No interactive transactions.** `executor.transaction(...)` runs its + statements in order with no rollback. Where all-or-nothing matters, use a + single statement with `RETURNING`, or an upsert with `ON CONFLICT`. +- **SQLite types.** Timestamps and JSON documents are text, booleans are + 0/1; `@saas/db/json` owns the decoding. +- **No schemas.** A bounded context's tables share a name prefix + (`identity_users`, `membership_organizations`), enforced by the + repositories. + +## What needs your credentials + +Sign-in with GitHub or Google needs OAuth client secrets; billing needs a +Polar access token, a webhook secret and `POLAR_PRODUCT_MAP` pointed at your +own Polar products; email needs Cloudflare Email Service set up for a +verified sending domain. The header comments of +`apps/identity-worker/wrangler.template.jsonc` and +`apps/billing-worker/wrangler.template.jsonc` say how each secret is set, +and `orun secrets set --org --env ` sets a runtime +secret in the workspace. + +## Custom domain + +The product answers on workers.dev from its first deploy. To serve it on +your own domain, follow "Setting the domain later" in +[ai/context/operations.md](ai/context/operations.md). diff --git a/.baseline/product/deployment.md b/.baseline/product/deployment.md new file mode 100644 index 0000000..21623b0 --- /dev/null +++ b/.baseline/product/deployment.md @@ -0,0 +1,7 @@ +# {{ .reponame }} — live deployment manifest + +> Not rendered yet. The bootstrap's `08-docs` phase probes every live URL and +> regenerates this file from what answered — the workspace, the URLs and +> their status, and the secrets inventory by name. Until then, nothing here +> claims the product is live. The operating contract is +> [operations.md](operations.md). diff --git a/README.md b/README.md index 9e88c82..b03fc32 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # cirrus-baseline Reusable **Cloudflare-only** multi-tenant SaaS starter, built as an -[Orun](https://opencode.ai/docs) component-native desired-state repo. Identity, +[Orun](https://github.com/sourceplane/orun) component-native desired-state repo. Identity, organizations, projects, RBAC, audit, metering, billing, webhooks, and notifications ship as separate bounded-context Cloudflare Workers behind a single public edge API, with a Next.js console on Workers + Static Assets — and @@ -62,12 +62,13 @@ it rather than quiet: This baseline births new products from one artifact — `repo-blueprint.yaml`, run by `orun new` (**[BOOTSTRAP.md](BOOTSTRAP.md)** → -[docs/phases/](docs/phases/README.md)). It declares nine idempotent phases — -scaffold, foundation, infrastructure, workers, workers-restore, edge, -console, optional domain, docs — each landing a verified slice, each -selectable with `--phase `. Products receive **product-only content** -(source, infra, CI, their own docs); none of this baseline's machinery -ships, and a product's docs speak only about the product. +[docs/phases/](docs/phases/README.md)). It declares two idempotent phases — +`01-product`, the whole product in one landing, and `08-docs`, the record of +what went live — each selectable with `--phase `. Products receive +**product-only content** (source, infra, CI, their own README, `AGENTS.md` +and context pack, from `.baseline/product/` and `ai/context/`); none of this +baseline's machinery ships, and a product's docs speak only about the +product. ## Prerequisites @@ -135,7 +136,7 @@ released there, and adopted here by bumping the pinned tag. ## CI -CI is powered by [Orun](https://opencode.ai/docs) with the local Stack Tectonic +CI is powered by [Orun](https://github.com/sourceplane/orun) with the published Stack Tectonic composition stack. `.github/workflows/ci.yml` calls only `orun plan` and `orun run` — no direct `pnpm`, `turbo`, Wrangler, or Terraform commands run in GitHub Actions. The Orun runtime is pinned where it runs: the `orun-action` diff --git a/ai/context/operations.md b/ai/context/operations.md index 088787a..1f58df9 100644 --- a/ai/context/operations.md +++ b/ai/context/operations.md @@ -121,23 +121,25 @@ orun integrations list --org --json && orun cloud check --org | headless/CI credentials | `ORUN_TOKEN` (workspace-scoped) + `GITHUB_TOKEN` | The ops phases (docs refresh and the original deployment sequence) all live -in ONE versioned artifact: `repo-blueprint.yaml` in the -baseline this product was born from. Clone it at a tag and select the phase -— from anywhere, with the two tokens above exported: +in ONE versioned artifact: `repo-blueprint.yaml` in the baseline this +product was built from, at the tag the Orun Cloud registry publishes for it. +`orun baseline new` fetches it at that tag and places one phase into a +checkout of this repository — from anywhere, with the two tokens above +exported: ```bash -git clone --depth 1 https://github.com/OPSFLOWS baseline && cd baseline - -orun new --blueprint repo-blueprint.yaml --out \ - --run-hooks --phase 08-docs --values # docs refresh +orun baseline list # the baselines your workspace can build +orun baseline new --local --out --run-hooks \ + --phase 08-docs --values /.rebrand/values.json # docs refresh ``` -`` carries this product's identity — at minimum `reponame`, -`productname`, `githuborg` and `orunWorkspace`, which the blueprint validates -before anything runs. `--run-hooks` is what makes a phase -land and verify rather than just place files; `--status` previews without -writing. Every phase is idempotent — re-running a completed one is a no-op -that re-verifies. +`` is the registry id of the baseline this product was built +from, one of those `orun baseline list` names. `.rebrand/values.json` is +this product's identity as its build recorded it — `reponame`, +`productname`, `githuborg`, `orunWorkspace` and the rest — which the +blueprint validates before anything runs. `--run-hooks` is what makes a phase land and verify rather than just +place files. Every phase is idempotent — re-running a completed one is a +no-op that re-verifies. ## Setting the domain later diff --git a/blueprint.yaml b/blueprint.yaml index 095ecae..5c94892 100644 --- a/blueprint.yaml +++ b/blueprint.yaml @@ -27,7 +27,7 @@ metadata: Multi-tenant SaaS on Cloudflare alone: 12 bounded-context Workers behind one edge API, a Next.js console, D1 + KV data plane, migrations, and CI that converges on merge. One provider, one consent, one token. Live on - stage+prod in ~25-30 minutes. + stage and prod in about fifteen minutes. tags: [saas, cloudflare, d1, nextjs] spec: source: @@ -129,7 +129,7 @@ spec: from: connection.cloudflare.workersSubdomain # ── PREVIEW ONLY. `repo-blueprint.yaml`'s `integrations/reconcile` hooks - # mint these, brokered, during phase 02. ──────────────────────────────── + # mint these, brokered, during 01-product. ────────────────────────────── # Transcribed from those hooks' own `keys:` and `template:` values, so # `testing/manifest.test.sh` compares this list to the document that mints # them rather than to a copy of itself — it used to compare against a shell @@ -179,10 +179,11 @@ spec: # this repo at its pinned tag would have nothing to run. `manifestPath` in # the registry row names THIS file, the console card; it is not the build. blueprint: repo-blueprint.yaml - # Was 60, then 30; baseline-v21 measured 14m51s over five landings - # (docs/phases/TIMINGS.md). One landing and one deploy per worker should - # bring it to about 9 — an estimate until a run measures it. - expectedMinutes: 12 + # Was 60, then 30; baseline-v21 measured 14m51s over five landings. + # Fifteen is the one-landing build's budget until a run measures it: the + # sum of the phases' own `expectedMinutes` (01-product 13, 08-docs 2), + # which testing/manifest.test.sh holds equal to this figure. + expectedMinutes: 15 tokenChannel: ORUN_TOKEN_FILE # how a runner hands over its refreshed token verify: urls: diff --git a/docs/phases/README.md b/docs/phases/README.md index 73f62cc..055d184 100644 --- a/docs/phases/README.md +++ b/docs/phases/README.md @@ -94,8 +94,9 @@ modes are the same files. `--resume` places every phase not already derived as done, in dependency order, honouring each barrier. Expected wall-clock on a clean run: **about -9 minutes** (an estimate until a run measures it; baseline-v21 measured 14m51s -over five landings, and it was 50–65 before that): +15 minutes** — `01-product` 13, `08-docs` 2, the figure the console card +shows (a budget until a one-landing run measures it; baseline-v21 measured +14m51s over five landings, and it was 50–65 before that): - **One landing builds the product.** `01-product` places the whole tree and lands it as one PR; the convergence that follows deploys everything in diff --git a/hooks/render-deployment-docs.sh b/hooks/render-deployment-docs.sh index 8dc44b2..92faee8 100755 --- a/hooks/render-deployment-docs.sh +++ b/hooks/render-deployment-docs.sh @@ -88,17 +88,16 @@ mkdir -p ai/context if [ ! -f ai/context/operations.md ] && [ -f "$L/ai/context/operations.md" ]; then cp "$L/ai/context/operations.md" ai/context/operations.md # The template speaks the source repo's name; the product copy must - # speak the product's. Reuse the rebrand values, then fill the - # rebrand-inert OPSFLOWS placeholder with the baseline this product came - # from — the repo whose repo-blueprint.yaml holds the ops phases. + # speak the product's. Reuse the rebrand values — after staging the copy, + # because rebrand.mjs rewrites only what `git ls-files` lists. + # + # Nothing else needs filling. The guide used to carry an `OPSFLOWS` + # placeholder that this step replaced with the baseline's repository (its + # default the retired `sourceplane/cirrus`); it now names no repository and + # tells the reader to fetch the phases with `orun baseline new`, which asks + # the registry where the baseline lives. + git add ai/context/operations.md >/dev/null 2>&1 || true node "$L/tooling/rebrand/rebrand.mjs" --values "$vals" --allow-dirty >/dev/null 2>&1 || true - opsref="${ORUN_BASELINE_REPO:-sourceplane/cirrus}" - python3 - "$opsref" <<'PYOPS' -import sys -p="ai/context/operations.md" -s=open(p).read() -open(p,"w").write(s.replace("OPSFLOWS", sys.argv[1])) -PYOPS echo "render-docs: healed ai/context/operations.md" fi diff --git a/repo-blueprint.yaml b/repo-blueprint.yaml index 3e280f2..97e4ec7 100644 --- a/repo-blueprint.yaml +++ b/repo-blueprint.yaml @@ -169,6 +169,25 @@ ignore: - "**/apps/webhooks-worker/wrangler.jsonc" - "*.tsbuildinfo" + # AN OPERATOR'S LOCAL SECRETS AND STATE, for the same reason: `orun new` + # snapshots the working tree, so a `--local` build from a checkout someone + # has run things in would copy them into somebody else's repository. Each + # glob is matched against a path's basename as well as the whole path, so + # `**/.env*` reaches every depth and every per-environment variant + # (`.env.production`, `.env.stage`), which the starters' narrower + # `.env`/`.env.local`/`.env.*.local` let through. It would drop an + # `.env.example` too; this repository tracks no `.env*` file at all, so + # nothing a product needs is lost. `.terraform` has no glob and so matches + # any path SEGMENT — the provider cache under every Terraform root — while + # the committed `.terraform.lock.hcl` files are a different segment and + # still ship. testing/leak.test.sh refuses any of these in a product. + - "**/.env*" + - "**/.dev.vars" + - "**/.dev.vars.*" + - .terraform + - "**/*.tfstate" + - "**/*.tfstate.backup" + # THE BASELINE'S OWN CI, which is not a product's (BE6). # # `github-workflows` copies the whole `.github` directory, so anything added @@ -533,11 +552,19 @@ modules: # feature, not the workaround: adding a file to `ai/context/` can no longer # ship it by accident, because shipping it means writing a module and saying # in a diff that a product should have it. + # + # `ai/context/deployment.md` HERE is this repository's own record — the + # baseline's workspace, its URLs, its probe results — and in a product's + # voice it was a false claim that the product was live before anything had + # deployed. A product starts with a placeholder that says it is not rendered + # yet; 08-docs' `render` hook overwrites it with what the product's own URLs + # answered. - name: ai-deployment - mode: copy + mode: template source: baseline - from: ai/context/deployment.md + from: .baseline/product/deployment.md to: ai/context/deployment.md + bind: [deployment.md] - name: ai-operations mode: copy source: baseline @@ -548,11 +575,12 @@ modules: source: baseline from: .github to: .github - - name: vscode - mode: copy - source: baseline - from: .vscode - to: .vscode + # NO `.vscode`. Its one file, `tasks.json`, is this repository's own agent + # loop: it runs coding agents with their sandbox and approvals bypassed + # against `agents/orchestrator.md` and `ai/state.json`, neither of which a + # product carries. Shipped, it was a task in somebody else's editor that runs + # an agent unattended against files that are not there. + # testing/leak.test.sh fails if it ships again. # ── Root files (single-file copies). intent.yaml, package.json et al. carry # instance identity; they are copied verbatim and rewritten in place by the @@ -587,11 +615,26 @@ modules: source: baseline from: .gitignore to: .gitignore + # The PRODUCT's README, not this repository's: this one is about the + # baseline — how it births products, its phases, links to BOOTSTRAP.md and + # docs/phases/ that no product has — and it said "This product is live" + # before anything had deployed. Rendered with the product's own name; the + # section between the 08-docs markers is what 08-docs rewrites. - name: root-readme - mode: copy + mode: template source: baseline - from: README.md + from: .baseline/product/README.md to: README.md + bind: [README.md] + # Where an agent starts. A finished build hands the operator a prompt that + # ends "clone and start building on it", so the repository has to + # say, at its root, what it is, what to read first and how a change lands. + - name: root-agents + mode: template + source: baseline + from: .baseline/product/AGENTS.md + to: AGENTS.md + bind: [AGENTS.md] # ── The empty discovery roots, declared (BE1). # orun's repo-scale gate — and later `orun plan` in the product's own CI — @@ -669,6 +712,7 @@ hooks: preInstantiate: - id: epic uses: orun.task/ensure@v1 + narrate: 'Epic {{ .hooks.epic.outputs.key }} is open.' with: kind: epic slug: "{{ .inputs.epicSlug }}" @@ -794,13 +838,28 @@ phases: - name: 01-product title: The product, built in one landing description: The whole tree — manifests, tooling, packages, data plane, fleet, edge and console — branded, landed as one pull request, and deployed by one convergence. - expectedMinutes: 9 + # The phases budget 13 + 2 = 15 minutes, the card's + # `bootstrap.expectedMinutes`; testing/manifest.test.sh holds them equal. + expectedMinutes: 13 + # WHAT THE BUILD PANEL SHOWS, line for line (orun-cloud saas-build-panel). + # The panel prints each hook's `narrate:` verbatim as progress, and it + # shows the timing itself — so every line here is short, and true + # whenever it is shown. + # + # NO `await` LINE, on purpose. A waiting event is not only the + # convergence: it is also what the build says while `requires.probe` below + # waits for a provider connection, so any fixed sentence ("one + # convergence is deploying… nothing is stuck") is false half the time. + # With none authored, orun writes ": <what it waits on>" from the + # engine's own reason ("…: waiting for github, cloudflare to be connected + # in workspace ws_…"), and an engine too old to know the reason says + # "<title> is waiting." A template naming `.meta.waitingOn` would read + # "Waiting on waiting for…", because the reasons are whole clauses. narrate: - start: "Creating the repository and landing the whole product in one pull request — packages, the D1 and KV data plane, the twelve-worker fleet, the API edge and the console. Then one convergence deploys it all in order. Usually about {{ .meta.expectedMinutes }} minutes." - await: "One convergence is deploying the product: D1 and KV first, then the fleet with its bindings, the API edge and the console on stage and prod. Nothing is stuck." - done: "{{ .inputs.reponame }} is live on stage and prod — {{ .meta.files }} files on main, branded as {{ .inputs.productname }}, every URL answering. That took {{ .meta.elapsed }}." - failed: "The product did not come up. The failing lane above names the component, and a provider error is in its log; whatever deployed is still there." - modules: [admin-worker, admin-worker-tests, ai-deployment, ai-operations, api-edge, api-edge-tests, billing-worker, billing-worker-tests, cli, cloudflare-d1, cloudflare-domain, cloudflare-kv, config-worker, config-worker-tests, contracts, contracts-tests, db, db-migrate, db-tests, discovery-roots, events-worker, events-worker-tests, github-workflows, identity-worker, identity-worker-tests, integrations-worker, integrations-worker-tests, membership-worker, membership-worker-tests, metering-worker, metering-worker-tests, notifications-client, notifications-client-tests, notifications-worker, notifications-worker-tests, policy-engine, policy-engine-tests, policy-worker, policy-worker-tests, projects-worker, projects-worker-tests, rebrand-values, root-gitignore, root-intent, root-package-json, root-pnpm-lock, root-pnpm-workspace, root-readme, root-turbo, sdk, shared, testing, tooling-deploy, tooling-eslint, tooling-tsconfig, tooling-wire, vscode, web-console-next, web-console-next-tests, webhook-verifier, webhooks-worker, webhooks-worker-tests] + start: "Creating the repository and landing the whole product in one pull request." + done: "{{ .inputs.productname }} is live on stage and prod, every URL answering." + failed: "The product is not up. The step that stopped says why; anything already deployed stays in place." + modules: [admin-worker, admin-worker-tests, ai-deployment, ai-operations, api-edge, api-edge-tests, billing-worker, billing-worker-tests, cli, cloudflare-d1, cloudflare-domain, cloudflare-kv, config-worker, config-worker-tests, contracts, contracts-tests, db, db-migrate, db-tests, discovery-roots, events-worker, events-worker-tests, github-workflows, identity-worker, identity-worker-tests, integrations-worker, integrations-worker-tests, membership-worker, membership-worker-tests, metering-worker, metering-worker-tests, notifications-client, notifications-client-tests, notifications-worker, notifications-worker-tests, policy-engine, policy-engine-tests, policy-worker, policy-worker-tests, projects-worker, projects-worker-tests, rebrand-values, root-agents, root-gitignore, root-intent, root-package-json, root-pnpm-lock, root-pnpm-workspace, root-readme, root-turbo, sdk, shared, testing, tooling-deploy, tooling-eslint, tooling-tsconfig, tooling-wire, web-console-next, web-console-next-tests, webhook-verifier, webhooks-worker, webhooks-worker-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 @@ -865,9 +924,11 @@ phases: # Re-tenant the fork. rebrand.mjs classifies the orun state backend as # org-owned and deliberately leaves it untouched, so intent.yaml would # keep the BASELINE's `workspace:` — the fork's CI would then claim - # another tenant's workspace on every remote op. Hook argv is not - # templated, so the value travels through .rebrand/values.json, which - # IS a rendered template. + # another tenant's workspace on every remote op. The value is read from + # .rebrand/values.json, the rendered record of the inputs. Hook argv IS + # templated — `retouch` above and `link` below pass inputs that way — + # but this argv is a script, and a value rendered into JavaScript + # source would need quoting for it; read from the record, it is data. - id: orun-workspace run: - node @@ -929,7 +990,9 @@ phases: # The repo has to exist before there is anywhere to land. - id: repo uses: orun.repo/ensure@v1 - narrate: "The repository exists at {{ .inputs.githuborg }}/{{ .inputs.reponame }}." + # From the action's outputs, so it reads true for a repository this + # build created and for one it found. + narrate: '{{ .hooks.repo.outputs.fullName }} is ready{{ if eq .hooks.repo.outputs.created "true" }} — created for this build{{ end }}.' with: owner: "{{ .inputs.githuborg }}" name: "{{ .inputs.reponame }}" @@ -953,6 +1016,7 @@ phases: # best effort and `check` is the gate: an unlinked repository stops # here, naming the fix, instead of an hour later in every lane. - id: link + narrate: "The repository is linked to the workspace, so its CI can authenticate." run: - bash - -c @@ -971,20 +1035,27 @@ phases: # purpose — the deploy token deliberately cannot touch D1. Keys that # already exist are kept. After the link, before the landing whose # convergence uses them. + # + # Their lines are static: an id with a `-` cannot be named in a + # template, and each says the one thing that is true whether the key + # was minted now or kept from before. - id: secret-workers-deploy uses: orun.integrations/reconcile@v1 + narrate: "CLOUDFLARE_API_TOKEN is in place, minted from your Cloudflare connection." with: provider: cloudflare keys: [CLOUDFLARE_API_TOKEN] template: workers-deploy - id: secret-d1-edit uses: orun.integrations/reconcile@v1 + narrate: "CLOUDFLARE_D1_TOKEN is in place, minted from your Cloudflare connection." with: provider: cloudflare keys: [CLOUDFLARE_D1_TOKEN] template: d1-edit - id: secret-account-id uses: orun.integrations/reconcile@v1 + narrate: "CLOUDFLARE_ACCOUNT_ID is in place, read from your Cloudflare connection." with: provider: cloudflare keys: [CLOUDFLARE_ACCOUNT_ID] @@ -999,9 +1070,14 @@ phases: # on main a minute later, for real, and the convergence after the # merge is what this bootstrap watches to green. # The PR pass was the same work twice and a third of the wall-clock. + # + # The line names the pull request, and says so when a re-run had + # nothing new to land. `label` names its pull request in the build + # panel (orun >= BV3 reads it; an older orun ignores the key). - id: land uses: orun.pr/land@v1 - narrate: "The product is merged into main." + label: Product + narrate: '{{ if eq .hooks.land.outputs.landed "true" }}PR #{{ .hooks.land.outputs.number }} is merged into main.{{ else }}Nothing new to land; main already has it.{{ end }}' with: task: "{{ .phase.hooks.task.outputs.key }}" epic: "{{ .inputs.epicSlug }}" @@ -1010,7 +1086,7 @@ phases: await: - id: converge uses: orun.run/watch@v1 - narrate: "The data plane, the fleet, the edge and the console deployed, and the convergence run came back green." + narrate: "The convergence on main is green: the data plane, the fleet, the edge and the console are deployed." with: # The run for the commit THIS landing merged (an unpinned watch # reads the previous push's run); the budget is roughly twice @@ -1023,14 +1099,14 @@ phases: # rungs (stage and prod), not to the workspace. - id: wiring uses: orun.secrets/exists@v1 - narrate: "The wiring secrets the workers read are published on stage and prod." + narrate: "WIRING_CLOUDFLARE_D1 and WIRING_CLOUDFLARE_KV are published on stage and prod." with: keys: [WIRING_CLOUDFLARE_D1, WIRING_CLOUDFLARE_KV] project: "{{ .inputs.reponame }}" environments: [stage, prod] - id: verify uses: orun.http/probe@v1 - narrate: "Every console and edge URL answered." + narrate: "The edge and the console answer on stage and prod." with: urls: - "https://{{ .inputs.reponame }}-api-edge-stage.{{ .inputs.subdomain }}.workers.dev/health" @@ -1040,12 +1116,13 @@ phases: - name: 08-docs title: The deployment, recorded - expectedMinutes: 1 + description: The live deployment written into ai/context/deployment.md from what its URLs answered, with prod's wait on stage and dev's verify lanes put back, landed as one pull request. + expectedMinutes: 2 narrate: - start: "Now recording what was actually built — probing every URL and writing the deployment manifest into the repository." - await: "Probing the live endpoints one last time." - done: "ai/context/deployment.md now records the live deployment, written from probed facts rather than from what the blueprint intended." - failed: "The deployment record did not land. Everything built is still there; only the write-up is missing." + # No `await` line, for the reason 01-product gives. + start: "Recording the live deployment in one pull request." + done: "ai/context/deployment.md records the live deployment, and prod waits on stage again." + failed: "The deployment record did not land; nothing deployed was changed." modules: [] requires: phases: [01-product] @@ -1074,19 +1151,25 @@ phases: - id: dev-lanes run: ["node", "{{ .baseline.dir }}/tooling/bootstrap/dev-lanes.mjs", "--restore"] - id: render + narrate: "The deployment record is written from the probed addresses." run: ["bash", "{{ .baseline.dir }}/hooks/render-deployment-docs.sh", ".", "{{ .inputs.orunWorkspace }}", "{{ .baseline.dir }}"] - id: land uses: orun.pr/land@v1 - narrate: "The deployment record is merged into main." + label: Docs + narrate: '{{ if eq .hooks.land.outputs.landed "true" }}PR #{{ .hooks.land.outputs.number }} is merged into main.{{ else }}Nothing new to land; main already has the record.{{ end }}' with: task: "{{ .phase.hooks.task.outputs.key }}" epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "docs(deployment): record the live deployment state" await: + # A re-check of the addresses 01-product already probed and pinned, so + # `quiet`: it files no facts of its own (orun >= BV3; an older orun + # ignores the key). Its authored line still speaks. - id: verify uses: orun.http/probe@v1 - narrate: "Every live URL answered on the final probe." + quiet: true + narrate: "The edge and the console still answer on stage and prod." with: urls: - "https://{{ .inputs.reponame }}-api-edge-stage.{{ .inputs.subdomain }}.workers.dev/health" diff --git a/testing/leak.test.sh b/testing/leak.test.sh index 9d11ea6..2bd09a9 100755 --- a/testing/leak.test.sh +++ b/testing/leak.test.sh @@ -25,7 +25,7 @@ # When that lands, this file grows the other half — rebrand --verify, and the # product's own `orun validate` / `orun plan --dry-run` inside the placed tree. # -# Needs: orun (the pinned version) + python3. No network, no credential. +# Needs: orun (the pinned version) + python3 with PyYAML. No network, no credential. set -euo pipefail here="$(cd "$(dirname "$0")" && pwd)" root="$(cd "$here/.." && pwd)" @@ -78,15 +78,33 @@ for missing in sorted(ALLOWED_AI - shipped_ai): bad(f"{missing} is declared a product file and would not ship") # ── the factory never ships ──────────────────────────────────────────────── +# `.vscode/tasks.json` is this repository's agent loop: it runs agents with +# their sandbox and approvals bypassed against `agents/orchestrator.md` and +# `ai/state.json`, neither of which a product has. `.baseline/` is this tree's +# own identity, the FROM side of every rebrand. NEVER = ("flows/", "agents/", "tasks/", "specs/", "testing/", "hooks/", "docs/phases/", "tooling/rebrand/", "tooling/bootstrap/", - "tooling/fork/", "tooling/migrations/", + "tooling/fork/", "tooling/migrations/", ".vscode/tasks.json", ".baseline/", "FORKING.md", "BOOTSTRAP.md", "repo-blueprint.yaml", "blueprint.yaml") for p in placed: for never in NEVER: if p == never or p.startswith(never): bad(f"{p} would ship — it is the factory, not the product") +# ── nor an operator's local secrets and state ───────────────────────────── +# `orun new` snapshots the working tree, so these reach a product only if the +# blueprint's `ignore` misses them. Matched as the ignore list means them: by +# basename at any depth, and `.terraform` as any path segment. Any `.env*` +# counts — a per-environment `.env.production` holds secrets as surely as +# `.env` does. +import fnmatch +LOCAL = (".env*", ".dev.vars", ".dev.vars.*", "*.tfstate", "*.tfstate.backup") +for p in placed: + segs = p.split("/") + if ".terraform" in segs[:-1] or any(fnmatch.fnmatchcase(segs[-1], g) for g in LOCAL): + bad(f"{p} would ship — an operator's local secret or state file, " + f"which the blueprint's `ignore` must exclude") + # ── and by content: PROVENANCE, which rebrand has no rule for ────────────── # Deliberately NOT a search for "cirrus". rebrand.mjs rewrites this # repository's own name into the product's — that is its whole job — so @@ -99,20 +117,56 @@ for p in placed: # so the customer is told their product was forked from Lumen. The file no # longer ships — the set gate above sees to that — and this catches the same # prose reappearing inside a file that does. -import re +# +# The product's own docs are read from the file their module places them FROM, +# which is not always the same path here: the README, AGENTS.md and the +# deployment placeholder come from `.baseline/product/`, because this +# repository's own README and deployment record are the baseline's. +import posixpath, re +import yaml +bp = yaml.safe_load((root / "repo-blueprint.yaml").read_text()) +source_of = {m["to"]: m["from"] for m in bp.get("modules") or [] + if m.get("from") and m.get("to")} + +# What an agent handed this repository reads first. A finished build's prompt +# ends "clone <repo> and start building on it", so these must ship, and must be +# the PRODUCT's. +PRODUCT_DOCS = {"README.md", "AGENTS.md"} | ALLOWED_AI +for missing in sorted(PRODUCT_DOCS - set(placed)): + bad(f"{missing} would not ship — a product's agent starts there") + PROVENANCE = re.compile( r"\blumen\b|\bfork(ed)? (of|from)\b|\bbaseline (repo|repository|commit)\b", re.I, ) -for rel in sorted(shipped_ai & ALLOWED_AI): - src = root / rel +# A placeholder that only some later step fills (the old `OPSFLOWS` clone URL, +# which nothing filled) is a broken instruction in the product's voice. +PLACEHOLDER = re.compile(r"\bOPSFLOWS\b|TBD_08DOCS") +LINK = re.compile(r"\[[^\]]*\]\(([^)\s]+)\)") +def ships(target): + return target in placed or any(p.startswith(target.rstrip("/") + "/") for p in placed) + +for rel in sorted(PRODUCT_DOCS & set(placed)): + src = root / source_of.get(rel, rel) if not src.exists(): - bad(f"{rel} is declared a product file and is not in this repository") + bad(f"{rel} is declared a product file and its source {src.relative_to(root)} " + f"is not in this repository") continue - for n, line in enumerate(src.read_text(errors="replace").splitlines(), 1): + text = src.read_text(errors="replace") + for n, line in enumerate(text.splitlines(), 1): if PROVENANCE.search(line): bad(f"{rel}:{n} tells the product where the BASELINE came from, " f"which rebrand cannot rewrite: {line.strip()[:70]}") + if PLACEHOLDER.search(line): + bad(f"{rel}:{n} ships a placeholder nothing fills: {line.strip()[:70]}") + # Every relative link lands on a file the product has. The baseline's own + # README linked BOOTSTRAP.md, docs/phases/ and specs/ — none of which ship. + for target in LINK.findall(text): + if re.match(r"^[a-z][a-z0-9+.-]*:|^#", target): + continue + path = posixpath.normpath(posixpath.join(posixpath.dirname(rel), target.split("#")[0])) + if not ships(path): + bad(f"{rel} links {target}, which the product does not carry") if problems: print("FAIL: the product would carry the baseline:", file=sys.stderr) @@ -123,7 +177,8 @@ if problems: print(f" {len(placed)} files derived across every phase") print(f" ai/context is exactly {len(ALLOWED_AI)} declared file(s)") print(f" none of the {len(NEVER)} factory paths; " - f"no baseline provenance in the context pack") + f"{len(PRODUCT_DOCS)} product docs ship, with no baseline provenance, " + f"no unfilled placeholder and no link outside the product") PY echo "leak.test.sh: ok" diff --git a/testing/manifest.test.sh b/testing/manifest.test.sh index 8c05f56..bc57d38 100755 --- a/testing/manifest.test.sh +++ b/testing/manifest.test.sh @@ -271,6 +271,20 @@ for path in manifests: if not boot.get("expectedMinutes"): B("bootstrap.expectedMinutes is missing — the console renders it") + # ── …and it is the phases' own budget, not a third opinion ──────────── + # + # The console shows this figure before Build and each phase's + # `expectedMinutes` while it runs. They disagreed (12 here against 9 + 1 + # in the phases, and ~25-30 in the description) with nothing comparing + # them, so an operator was given three budgets for one build. The card's + # is the phases' sum, which is the thing that does the work. + phase_minutes = [p_.get("expectedMinutes") for p_ in bp_phases] + if boot.get("expectedMinutes") and phase_minutes and all(isinstance(m, int) for m in phase_minutes): + if boot["expectedMinutes"] != sum(phase_minutes): + B(f"bootstrap.expectedMinutes is {boot['expectedMinutes']} and repo-blueprint.yaml's " + f"phases budget {' + '.join(map(str, phase_minutes))} = {sum(phase_minutes)} — " + f"the console would show one figure before Build and another during it") + # ── …and what BE-K1e added in their place ───────────────────────────── # # With no umbrella and no brief, `blueprint` is the ONLY entry point: it diff --git a/testing/phases.test.sh b/testing/phases.test.sh index 79ead34..bd80f9c 100755 --- a/testing/phases.test.sh +++ b/testing/phases.test.sh @@ -74,7 +74,16 @@ WAS = { # gate requires, which the scaffold flow used to create with a mkdir. # `tooling-deploy` arrived with the one-landing bootstrap: policy-worker's # pre-deploy runs tooling/deploy/fleet-stubs.mjs in the product's own CI. -ADDED = {"01-product": ["discovery-roots", "tooling-deploy"]} +# +# `root-agents` places the product's AGENTS.md (orun-cloud saas-build-panel +# BV4): a finished build hands the operator a prompt that ends "clone <repo> +# and start building on it", and that is the file the agent reads first. +ADDED = {"01-product": ["discovery-roots", "root-agents", "tooling-deploy"]} +# REMOVED, deliberately, and argued here rather than by editing WAS. `vscode` +# shipped `.vscode/tasks.json`, this repository's own agent loop — it runs +# agents with their sandbox bypassed against `agents/orchestrator.md` and +# `ai/state.json`, which no product carries. testing/leak.test.sh keeps it out. +REMOVED = {"01-product": ["vscode"]} # FOLDED, deliberately: a landing has a fixed cost, and since the one-landing # bootstrap NOTHING between the scaffold and the custom domain is a landing of # its own: the order those phases enforced (the data plane before the fleet, @@ -111,7 +120,8 @@ for name, was in WAS.items(): continue now = sorted(by_name[name].get("modules") or []) folded_in = [m for gone, into in FOLDED.items() if into == name for m in WAS[gone]] - want = sorted(was + ADDED.get(name, []) + folded_in) + gone_now = set(REMOVED.get(name, [])) + want = sorted(m for m in was + ADDED.get(name, []) + folded_in if m not in gone_now) if now != want: moved_in = sorted(set(now) - set(want)) moved_out = sorted(set(want) - set(now)) @@ -280,6 +290,16 @@ for p in phases: ids = {h.get("id") for h in hooks_of(p)} for slot in ("start", "await", "done", "failed"): line = n.get(slot) + # `await` IS OPTIONAL, and this baseline authors none (orun-cloud + # saas-build-panel BV4). It captions a WAITING event, which is the + # convergence or a provider connection `requires.probe` is still + # asking for — one fixed sentence is false for one of them. Left + # unauthored, orun generates "<title>: <reason>" from the engine's own + # reason, which is true for both; a line naming `.meta.waitingOn` would + # read "Waiting on waiting for…", because the reasons are whole clauses. + # An authored one is still held to every rule below. + if not line and slot == "await": + continue if not line: bad(f"phase {p['name']} declares no narrate.{slot} — an operator sees " f"a generated line instead of the one this baseline meant") diff --git a/testing/placement.test.sh b/testing/placement.test.sh index 656dd16..9e1a0e4 100755 --- a/testing/placement.test.sh +++ b/testing/placement.test.sh @@ -75,7 +75,11 @@ fi # ── the gates that ride inside the placement ─────────────────────────────── # `orun new` prints this line only after running validate + plan --dry-run in # the produced tree. Its absence means the tier lost a check without failing. -grep -q "repo gate: validate + plan --dry-run passed" "$scratch/place.log" \ +# Two spellings: the pinned v2.58.11 prints `repo gate: validate + plan +# --dry-run passed`; later releases print a summary whose `✓ Verified intent +# valid · N components × M envs → J jobs` row is written only when that same +# gate passed (cmd/orun/new_summary.go), so a pin bump does not turn this red. +grep -qE "repo gate: validate \+ plan --dry-run passed|Verified +intent valid" "$scratch/place.log" \ || fail "the placement did not report the repo-scale gate — \`orun validate\` and \`orun plan --dry-run\` are Tier 1 checks that ride inside \`orun new\`, and a silent loss of them is exactly the regression BE1a was about" @@ -133,7 +137,7 @@ for missing in sorted(ALLOWED_AI - shipped_ai): NEVER = ("flows/", "agents/", "tasks/", "specs/", "testing/", "hooks/", "docs/phases/", "tooling/rebrand/", "tooling/bootstrap/", - "tooling/fork/", "tooling/migrations/", + "tooling/fork/", "tooling/migrations/", ".vscode/tasks.json", ".baseline/", "FORKING.md", "BOOTSTRAP.md", "repo-blueprint.yaml", "blueprint.yaml") for p in placed: for never in NEVER: @@ -148,7 +152,29 @@ for p in placed: # what the product ended up with, after every rewrite. PROVENANCE = re.compile( r"\blumen\b|\bfork(ed)? (of|from)\b|\bbaseline (repo|repository|commit)\b", re.I) -for rel in sorted(shipped_ai & ALLOWED_AI): + +# THE PRODUCT'S OWN DOCS, as placed: rendered from `.baseline/product/` with +# the product's name. A `{{` left in one is a template that did not render; a +# `<no value>` is an input it named that the build does not have. +import json +vals = json.loads((root / "tests/fixtures/acme.json").read_text()) +# Until 08-docs runs, the two files it rewrites say that nothing is recorded +# — the baseline's own copies said "LIVE (200)" and "This product is live". +NOT_YET = {"README.md": "Not recorded yet", "ai/context/deployment.md": "Not rendered yet"} +PRODUCT_DOCS = {"README.md", "AGENTS.md", "ai/context/deployment.md"} +for rel in sorted(PRODUCT_DOCS): + f = tree / rel + if not f.is_file(): + bad(f"{rel} did not ship") + continue + text = f.read_text(errors="replace") + if "{{" in text or "<no value>" in text: + bad(f"{rel} shipped unrendered") + if vals["reponame"] not in text and vals["productname"] not in text: + bad(f"{rel} does not name the product it shipped in") + if rel in NOT_YET and NOT_YET[rel] not in text: + bad(f"{rel} claims a deployment before 08-docs has recorded one") +for rel in sorted((shipped_ai & ALLOWED_AI) | (PRODUCT_DOCS & set(placed))): for n, line in enumerate((tree / rel).read_text(errors="replace").splitlines(), 1): if PROVENANCE.search(line): bad(f"{rel}:{n} tells the product where the BASELINE came from: "