Skip to content

feat(deploy): derive a shared Preview target's configuration from production's rendered one - #241

Merged
aRustyDev merged 2 commits into
mainfrom
feat/preview-config
Nov 16, 2026
Merged

aRustyDev merged 2 commits into
mainfrom
feat/preview-config

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

The first piece of deploying release candidates as Worker Previews (#195 stage E, ADR-0111). No deploy runs it yet.

Why

A Worker Preview inherits none of production's bindings: Cloudflare's Previews configuration says each one must be
restated under previews. A second template restating them by hand would drift from the first, so this derives them.

What it adds

scripts/preview-config.py --config <rendered> --profile shared --out <file.json> takes the configuration that
render-wrangler.sh rendered for production and writes it out as JSON, adding a previews block. Wrangler reads JSON as
it reads TOML.

The top level stays production's, unchanged. Deploying a Preview must not change what production runs. Whether
production turns preview_urls on is its own setting: Q-0111.1, decided at the cut-over with the Access app in the
infrastructure drafts.

What the shared profile (production's data) does with each part of the configuration:

Part In previews
vars, Hyperdrive, R2, rate limits, send_email, version_metadata restated as they are
the queue producer restated
the queue consumer left out: it never targets a Preview, and production consumes what a shared target sends
each room binding restated with script_name = the production Worker, so they are production's rooms (as the spike measured)
triggers, routes, migrations, assets, placement not restated

It refuses:

  • a setting it doesn't know, so a binding added to the template later can't silently be left out of the targets;
  • a configuration without version_metadata, because a target's smoke compares the deployment id it gives;
  • the isolated profile, which comes with stage F.

Checked

test_preview_config.py: 920 checks.

  • The real template, rendered with production-shaped values:
    • its top level is unchanged and its previews block matches the model;
    • every room names the production Worker;
    • it has a consumer and a cron, so dropping them is exercised.
  • 400 generated configurations, checked against a model written in the test, with a check that every case class
    was produced.
  • Refusals: every unknown binding kind, and each refusal writes nothing.

Hand mutants: 11 versions of the script with a planted bug; each one fails the tests.

wrangler 4.151.2 (CI's version): deploy --dry-run parses the config derived from the real template with no warning
about previews. Control: an unknown field under previews draws wrangler's "Unexpected fields" warning.

Also passing: every deps step (14), every ci-scripts test (29, each run on its own with sh as dash),
actionlint, and test_plan_ci.py (5025).

Next

scripts/deploy-target.sh:

  1. wrangler preview with this configuration;
  2. the Preview's secrets, from a file and never from arguments;
  3. flagship.py put;
  4. the smoke through the edge, with a CI pin;
  5. on failure, delete the Preview and its flag.

It will be tested with fakes. After that comes deploy.yml: the switch from staging to targets is held until the cut-over.

Refs #195

🤖 Generated with Claude Code

aRustyDev and others added 2 commits November 16, 2026 17:07
…duction's rendered one

The first piece of deploying release candidates as Worker Previews (#195 stage E, ADR-0111). A Preview inherits none of
production's bindings: each must be restated under `previews`. A second template restating them by hand would drift from
the first, so scripts/preview-config.py derives the block from the configuration render-wrangler.sh rendered for
production, and writes JSON (wrangler reads it as it reads TOML).

- The top level is production's, unchanged: deploying a Preview must not change what production runs. Whether production
  turns `preview_urls` on is its own setting, Q-0111.1, decided at the cut-over with the Access app of the infrastructure
  drafts.
- The `shared` profile (production's data):
  - vars, Hyperdrive, R2, rate limits, send_email and version_metadata restated as they are;
  - the queue producer restated, the consumer left out (it never targets a Preview, and production consumes what a
    shared target sends);
  - every room binding given `script_name` = the production Worker unless it names one already, so the rooms are
    production's, as the spike measured;
  - triggers, routes, migrations, assets and placement not restated.
- A setting it does not know is refused, so a binding added to the template cannot be left out of the targets without a
  decision. version_metadata is required (a target's smoke compares the deployment id). `isolated` (stage F) is refused.

Not run by any deploy yet; the deploy of a target comes next.

Tests: test_preview_config.py, 920 checks.
- The real template, rendered with production-shaped values by render-wrangler.sh. Its top level is unchanged, its
  previews are the model's, and every room names the production Worker. The template has a consumer and a cron, so
  dropping them is exercised.
- 400 generated configurations against a model written in the test, with a check that the generator reached each case
  class.
- Every unknown binding kind and every refusal writes nothing.
11 hand mutants each fail it.

Validated with wrangler 4.151.2 (CI's version): `deploy --dry-run` parses the config derived from the real template with no
warning about `previews`. The control: an unknown field under `previews` draws wrangler's "Unexpected fields" warning.

Also: every deps step (14), every ci-scripts test (29) run separately with sh as dash, and actionlint. plan-ci.py routes the
script to ci-scripts (test_plan_ci.py: 5025).

Refs: #195
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit 4ffe101 into main Nov 16, 2026
38 checks passed
@aRustyDev
aRustyDev deleted the feat/preview-config branch November 16, 2026 23:28
aRustyDev added a commit that referenced this pull request Nov 17, 2026
…h the edge, removing it again on any failure (#257)

* feat(deploy): smoke a target through the edge: opt in as CI, then check 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]>

* feat(deploy): deploy a target as a Worker Preview and prove it through 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]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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