diff --git a/.github/workflows/baseline.yml b/.github/workflows/baseline.yml index f469118..bb58815 100644 --- a/.github/workflows/baseline.yml +++ b/.github/workflows/baseline.yml @@ -54,8 +54,42 @@ jobs: - run: bash testing/leak.test.sh # The tools the phases' hooks run, against this tree. - run: bash testing/retouch.test.sh + # A product's secret refs name the product's workspace, not this one's. + - run: bash testing/tenancy.test.sh - run: bash testing/tag-gate.test.sh + # THE BUILD DOCUMENT RUNS WITH THE BINARY A BOOTSTRAP ACTUALLY RUNS. + # + # The contract suite above reads `repo-blueprint.yaml` with PyYAML, which + # parses anything well-formed. As first pushed to this repository the document + # was refused by every released orun at phase one — + # + # ✕ action orun.pr/land@v1 has no parameter "repo" + # ✕ input "domain" has unknown type "bool" + # + # — with every gate green, because none of them asked orun. This job pins the + # bootstrap FLOOR (BOOTSTRAP.md: v2.60, where the run-level + # `hooks.preInstantiate` list arrives) and makes orun place the whole tree, + # hooks off: offline, no credential, about ten seconds. + blueprint-runs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: sourceplane/orun-action@v1.2.0 + with: + version: v2.60.0 + - uses: actions/setup-node@v5 + with: + node-version: 22 + package-manager-cache: false + - name: Python + PyYAML + run: python3 -c 'import yaml' || pip install --quiet pyyaml + - name: Tier 1 — the tree is placed, branded, and made to answer + run: | + set -euo pipefail + orun --version + bash testing/placement.test.sh + # The migration checksums. This lived in `verify.yml` and travelled into every # product, where `tooling/migrations/` does not exist because no module places # it — the lane could only be red. It is the baseline's own invariant, so it @@ -64,7 +98,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + # `package-manager-cache: false` is load-bearing. setup-node@v5 reads + # `packageManager` from the ROOT package.json and turns pnpm caching on by + # itself, then fails looking for a pnpm this job never installs. Inside + # Cirrus this workflow never ran — a nested `.github/` is inert — so the + # first run of this lane was the first push of the split repository, and + # it was red. The script needs node and nothing else. - uses: actions/setup-node@v5 with: node-version: 22 + package-manager-cache: false - run: node tooling/migrations/rechecksum.mjs --check diff --git a/ai/context/open-risks.md b/ai/context/open-risks.md index 1979407..061f556 100644 --- a/ai/context/open-risks.md +++ b/ai/context/open-risks.md @@ -6,4 +6,4 @@ | R2 | Broadcast size: a Worker invocation has CPU and subrequest limits; a large list must be paced. | mail-worker sends in batches and records progress per delivery, so a re-run resumes. Queues are the upgrade path (see the epic's open questions). | | R3 | Abuse of public write paths (subscribe, forms, reactions). | KV token-bucket rate limiting per fingerprint + optional Turnstile + honeypot; fail-open so an outage never takes the site down. | | R4 | The owner token is a single secret. | Constant-time comparison, never logged, rotated via `wrangler secret put`; the CLI reads it from the environment only. | -| R5 | No Virga product has been bootstrapped end to end yet. | The phases are one selection each on `repo-blueprint.yaml`, ported from Cirrus's one-document model in VG8; the first bootstrap records real timings in `docs/phases/TIMINGS.md`. | +| R5 | No Virga product has been bootstrapped end to end yet, and no phase has run with its hooks on. | Placement is gated (`testing/placement.test.sh`); everything past it is listed, with what would prove it, in [`docs/GAPS.md`](../../docs/GAPS.md). The first bootstrap records real timings in `docs/phases/TIMINGS.md`. | diff --git a/apps/mail-worker/component.yaml b/apps/mail-worker/component.yaml index 2d90bab..eb2faaa 100644 --- a/apps/mail-worker/component.yaml +++ b/apps/mail-worker/component.yaml @@ -13,8 +13,8 @@ spec: - component: cloudflare-d1 - component: db-migrate secretEnv: - WIRING_CLOUDFLARE_D1_STAGE: "secret://lumen/virga/stage/WIRING_CLOUDFLARE_D1" - WIRING_CLOUDFLARE_D1_PROD: "secret://lumen/virga/prod/WIRING_CLOUDFLARE_D1" + WIRING_CLOUDFLARE_D1_STAGE: "secret://virga/virga/stage/WIRING_CLOUDFLARE_D1" + WIRING_CLOUDFLARE_D1_PROD: "secret://virga/virga/prod/WIRING_CLOUDFLARE_D1" subscribe: environments: diff --git a/apps/site-api/component.yaml b/apps/site-api/component.yaml index eaf5c5a..f787808 100644 --- a/apps/site-api/component.yaml +++ b/apps/site-api/component.yaml @@ -17,10 +17,10 @@ spec: # Wiring documents from orun secrets: lease-published by the infra # components; wire-live renders the wrangler template from these. secretEnv: - WIRING_CLOUDFLARE_D1_STAGE: "secret://lumen/virga/stage/WIRING_CLOUDFLARE_D1" - WIRING_CLOUDFLARE_D1_PROD: "secret://lumen/virga/prod/WIRING_CLOUDFLARE_D1" - WIRING_CLOUDFLARE_KV_STAGE: "secret://lumen/virga/stage/WIRING_CLOUDFLARE_KV" - WIRING_CLOUDFLARE_KV_PROD: "secret://lumen/virga/prod/WIRING_CLOUDFLARE_KV" + WIRING_CLOUDFLARE_D1_STAGE: "secret://virga/virga/stage/WIRING_CLOUDFLARE_D1" + WIRING_CLOUDFLARE_D1_PROD: "secret://virga/virga/prod/WIRING_CLOUDFLARE_D1" + WIRING_CLOUDFLARE_KV_STAGE: "secret://virga/virga/stage/WIRING_CLOUDFLARE_KV" + WIRING_CLOUDFLARE_KV_PROD: "secret://virga/virga/prod/WIRING_CLOUDFLARE_KV" subscribe: environments: diff --git a/docs/GAPS.md b/docs/GAPS.md new file mode 100644 index 0000000..5c082f2 --- /dev/null +++ b/docs/GAPS.md @@ -0,0 +1,113 @@ +# Gaps — what is proven about this baseline, and what is not + +Written 2026-10-01, when Virga was split out of `sourceplane/cirrus` into this +repository, made public, and attached to its own workspace. Every line under "proven" was +run, not inferred; every line under "not proven" names what would prove it. +Delete an entry when it stops being true — a gaps file that is never shortened +is a file nobody reads. + +## Proven + +| What | How | +|---|---| +| The build document is one orun can run. | `testing/placement.test.sh` places the whole blueprint with hooks off, under orun v2.60.0 (the floor) and v2.71.0. Baseline CI's `blueprint-runs` job repeats it on every pull request. | +| A product placed from it is a product. | The placed tree is branded as `01-scaffold` brands it: no factory path, no baseline identity, `intent.yaml` and all 18 secret refs naming the product's workspace. | +| That product builds. | A placed, branded product passed its own `install`, `wire:fixture`, `typecheck`, `lint`, `test` and `build`. Run by hand once; **not** a gate. | +| The static contract holds. | `coverage`, `phases`, `manifest`, `leak`, `retouch`, `tag-gate`, `tenancy` — all in Baseline CI. | +| This repository is attached to a workspace. | `orun workspace` resolves `ws_F6PEAMKD` (`virga`) from `intent.yaml`; `orun cloud check` reports `sourceplane/virga` allow-listed; `orun plan` resolves 16 components into 33 jobs. | +| CI reaches the platform without a credential. | With `ORUN_CI=true`, run 36834192908 planned 12 jobs and each run lane was answered by the platform: `secret resolution failed … Secret not found (code: not_found) [requestId: req_…]`. That is the answer a workspace with no minted secrets should give. | +| An unproven tag cannot be pushed. | The ruleset `baseline-tags-restrict-creation` refused `baseline-v0-ruleset-probe` from an org admin: `Cannot create ref due to creations being restricted`. | + +## Not proven + +### 1. No phase has ever run with its hooks on + +Placement proves the document parses and the files land. It does not run +`orun.task/ensure`, `orun.repo/ensure`, `orun.pr/land`, `orun.run/watch`, +`orun.integrations/reconcile`, `orun.secrets/exists` or `orun.http/probe` — +which is everything a bootstrap does that is not copying a file. Two defects +that stopped the document at phase one (`repo:` on `orun.pr/land@v1`, and +`type: bool`) were found only because placement was finally run; the same +class of defect in a hook's *behaviour* is still unlooked-for. + +*Would prove it:* one real `orun new --resume --run-hooks` into a throwaway +repository and workspace. + +### 2. There is no rehearsal, so there is no tag — deliberately, for now + +`rehearsal.yml` and `testing/rehearsal/` are not ported from Cirrus. The tag +gate therefore answers exit 3, "the question could not be answered", for every +commit, and `baseline-v1` does not exist. Left out on purpose at the split: a +harness that creates and destroys real Cloudflare resources should not be +written without being run. + +Consequences that follow from it and are easy to forget: + +- **Virga is not in the registry.** `orun baseline list` shows `cirrus`, + `lumen` and `multi-tenant-saas`. A row in orun-cloud's + `infra/baselines-registry/baselines.yaml` needs a tag to pin, and the sync + refuses a tag that does not exist. Nobody can build from Virga through the + console until this is closed. +- **`docs/phases/TIMINGS.md` and `expectedMinutes: 43` are estimates.** No + bootstrap has been timed. + +### 3. The tag ruleset is binding in one direction only + +The ruleset restricts creation of `baseline-v*` and has **no bypass actor**. +GitHub refuses the Actions integration on a bypass list (`Actor GitHub Actions +integration must be part of the ruleset source or owner organization`), so +"`tag.yml`'s token is the only creator" cannot be expressed with +`GITHUB_TOKEN`. Today that costs nothing, because the gate refuses everything. +The day a rehearsal goes green, `tag.yml`'s `cut` job will pass the gate and +then be refused by the ruleset. + +*Closes it:* a GitHub App or a deploy key on the bypass list, and `cut` +creating the tag with that identity. It also only restricts **creation** — +moving an existing tag is not restricted, and should be once one exists. + +### 4. The workspace is not yet one a bootstrap can finish in + +Cloudflare is connected (inherited from the account, `Nexo@sourceplane.ai's +Account`), and `orun baseline check cirrus` — the nearest registered +Cloudflare-only baseline — answers `ready to build` here. What is left: + +- **The token's D1 Write permission group is unchecked.** Without it + `03-infrastructure`'s `d1-edit` mint is refused with + `parent_grant_insufficient`, and nothing short of a mint proves it either + way. The `d1-edit` template is listed as active, which says the platform + offers it, not that the connection's token can grant it. +- **GitHub is connected to the wrong account.** The only connection is + inherited from the account and is to `pullely`, a user. The platform learns + of a pull request through the App installation on the account that OWNS the + repository — `sourceplane` — so `orun integrations list` says "github: + active" and the landings would still not be filed. +- **No admin-role API key has been minted.** Builder and viewer keys read + fine and have their secret writes denied, masked as `not_found`. +- **No secrets.** `orun secrets list` is empty, which is why every run lane + above failed, and why `ORUN_CI` is **unset** again: the variable exists so a + pre-bootstrap repository is not red, and this is one. Set it with + `gh variable set ORUN_CI --body true` once this repository's own secrets + exist. + +### 5. This repository's own environments have never deployed + +`intent.yaml` declares `dev`, `stage` and `prod` with `BASE_DOMAIN: virga.site`. +With `ORUN_CI` on, a push to `main` converges them for real. Whether the +`virga.site` zone exists in the connected Cloudflare account is unchecked. + +### 6. Smaller things, written down so they are not rediscovered + +- `kiox.lock` keeps `name: virga` in a product while `kiox.yaml` is renamed — + the rebrand excludes lock files. Cirrus does the same. Harmless so far. +- The secret refs here use the workspace **slug** (`secret://virga/virga/…`) + on purpose: the rebrand's scoped rule matches `[a-z0-9-]+`, so a `ws_…` id + in that segment would not be rewritten and a product would keep this tenant. +- `orun workspace create` cannot name an account, and a login that owns more + than one is refused. This workspace was created with a locally patched CLI + that sends `accountId`. The released CLI still cannot do it. +- **This repository is public because its workspace is.** `virga` is under the + openproduct account, whose workspaces are public and whose covenant is that + their repositories are too. It was made public on 2026-10-01 for that reason; + its tree was already public inside `sourceplane/cirrus`. Making it private + again breaches the covenant — move it to a workspace under a standard account + first. diff --git a/infra/db-migrate/component.yaml b/infra/db-migrate/component.yaml index 6f7cc81..acc053e 100644 --- a/infra/db-migrate/component.yaml +++ b/infra/db-migrate/component.yaml @@ -35,9 +35,9 @@ spec: # connection fact, and the database id arrives in the wiring document the # cloudflare-d1 component lease-publishes. secretEnv: - CLOUDFLARE_API_TOKEN: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_D1_TOKEN" - CLOUDFLARE_ACCOUNT_ID: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" - WIRING_CLOUDFLARE_D1: "secret://lumen/virga/{{ .environment }}/WIRING_CLOUDFLARE_D1" + CLOUDFLARE_API_TOKEN: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_D1_TOKEN" + CLOUDFLARE_ACCOUNT_ID: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + WIRING_CLOUDFLARE_D1: "secret://virga/virga/{{ .environment }}/WIRING_CLOUDFLARE_D1" subscribe: environments: diff --git a/infra/terraform/cloudflare-d1/component.yaml b/infra/terraform/cloudflare-d1/component.yaml index b0ae039..4eece81 100644 --- a/infra/terraform/cloudflare-d1/component.yaml +++ b/infra/terraform/cloudflare-d1/component.yaml @@ -31,10 +31,10 @@ spec: # touch D1). Declared at component level because plan-only lanes refresh # against the live Cloudflare API too, not just apply. secretEnv: - CLOUDFLARE_API_TOKEN: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_D1_TOKEN" + CLOUDFLARE_API_TOKEN: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_D1_TOKEN" # Non-secret connection fact (account-id template). - CLOUDFLARE_ACCOUNT_ID: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" - TF_VAR_cloudflare_account_id: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + CLOUDFLARE_ACCOUNT_ID: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + TF_VAR_cloudflare_account_id: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" subscribe: environments: diff --git a/infra/terraform/cloudflare-domain/component.yaml b/infra/terraform/cloudflare-domain/component.yaml index 5082e44..8aaeb2e 100644 --- a/infra/terraform/cloudflare-domain/component.yaml +++ b/infra/terraform/cloudflare-domain/component.yaml @@ -34,9 +34,9 @@ spec: - component: web-site secretEnv: - CLOUDFLARE_API_TOKEN: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_API_TOKEN" - CLOUDFLARE_ACCOUNT_ID: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" - TF_VAR_cloudflare_account_id: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + CLOUDFLARE_API_TOKEN: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_API_TOKEN" + CLOUDFLARE_ACCOUNT_ID: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + TF_VAR_cloudflare_account_id: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" # PARKED BY DESIGN — no environment subscriptions, so no jobs are planned. # A fresh product has no zone in the connected account, and diff --git a/infra/terraform/cloudflare-kv/component.yaml b/infra/terraform/cloudflare-kv/component.yaml index 1f13df0..2323de6 100644 --- a/infra/terraform/cloudflare-kv/component.yaml +++ b/infra/terraform/cloudflare-kv/component.yaml @@ -25,9 +25,9 @@ spec: secretOutputs: "WIRING_CLOUDFLARE_KV=wiring" secretEnv: - CLOUDFLARE_API_TOKEN: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_API_TOKEN" - CLOUDFLARE_ACCOUNT_ID: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" - TF_VAR_cloudflare_account_id: "secret://lumen/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + CLOUDFLARE_API_TOKEN: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_API_TOKEN" + CLOUDFLARE_ACCOUNT_ID: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + TF_VAR_cloudflare_account_id: "secret://virga/virga/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" subscribe: environments: diff --git a/intent.yaml b/intent.yaml index 9379bf1..c0360bb 100644 --- a/intent.yaml +++ b/intent.yaml @@ -14,10 +14,13 @@ execution: # enforce claim ⊆ authorized. Declaring it implies strict mode — a # non-interactive run that resolves no workspace fails fast. # - # REPLACE THIS before the first bootstrap. The placeholder is deliberate - # and fails loudly: inheriting another product's workspace id would make - # this repo's CI claim someone else's tenant. - workspace: ws_REPLACE_ME + # This repository's OWN workspace: `virga`, under the openproduct account. + # It is not a default for anything built from here — 01-scaffold's + # `orun-workspace` hook rewrites this line to the product's workspace, and + # rebrand.mjs rewrites the workspace segment of every `secret://` ref, + # because a product that inherits this id claims this tenant on every + # remote op. `testing/placement.test.sh` fails if either stops happening. + workspace: ws_F6PEAMKD requireOrg: true # Push the resolved catalog after a successful plan on the default branch, # keeping the workspace-global catalog head fresh without an explicit diff --git a/repo-blueprint.yaml b/repo-blueprint.yaml index bdd42a7..26faa43 100644 --- a/repo-blueprint.yaml +++ b/repo-blueprint.yaml @@ -59,7 +59,7 @@ inputs: default: "your-workers-subdomain" description: workers.dev subdomain, used by the site build and by every deploy smoke and probe. repoPrivate: - type: bool + type: boolean default: true description: Whether orun.repo/ensure creates the product repo private. Visibility is the operator's choice, so it is asked rather than assumed. orunWorkspace: @@ -78,7 +78,7 @@ inputs: The epic every phase clubs its task under. Found by slug, so a fresh run and a resumed run find the same work. domain: - type: bool + type: boolean default: false description: >- Whether to run 07-domain. It needs the Cloudflare zone to already @@ -649,7 +649,6 @@ phases: epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "feat(scaffold): the repository is born" - repo: "{{ .inputs.githubOrg }}/{{ .inputs.repoName }}" - name: 02-foundation title: The shared packages @@ -693,7 +692,6 @@ phases: epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "feat(foundation): the shared packages" - repo: "{{ .inputs.githubOrg }}/{{ .inputs.repoName }}" await: - id: converge uses: orun.run/watch@v1 @@ -778,7 +776,6 @@ phases: epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "feat(infrastructure): D1 and KV on stage and prod" - repo: "{{ .inputs.githubOrg }}/{{ .inputs.repoName }}" await: - id: converge uses: orun.run/watch@v1 @@ -852,7 +849,6 @@ phases: epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "feat(mail): the schema and the mail Worker" - repo: "{{ .inputs.githubOrg }}/{{ .inputs.repoName }}" await: - id: converge uses: orun.run/watch@v1 @@ -907,7 +903,6 @@ phases: epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "feat(api): the public site API" - repo: "{{ .inputs.githubOrg }}/{{ .inputs.repoName }}" await: - id: converge uses: orun.run/watch@v1 @@ -969,7 +964,6 @@ phases: epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "feat(site): the website on Workers and Static Assets" - repo: "{{ .inputs.githubOrg }}/{{ .inputs.repoName }}" await: - id: converge uses: orun.run/watch@v1 @@ -1032,7 +1026,6 @@ phases: epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "feat(domain): the custom domain in front of the site" - repo: "{{ .inputs.githubOrg }}/{{ .inputs.repoName }}" await: - id: converge uses: orun.run/watch@v1 @@ -1081,7 +1074,6 @@ phases: epic: "{{ .inputs.epicSlug }}" branchSlug: "{{ .phase.name }}" title: "docs(deployment): record the live deployment state" - repo: "{{ .inputs.githubOrg }}/{{ .inputs.repoName }}" await: - id: verify uses: orun.http/probe@v1 diff --git a/testing/placement.test.sh b/testing/placement.test.sh new file mode 100755 index 0000000..f8b7870 --- /dev/null +++ b/testing/placement.test.sh @@ -0,0 +1,156 @@ +#!/usr/bin/env bash +# THE BUILD DOCUMENT RUNS, AND WHAT IT PLACES IS A PRODUCT. +# +# Every other gate here reads `repo-blueprint.yaml` with PyYAML, which will +# parse anything well-formed. None of them asked the question that matters: +# can the orun CLI read it. It could not. As first pushed to this repository, +# +# ✕ phases[0] (01-scaffold) hooks[9] (land): action orun.pr/land@v1 has no +# parameter "repo" +# ✕ input "domain" has unknown type "bool" +# +# — refused by every released orun at the first phase, with six gates green. +# A bootstrap would have failed before placing a file. +# +# So this makes orun itself answer, and then looks at what it placed: +# 1. `orun new` places the whole blueprint, hooks off. That parses the +# document, validates every hook against the action registry, and runs +# the repo-scale gate (`orun validate` + `orun plan --dry-run`) on the +# placed tree. +# 2. The tree is branded exactly as 01-scaffold's hooks brand it, and +# `rebrand --verify` finds no baseline identity left. +# 3. The product carries no factory path, its `intent.yaml` claims the +# product's workspace, and every secret ref names that workspace. +# +# Offline: placement writes files and a run with hooks off does not probe. +# Needs: orun (>= the floor BOOTSTRAP.md names), node, python3, git. +set -euo pipefail +here="$(cd "$(dirname "$0")" && pwd)" +root="$(cd "$here/.." && pwd)" + +command -v orun >/dev/null || { echo "placement.test.sh needs orun on PATH" >&2; exit 1; } +command -v node >/dev/null || { echo "placement.test.sh needs node for rebrand" >&2; exit 1; } + +scratch="$(mktemp -d)" +trap 'rm -rf "$scratch"' EXIT +fails=0 +fail() { echo " ✕ $*" >&2; fails=$((fails + 1)); } + +# Awkward on purpose: a two-word name, a hyphenated slug, a workspace given as +# the ws_… id the blueprint's `from: workspace` always supplies. `domain` is on +# because 07-domain is conditional and a gate that skips a phase cannot vouch +# for it. +WS="ws_0000000F" +sets=( + --set repoName=acme-blog + --set "productName=Acme Blog" + --set productDomain=acme.blog + --set githubOrg=acme-co + --set workersDevSubdomain=acme + --set "orunWorkspace=$WS" + --set domain=true +) + +tree="$scratch/product" +mkdir -p "$tree"/{apps,infra,packages,tests} + +echo "── placing the whole blueprint (offline, no credential)" +if ! orun new --blueprint "$root/repo-blueprint.yaml" --out "$tree" "${sets[@]}" \ + > "$scratch/place.log" 2>&1; then + echo "FAIL: orun refused the build document, or the placement did not run ($(orun version 2>&1 | head -1))" >&2 + tail -20 "$scratch/place.log" >&2 + exit 1 +fi +grep -q "repo gate: validate + plan --dry-run passed" "$scratch/place.log" \ + || fail "the placement did not report the repo-scale gate (orun validate + plan --dry-run)" +placed_count="$(find "$tree" -type f -not -path "*/.orun/*" | wc -l | tr -d ' ')" +[ "$placed_count" -ge 200 ] || fail "only $placed_count files placed — that is not a product" +echo " $placed_count files placed; the repo-scale gate ran" + +echo "── branding, as 01-scaffold's hooks do, then rebrand --verify" +( + cd "$tree" + git init -q -b main + git config user.email t@example.invalid + git config user.name "tier one" + printf '.orun/\n' >> .gitignore + git add -A +) >/dev/null 2>&1 +if ! (cd "$tree" && node "$root/tooling/rebrand/rebrand.mjs" \ + --values .rebrand/values.json --allow-dirty) > "$scratch/brand.log" 2>&1; then + echo "FAIL: rebrand did not complete" >&2; tail -20 "$scratch/brand.log" >&2; exit 1 +fi +# The blueprint's own `orun-workspace` hook, extracted and run rather than +# re-typed here, so this exercises the document's code and not a copy of it. +python3 - "$root/repo-blueprint.yaml" "$scratch/ws-hook.js" <<'PY' +import sys, yaml +bp = yaml.safe_load(open(sys.argv[1])) +ph = next(p for p in bp["phases"] if p["name"] == "01-scaffold") +hooks = [h for hs in ph["hooks"].values() for h in hs] +hook = next((h for h in hooks if h.get("id") == "orun-workspace"), None) +if not hook or hook["run"][:2] != ["node", "-e"]: + sys.exit("01-scaffold has no `orun-workspace` node hook — this check has gone blind") +open(sys.argv[2], "w").write(hook["run"][2]) +PY +(cd "$tree" && node "$scratch/ws-hook.js") > "$scratch/ws.log" 2>&1 \ + || { echo "FAIL: the orun-workspace hook failed" >&2; cat "$scratch/ws.log" >&2; exit 1; } +(cd "$tree" && git add -A) >/dev/null 2>&1 +if ! (cd "$tree" && node "$root/tooling/rebrand/rebrand.mjs" \ + --verify --values .rebrand/values.json) > "$scratch/verify.log" 2>&1; then + echo "FAIL: rebrand --verify found baseline identity left in the product" >&2 + tail -20 "$scratch/verify.log" >&2; exit 1 +fi +echo " branded; no baseline-identity residue" + +echo "── what the product actually carries" +python3 - "$tree" "$WS" <<'PY' +import pathlib, re, sys +tree, ws = pathlib.Path(sys.argv[1]), sys.argv[2] +problems = [] +def bad(m): problems.append(m) + +placed = sorted( + p.relative_to(tree).as_posix() + for p in tree.rglob("*") + if p.is_file() and ".git" not in p.parts and ".orun" not in p.parts +) + +NEVER = ("flows/", "agents/", "tasks/", "specs/", "testing/", "hooks/", + "docs/phases/", "tooling/rebrand/", "tooling/bootstrap/", + "tooling/blueprint/", "tooling/migrations/", + "BOOTSTRAP.md", "repo-blueprint.yaml", "blueprint.yaml", + ".github/workflows/baseline.yml", ".github/workflows/tag.yml", + ".github/workflows/rehearsal.yml") +for p in placed: + for never in NEVER: + if p == never or p.startswith(never): + bad(f"{p} shipped — it is the factory, not the product") + +intent = (tree / "intent.yaml").read_text() +m = re.search(r"(?m)^\s*workspace:\s*(\S+)", intent) +if not m or m.group(1) != ws: + bad(f"intent.yaml claims workspace {m.group(1) if m else None!r}; the build ran in {ws!r}") + +refs = set() +for p in placed: + if p.endswith("component.yaml"): + refs |= set(re.findall(r"secret://[^/\"\s]+/[^/\"\s]+/", (tree / p).read_text())) +want = f"secret://{ws}/acme-blog/" +if not refs: + bad("no secret ref in any placed component.yaml — this check has gone blind") +for r in sorted(refs - {want}): + bad(f"a secret ref names {r} — the platform refuses a ref whose workspace is " + f"not the run's; every ref must be {want}") + +comps = [p for p in placed if p.endswith("/component.yaml")] +if problems: + print("FAIL: the placed product is not the product:", file=sys.stderr) + for p in problems: + print(f" - {p}", file=sys.stderr) + sys.exit(1) +print(f" {len(placed)} product files, {len(comps)} components; no factory path") +print(f" intent.yaml and every secret ref name {ws}") +PY + +[ "$fails" -eq 0 ] || exit 1 +echo "placement.test.sh: ok" diff --git a/testing/retouch.test.sh b/testing/retouch.test.sh index 0ab47a3..05e9da6 100755 --- a/testing/retouch.test.sh +++ b/testing/retouch.test.sh @@ -81,13 +81,15 @@ grep -q 'replace marker' "$tmp/two.log" || bad "second run did not report a repl ok "a second run replaces the marker (a different phase's too) rather than appending" echo "── retouch: every other byte is as it was" -if [ "$(head -n -1 "$tmp/apps/alpha/component.yaml" | cksum)" = "$(cksum < "$tmp/alpha.orig")" ]; then +# `sed '$d'`, not `head -n -1`: the negative count is GNU-only, and on a Mac +# this gate failed on the test's own plumbing while retouch.mjs was correct. +if [ "$(sed '$d' "$tmp/apps/alpha/component.yaml" | cksum)" = "$(cksum < "$tmp/alpha.orig")" ]; then ok "apps/alpha: the file above the marker is byte-for-byte the original" else bad "apps/alpha: bytes above the marker changed" - diff <(head -n -1 "$tmp/apps/alpha/component.yaml") "$tmp/alpha.orig" >&2 || true + diff <(sed '$d' "$tmp/apps/alpha/component.yaml") "$tmp/alpha.orig" >&2 || true fi -if [ "$(head -n -1 "$tmp/infra/beta/component.yaml" | cksum)" = "$(printf '%s\n' "$(cat "$tmp/beta.orig")" | cksum)" ]; then +if [ "$(sed '$d' "$tmp/infra/beta/component.yaml" | cksum)" = "$(printf '%s\n' "$(cat "$tmp/beta.orig")" | cksum)" ]; then ok "infra/beta: only a newline was added before the marker" else bad "infra/beta: bytes above the marker changed" diff --git a/testing/tenancy.test.sh b/testing/tenancy.test.sh new file mode 100755 index 0000000..0827fc7 --- /dev/null +++ b/testing/tenancy.test.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# A PRODUCT'S SECRET REFS NAME THE PRODUCT'S WORKSPACE. +# +# Every deployable component reads its credentials through +# `secret://///`, and the platform refuses a ref +# whose workspace segment is not the workspace the run is in: +# +# Ref workspace "lumen" does not name this run's workspace +# +# This baseline's own refs name ITS workspace (`virga`). rebrand.mjs rewrites +# the segment — and for as long as it skipped a `ws_…` id, which is the only +# form the blueprint's `orunWorkspace` input ever takes, it left the baseline's +# segment (then `lumen`) standing in every product. +# Nothing offline noticed: the leftover sweep looks for THIS repository's name, +# and a workspace slug is not it. The first thing to notice would have been phase 03's +# convergence, forty minutes into somebody's bootstrap. +# +# So this rebrands a copy of the tree three ways and reads the refs back. +# Needs: node, git. No network. +set -euo pipefail +here="$(cd "$(dirname "$0")" && pwd)" +root="$(cd "$here/.." && pwd)" + +command -v node >/dev/null || { echo "tenancy.test.sh needs node" >&2; exit 1; } + +fail=0 +ok() { echo " ok $*"; } +bad() { echo " ✕ $*" >&2; fail=1; } + +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT + +# One rebranded copy per case: the tracked tree, in a repository of its own, +# because rebrand.mjs sweeps `git ls-files`. +rebranded_refs() { # -> prints the distinct ref prefixes + local dir="$tmp/$1" + mkdir -p "$dir" + (cd "$root" && git ls-files -z | tar --null -T - -cf -) | tar -C "$dir" -xf - + ( + cd "$dir" + git init -q && git add -A + mkdir -p .rebrand && printf '%s\n' "$2" > .rebrand/values.json + node tooling/rebrand/rebrand.mjs --values .rebrand/values.json --allow-dirty > rebrand.log 2>&1 \ + || { cat rebrand.log >&2; exit 1; } + git grep -h -o -E 'secret://[^/"]+/[^/"]+/' -- . ':!tooling/rebrand' ':!testing' ':!rebrand.log' | sort -u + ) +} + +base='"repoName":"acme-blog","productName":"Acme Blog","productDomain":"acme.blog","workersDevSubdomain":"acme","githubOrg":"acme-co"' + +echo "── a ws_… id, which is what the blueprint supplies" +refs="$(rebranded_refs wsid "{$base,\"orunWorkspace\":\"ws_ABCD1234\"}")" +[ "$refs" = "secret://ws_ABCD1234/acme-blog/" ] \ + && ok "every ref names ws_ABCD1234 and the product's own project" \ + || bad "refs after a ws_ rebrand: $(echo $refs)" + +echo "── a slug" +refs="$(rebranded_refs slug "{$base,\"orunWorkspace\":\"ws_ABCD1234\",\"orunWorkspaceSlug\":\"acme\"}")" +[ "$refs" = "secret://acme/acme-blog/" ] \ + && ok "an explicit orunWorkspaceSlug wins" \ + || bad "refs with an explicit slug: $(echo $refs)" + +echo "── no workspace at all" +refs="$(rebranded_refs none "{$base}")" +[ "$refs" = "secret://acme-blog/acme-blog/" ] \ + && ok "the repo name is the last resort — never the baseline's workspace" \ + || bad "refs with no workspace: $(echo $refs)" + +echo "── and this tree has refs to rewrite at all" +n="$(cd "$root" && git grep -h -o -E 'secret://[^/"]+/virga/' -- '*component.yaml' | wc -l | tr -d ' ')" +[ "$n" -ge 10 ] && ok "$n refs in component.yaml files" \ + || bad "only $n secret refs found in this tree — the cases above proved nothing" + +[ "$fail" -eq 0 ] || exit 1 +echo "tenancy.test.sh: ok" diff --git a/tooling/rebrand/rebrand.mjs b/tooling/rebrand/rebrand.mjs index ee544a9..df1e898 100644 --- a/tooling/rebrand/rebrand.mjs +++ b/tooling/rebrand/rebrand.mjs @@ -70,15 +70,35 @@ const brandSlug = values.brandSlug ?? repoName; const cliBin = values.cliBin ?? repoName; const workersDevSubdomain = values.workersDevSubdomain ?? "your-workers-subdomain"; // A `secret://///` ref names the WORKSPACE first -// and the project (repo) second. In this baseline the workspace segment is -// `lumen` (the org's workspace slug) and the project is `virga`, so the two -// are already distinct — but an instance may live in its own workspace. +// and the project (repo) second. In this baseline both happen to be `virga` — +// the workspace's slug and the repo's — so the scoped rule below must run +// before the repo-slug pass, or one rename would rewrite both. A product lives +// in its own workspace, so the segment is renamed: orunWorkspaceSlug when the +// caller supplied one, else orunWorkspace itself. +// +// The baseline's own refs use the workspace SLUG, never its ws_… id: the rule +// below matches `[a-z0-9-]+`, and a `ws_F6…` segment would not be found, so a +// product would keep this repository's tenant. +// +// A ws_… id IS a valid workspace segment. The resolve verifies the segment +// against membership and accepts a slug, a public id or a ws_ ref (orun-cloud +// state-worker secrets-resolve.ts, verifySegments). This used to skip a ws_… +// id and KEEP the baseline's segment (then `lumen`, the workspace Cirrus +// declares) — and the blueprint's `orunWorkspace` input is always a +// ws_… id (`from: workspace`) and nothing supplies a slug, so every product +// built from this baseline carried `secret://lumen//…` and every +// resolve in it was refused: +// +// Ref workspace "lumen" does not name this run's workspace +// +// Cirrus fixed the same rule; this is that fix, which the split did not carry. +// The repo name is the last resort, only when no workspace was given at all. const orunWorkspaceSlug = (() => { const explicit = (values.orunWorkspaceSlug ?? "").trim(); if (explicit) return explicit; const ws = (values.orunWorkspace ?? "").trim(); - if (ws && !/^ws_/i.test(ws)) return ws; // already a slug - return "lumen"; // keep the baseline's workspace slug when none is given + if (ws) return ws; + return repoName; })(); const envPrefix = cliBin.toUpperCase().replace(/-/g, "_");