Skip to content

feat(deploy): deploy a target as a Worker Preview and prove it through the edge, removing it again on any failure - #257

Merged
aRustyDev merged 6 commits into
mainfrom
feat/deploy-target
Nov 17, 2026
Merged

aRustyDev merged 6 commits into
mainfrom
feat/deploy-target

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

Stacked on #253 (its base). It uses #253's edge-opt-in.sh and the smoke's pin and route.
Merge that one first; GitHub then retargets this one to main.

The third piece of deploying release candidates as Worker Previews (#195 stage E, ADR-0111). No workflow runs it yet:
release candidates keep deploying to staging until the cut-over.

What it adds

scripts/deploy-target.sh, which takes everything from the environment, as deploy-worker.sh does. In order:

  1. Checks every input before anything is asked of Cloudflare. A usage error is exit 2, with nothing called. It checks:

    • the target name, in the edge's grammar (the Preview's label is the name with . written as -);
    • the commit, the shared origin and the web files;
    • that the kind is one of the Flagship policy's target kinds;
    • that the policy lets CI reach that kind through the chosen audience. Otherwise the smoke could never opt in.
  2. Renders production's configuration and derives the target's from it (feat(deploy): derive a shared Preview target's configuration from production's rendered one #241, shared data).

  3. Runs wrangler preview --name <label> --json --ignore-base-config --tag <sha>.

  4. Reads the answer with scripts/preview-result.py. It requires:

    • the URL the edge accepts;
    • a deployment id the edge accepts;
    • every declared binding, in what Cloudflare actually applied;
    • every room bound to production's Worker;
    • every variable with the text it was given (THRUST_PUBLIC_BASE_URL = the shared origin, Q-0111.2).

    Other bindings are checked by name only: the spike recorded only the shapes of rooms and variables.

  5. Writes the target's flag with flagship.py put, which reads it back.

  6. Opts in and runs the smoke through the edge, with the pin and the target's route.

  7. Runs the smoke's control: a version nobody deployed must fail.

On any failure from step 3 on, it deletes the flag first, so the edge stops routing to it, then the Preview. A failed
deploy over a live target therefore leaves no target at all. If the cleanup itself fails, it says exactly what it left.

Each tool sees only its own secret:

Step Sees
wrangler the Cloudflare token
flagship.py the Flagship token
the opt-in its service token
the smoke its password
the render and the readers nothing

Tests

test-deploy-target.sh, under dash: 121 checks pass.

  • The fakes:
    • target_fakes.py stands in for wrangler's Previews. It applies the previews block in the shape the spike recorded,
      and can be told to deviate.
    • The opt-in and the smoke fakes are truthful: they pass only when the Preview and the flag really agree.
    • The real flagship.py runs against flagship_fake.py.
  • What it shows:
    • every target kind deploys, with its Preview and flag checked against a model;
    • the steps run in order, each with only its own secret;
    • every failure point leaves nothing (no flag, no Preview), and a Preview that isn't the one asked for stops the deploy
      before any flag is written;
    • a flag that doesn't stick is caught;
    • a failed cleanup says what it left;
    • every usage error calls nothing;
    • a redeploy replaces the Preview and the flag.

test_preview_result.py: 3957 checks. It generates 300 previews blocks with Cloudflare's answers behind 0 to 3
progress lines, then drops every binding, removes or changes every room's script_name, changes every variable's text,
and breaks the URL and the deployment id in every way the edge refuses.

Hand mutants: 17 versions of the two scripts with a planted bug; each one fails the tests.

  • The first run had one survivor. With the post-deploy check's failure ignored, the deploy still failed later, when
    flagship.py refused the empty URL, so the expected message appeared anyway. Each of those cases now also requires that
    no flag was ever written, and the re-run killed every mutant.

A real bug the tests found, fixed here: the cleanup skipped the flag when put had failed its read-back, which left
behind whatever put had partly written.

Also passing:

  • every deps step (14);
  • every ci-scripts test (32), each run on its own with sh as dash;
  • actionlint;
  • test_plan_ci.py (5031).

Not verified

A real wrangler preview. Nothing here runs against Cloudflare. The fakes follow the spike's recorded output.

  • The first real target deploy is the check. It comes after the infrastructure issues (the Flagship app, the Access
    apps) and Q-0111.1.
  • Unknown: the shapes of the Hyperdrive, R2, queue, rate-limit and email bindings in .deployment.env. That is why
    they are checked by name only.

Next

deploy.yml. A release candidate deploys as a target and sets alias-staging, behind a switch that stays off until the
cut-over. It includes the migration rule for shared data: the newest shared target migrates, behind a reviewer.

Refs #195

🤖 Generated with Claude Code

aRustyDev and others added 5 commits November 16, 2026 17:55
…ck the version and the route

The smoke of a Preview target must go through the shared hostname (ADR-0111): the edge sends a request to the target only with
a pin cookie, which it sets on /_edge/opt-in/<audience>?target=<name> for a principal Access admitted there. Without the pin
the answer is production's. Part of #195 stage E; no deploy runs these yet.

- scripts/edge-opt-in.sh <shared-origin> <audience> <target> <cookie-jar>:
  - asks with the CI opt-in service token (EDGE_CI_CLIENT_ID/_SECRET, in a 0600 header file, never argv), and writes the
    edge's pin (__Host-thrust_edge) to the jar;
  - asks again only for the refusals that time cures: the edge's "that target does not exist or is not open to you", given
    until the target's flag has propagated (up to 30 s), a 503, no answer;
  - every other answer is final: an empty-bodied Access 403, the edge's "not admitted", any other status, a 303 that sets
    no pin;
  - refuses, before asking anything, an origin that is not https, and an audience or target outside the edge's own grammar.
- scripts/smoke-deploy.sh:
  - SMOKE_COOKIE_FILE: the pin goes with every request of both phases. The sign-in's session cookies join it in one jar,
    so the read reaches the same target.
  - SMOKE_EXPECT_ROUTE: phase 1 also needs the edge's x-thrust-route to name the target.
  - Without either, the smoke is unchanged.
  - The new name check spells its letters out: in a UTF-8 locale `[a-z]` also matches capitals. The test found it.

Tests (test-smoke-deploy.sh, under dash: 54 passed, in the C and a UTF-8 locale). smoke_stub.py now also stands for the edge
with one target (--pin): only a request with that target's pin reaches it, and any other gets production's version, route and
an API that answers 421. Cases:
- through the edge, both phases reach the target;
- without the pin, production's version fails it;
- another route, or no route header, fails it;
- the opt-in waits out propagation and a transient 503, and gives up after its attempts;
- each final refusal is final, not retried;
- every usage error asks nothing;
- the secret is in no curl argv and in no output (seen through the existing argv-logging curl wrapper).
11 hand mutants of the two scripts each fail it. The first run had one survivor: retrying every 403 still matched the refusal
cases' fragment, so those cases now require the message only an immediate refusal prints.

Also: every deps step (14) and every ci-scripts test (29), run separately with sh as dash. plan-ci.py routes edge-opt-in.sh with
the other deploy scripts (test_plan_ci.py: 5024). A row in cicd.md.

Refs: #195
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h the edge, removing it again on any failure

The third piece of deploying release candidates as Worker Previews (#195 stage E, ADR-0111). It joins the two before it: the
target's configuration (preview-config.py, #241) and the smoke through the edge (edge-opt-in.sh and the smoke's pin and route).
No workflow runs it yet: the switch from staging to targets is held until the cut-over.

scripts/deploy-target.sh, everything from the environment like deploy-worker.sh:
1. Every input is checked before anything is asked of Cloudflare (exit 2, nothing called):
   - the name, in the edge's grammar; its Preview label is the name with `.` as `-`;
   - the commit, the shared origin, the web files, every variable;
   - the kind, a target kind of the Flagship policy;
   - the audience, one the policy lets CI reach that kind through (else the smoke could never opt in);
   - the expiry.
2. Production's configuration is rendered, and the target's derived from it (shared: production's data and rooms).
3. `wrangler preview --name <label> --json --ignore-base-config --tag <sha>`.
4. scripts/preview-result.py reads the answer. Behind the progress lines, it requires:
   - the URL the edge accepts, https://<label><suffix>;
   - a deployment id the edge accepts;
   - every declared binding, in what Cloudflare applied;
   - every room on the script_name it was given (production's Worker);
   - every variable with the text it was given (THRUST_PUBLIC_BASE_URL = the shared origin, Q-0111.2).
   Other bindings are checked by name only: the spike recorded only the shapes of rooms and variables.
5. `flagship.py put`: {url, deployment, release = the commit, kind, data = shared, expires}, read back.
6. The opt-in and the smoke through the edge, with the pin and the target's route.
7. The smoke's control: a version nobody deployed must fail.

A failure from step 3 on deletes the flag first, then the Preview, and a failed deploy over a live target therefore leaves
no target. A cleanup that fails says what it left. Each tool sees only its own secret: wrangler the Cloudflare token,
flagship.py the Flagship token, the opt-in its service token, the smoke its password; the render and the readers none.

Tests:
- test-deploy-target.sh, under dash: 121 passed. Fakes: target_fakes.py for wrangler's Previews (applying the previews block
  in the spike's recorded shape), a truthful opt-in and a truthful smoke, and the real flagship.py against flagship_fake.py.
  It covers:
  - every target kind deploying, with its Preview and flag checked against a model;
  - the steps in order, each with only its own secret;
  - every failure point leaving nothing (no flag, no Preview), and the step-4 ones stopping before any flag is written;
  - a flag that does not stick;
  - a failed cleanup saying what it left;
  - every usage error calling nothing;
  - a redeploy replacing the Preview and the flag.
- test_preview_result.py: 3957 checks. 300 generated previews blocks with Cloudflare's answers behind 0 to 3 progress lines,
  then every binding dropped, every room's script_name gone or wrong, every variable's text changed, and the URL and the
  deployment id broken every way the edge refuses.
- 17 hand mutants of the two scripts. The first run had one survivor: the deploy carried on past a Preview that was not the
  one asked for, until flagship.py refused the empty URL, and the message the case looked for was printed either way. Each
  step-4 failure now also requires that no flag was ever written, and the rerun killed every mutant.
- The test found a real bug, fixed here: the cleanup skipped the flag when `put` had failed its read-back, leaving whatever it
  had written.

Also run: every deps step and every ci-scripts test, each separately with sh as dash. plan-ci.py routes both scripts to
ci-scripts. A row in cicd.md. .gitignore keeps the two rendered configurations out.

Refs: #195
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Base automatically changed from feat/target-smoke to main November 17, 2026 03:42
# Conflicts:
#	.github/scripts/plan-ci.py
#	docs/src/architecture/cicd.md
@aRustyDev
aRustyDev merged commit 0c3c0ef into main Nov 17, 2026
40 checks passed
@aRustyDev
aRustyDev deleted the feat/deploy-target branch November 17, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant