Skip to content

feat(deploy): make every Flagship routing flag from a policy in the repository, and check the live app against it - #229

Merged
aRustyDev merged 1 commit into
mainfrom
feat/flagship-as-code
Nov 16, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
feat/flagship-as-code

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

Stage D of #195 (ADR-0111). The Flagship flags the edge reads are made only by CI, from a policy in this repository.
Nothing runs live until the Flagship app exists.

What it adds

.github/deploy/flagship/policy.json, which names no person:

  • the value of routing (off);
  • the audiences (dev, rc), which must be exactly the edge's ACCESS_AUD_<AUDIENCE> variables;
  • the aliases (prod, staging);
  • for each kind of target, which principal kinds and audiences reach it:
Target kind Principal kinds Audiences
release, rc human, ci dev, rc
dev human, ci dev

These defaults are mine. Change them if they're not what you want.

scripts/flagship.py, the only writer:

  • validate: checks the policy alone, offline. It runs in deps.
  • check [--evaluate] [--retries n]: reports:
    • every difference from the policy;
    • every flag the policy doesn't make;
    • every target or alias value the edge would refuse.
      With --evaluate, it also asks Flagship what each flag serves to every principal kind and audience.
  • sync: rewrites what differs, creates routing, deletes foreign flags, then re-reads everything and checks again.
  • put, alias, delete: for the deploys and teardowns of targets (stages E and F). Each reads back what it wrote.

A target flag defaults to denied ({}). Its allowed value is {url, deployment, release, kind, data, expires},
and it has one rule per policy entry: kind in [...] and audience in [...], both of which must match. Values follow
the edge's own grammar (route.rs, pin.rs).

Secrets: the token is read only from the environment, never from an argument. The base URL must be https (http only
to 127.0.0.1, for the test fake).

.github/workflows/flagship.yml:

  • sync: on a push to main that changes the policy, the script or the workflow, and by hand.
  • check --evaluate --retries 12: after a sync, and nightly at 05:23 UTC. It writes nothing, so a dashboard edit is
    reported, not silently overwritten.
  • Off until the repository variable FLAGSHIP_APP_ID is set.
  • Credentials: in the environment flagship. lint-all-workflows.sh allows only its two jobs to use it.

Wiring:

  • ci.yml: flagship.py validate in deps; test_flagship.py in ci-scripts.
  • plan-ci.py: routes the policy and the script to deps and ci-scripts. Its tests' samples follow.

Docs:

  • cicd.md gets a "Routing flags" section;
  • status.md gets G-43;
  • ADR-0111 gets a dated update.

One deviation from the plan

There is no live check on pull requests. A pull request has no secrets, and a policy change is meant to differ from
what is live. Pull requests get validate and the tests against the fake; the live check runs after every sync and
every night.

To turn it on (after the infrastructure issue makes the app)

  1. Create the environment flagship, with deployment branches limited to main.
  2. Give it the secrets FLAGSHIP_WRITE_TOKEN and FLAGSHIP_READ_TOKEN: app-scoped Write and Read tokens.
  3. Give it the variables CLOUDFLARE_ACCOUNT_ID and PREVIEW_HOST_SUFFIX (the edge's).
  4. Set the repository variable FLAGSHIP_APP_ID.

Tests

test_flagship.py: 463 checks, about 20 s, against flagship_fake.py. The fake is built from the published OpenAPI
schema: its fields, cursor pagination, AND/OR condition groups, and evaluation as documented. The expected flags come
from a model in the test, not from the script. It covers:

  • every target kind, with several names;
  • every applicable change to every flag of a good app. check finds each one, and sync restores exactly that app,
    writing only that flag;
  • foreign flags, and every broken value and policy;
  • page sizes 1, 2, 3 and 200;
  • a service that ORs conditions, which only --evaluate catches;
  • propagation lag: fails without --retries, passes with them;
  • both response shapes of evaluate;
  • every missing or malformed variable, and a wrong token;
  • the token appearing in no output.

Hand mutants: 21 versions of the script with a planted bug; each one makes the tests fail.

Also passing:

  • every deps step (13);
  • every ci-scripts test (28), each run on its own with sh as dash;
  • actionlint;
  • the workflow linter, with a control: without the new allowance, it refuses flagship.yml's environment and secrets.

Not verified

  • The real Flagship API (G-43). The spike exercised flag create, read, update and delete with a one-condition rule.
    It did not exercise the list endpoint, a two-condition rule or the evaluate endpoint. The first flagship.yml run's
    check --evaluate is the check.
  • The book build. mdbook-mermaid isn't installed here; the docs job builds it.

Refs #195

🤖 Generated with Claude Code

…epository, and check the live app against it

Stage D of #195 (ADR-0111): the flags the edge reads are made only by CI, from definitions in this repository.

- .github/deploy/flagship/policy.json:
  - routing's value (off);
  - the audiences, dev and rc, which must be exactly the edge's ACCESS_AUD_<AUDIENCE> variables;
  - the aliases, prod and staging;
  - per kind of target, which principal kinds and audiences reach it:
    - release and rc: human and ci, through dev or rc;
    - dev: human and ci, through dev.
  It names no person.
- scripts/flagship.py, the only writer:
  - validate: the policy alone, offline;
  - check [--evaluate] [--retries n]: every difference from the policy, every foreign flag, every value the edge would
    refuse, and (with --evaluate) what Flagship actually serves to every principal kind and audience;
  - sync: rewrites what differs, creates routing, deletes foreign flags, then re-reads and checks again;
  - put / alias / delete: for the deploys and teardowns of targets (stages E and F); each reads back what it wrote.
  A target flag: default `denied` ({}), `allowed` = {url, deployment, release, kind, data, expires}, one rule per policy
  entry with `kind in [...]` and `audience in [...]`. Values are held to the edge's own grammar (crates/edge/src/route.rs,
  pin.rs). The token comes only from the environment; the base URL must be https (or http to 127.0.0.1, for the fake).
- .github/workflows/flagship.yml: sync on a push to main that changes the policy, the script or the workflow, and by hand;
  check --evaluate --retries 12 after it and nightly. Off until the repository variable FLAGSHIP_APP_ID is set; environment
  `flagship` with app-scoped Read and Write tokens. lint-all-workflows.sh allows its two jobs that environment.
- ci.yml: `flagship.py validate` in deps; test_flagship.py in ci-scripts. plan-ci.py routes the policy and the script to
  deps and ci-scripts (test_plan_ci.py's samples follow).
- cicd.md "Routing flags", status.md G-43, and a dated update to ADR-0111.

Deviation from the plan: no live check on pull requests. A pull request has no secrets, and a policy change is meant to
differ from what is live; it gets validate and the fake-backed tests, and the live check runs after every sync and nightly.

Tests: test_flagship.py, 463 checks against flagship_fake.py, a stand-in built from the published OpenAPI schema (the
fields, cursor pagination, AND/OR condition groups, evaluation as documented). The expected flags come from a model in
the test, not from the script. It covers:
- every target kind with several names;
- every applicable change to every flag of a good app (check finds it; sync restores exactly that app and writes only
  that flag);
- foreign flags;
- every broken value and policy;
- page sizes 1, 2, 3 and 200;
- a service that ORs conditions (caught only with --evaluate);
- propagation lag (fails without retries, passes with them);
- both response shapes of evaluate;
- every missing or malformed variable, and a wrong token;
- the token in no output.
21 hand mutants of the script each fail it.

Also passing: every deps step (13), every ci-scripts test (28) individually with sh as dash, actionlint, and the
workflow linter with a control (without the allowance it refuses flagship.yml's environment and secrets).

Not verified: the real Flagship API beyond what the spike exercised (G-43). Nothing runs live until the app exists.

Refs: #195
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit bbe21ff into main Nov 16, 2026
44 checks passed
@aRustyDev
aRustyDev deleted the feat/flagship-as-code branch November 16, 2026 21:05
aRustyDev added a commit that referenced this pull request Nov 16, 2026
… (stage 0.2) (#236)

research/0018-gate-spike.md records what the spike (draft #232, closed) measured: five
designs against seven scenarios, and eleven facts, in two identical samples. The choice
is A+: every called workflow ends with a `verdict` job, and gate requires the callee's
result to be success and its `verdict` output to be pass. It was right on all seven
scenarios; the control (the calling job's result only) was wrong on three, the same
without the output on one, and re-actors/alls-green on two.

The measurements corrected the plan, and PLAN.md and phases/0001-foundation.md say so:

- A calling job is success when at least one job inside it succeeded, even if a planned
  sibling was skipped; with nothing inside run it is skipped. The plan had said success
  when every job inside was skipped.
- A callee's workflow-level concurrency deadlocks the run and starts no job (the group is
  built from the caller's name), and a permission its caller did not grant stops the run
  from starting, so no gate would report.
- An if that cannot be evaluated skips the job without failing it.
- actionlint refuses a broken call contract, but only inside a git repository.

Also recorded: flagship.yml (#229) on the inventory, and the test-suites plan (#234),
whose pull requests edit commands inside jobs that Phase 1 moves.

Docs only: plan-ci.py plans no job for this diff.

Co-authored-by: Claude Sonnet 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