Skip to content

ci: fail when an expected test count of the contract suite's passes is stale - #181

Merged
aRustyDev merged 1 commit into
mainfrom
ci/contract-count-guard
Nov 15, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
ci/contract-count-guard

Conversation

@aRustyDev

@aRustyDev aRustyDev commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Part of #58; this PR does not close it.

The expected test counts of the contract suite's passes went stale twice in one day (2026-11-14: stage2's main said 59 while the suite listed 61, then 64), because a count is checked only when its script runs, and scripts/stage2-contract.sh needs a deployed Worker. This makes CI check them.

What it does

scripts/check-contract-counts.sh reads every arm of scripts/stage2-contract.sh (13) and scripts/contract.sh (10 on this branch, 11 on main since #176 added mail), runs the arm's own filters through libtest (cargo test -p thrust-contract-tests --test <bin> -- --list --format terse <filters>; no server, no environment), counts the lines that end in : test, and compares with the arm's count. It copies no filter, so a filter cannot drift from its count.

  • hermetic job: the real check, right after the suite is built by the nextest step, then a control: the real stage2-contract.sh with its main count made wrong must be refused.
  • deps job: --self-test, no compile: 16 worlds with a fake lister, each read to be refused for the reason it names.
  • Two steps, so gate's required contexts do not change.

It also covers three counts that no CI cell checks today: blast, budget and engine (contract-all.sh runs nine passes and not those; mutants.sh runs the last two against broken builds only).

It fails closed

Exit 1 is a count that differs. Exit 2, "cannot vouch", is: an arm it cannot read; a different number of arms read than written (the check that a reformatted script cannot make it read nothing and pass); no arm at all; a count that is not a number; an EXPECT_ variable with no value or two; a listing that fails; and a filter that selects nothing (libtest prints nothing and exits 0 for that, which is not a count of anything).

Checked

  • All 23 arms agree on this branch (stage2 main 64, contract main 70, bindings 3 and 5).
  • On a runner, the first CI run (this branch merged with main, which by then had feat(email): an SMTP adapter, and the native server sends the reset mail when it has a relay #176's mail pass): the hermetic step read 13 stage2 arms and 11 contract arms and passed in 33 seconds (the first listing took 26 of them, the other 23 together 6), so whatever cargo test -p had to compile again cost under half a minute against the job's 30-minute timeout. The eleventh arm is contract mail: 3 tests, which did not exist when I wrote the guard and was counted with no change to it (the arms are read from the scripts, and a count of arms read that differs from the count of arms written is exit 2). The control, a stage2 count made wrong, was refused.
  • End to end, on the real suite: renaming one test out of the sweeper_ filter makes four arms fail with exit 1, naming the script (stage2 main 65 for 64, sweeper 2 for 3; contract main 71 for 70, sweeper 2 for 3). The file was restored and compared byte for byte.
  • The self-test passes under /bin/dash, under this Mac's sh, and in an ubuntu:24.04 container (dash with GNU sed and grep, as on the runner). The self-test's verbose mode (CHECK_VERBOSE=1) prints what each case said; I read them all.
  • The prose that had rotted in stage2-contract.sh is fixed: its usage line named 6 of its 13 passes, its header said bindings runs 5 tests (it runs 3), and crontrigger, blast and ratelimit had no entry. evidence-and-controls.md, contract-suite.md and G-33's mention of the stale 59 now say what enforces the rule.

Not run here

Stage2's count of 64 has still never been run against a deployed Worker: this checks it against the suite, not against a Worker.

🤖 Generated with Claude Code

…s stale

`scripts/contract.sh` and `scripts/stage2-contract.sh` each exit 5 when the number of tests that passed is not the number they expect, but only when they are run. Most of contract.sh's passes run in CI cells; `blast`, `budget` and `engine` run in none (contract-all.sh has nine passes and not those, and only mutants.sh runs the last two, against broken builds); and stage2-contract.sh needs a deployed Worker. Its `main` count was 59 until 2026-11-14 while the suite had listed 61 since #151, and #169's three tests made it 64 the same day. Nothing noticed.

`scripts/check-contract-counts.sh` reads every arm of both scripts (13 in stage2, 10 in contract.sh), runs the arm's own filters through libtest (`cargo test -p thrust-contract-tests --test <bin> -- --list --format terse <filters>`, which needs no server and no environment), counts the lines that end in `: test`, and compares. It copies no filter, so a filter cannot drift from its count. It fails closed with exit 2 on an arm it cannot read, a different number of arms read than written, no arm at all, a count that is not a number, an `EXPECT_` variable with no value or two, a listing that fails, and a filter that selects nothing (libtest prints nothing and exits 0 for that).

The self-test (a step of `deps`, no compile) runs it on 16 worlds with a fake lister, each read to be refused for the reason it names: a count one too high and one too low, a filter that selects nothing, a failing listing, a script with nothing to read, an arm with no count, a variable with none and with two, the default arm of contract.sh read as `main`, one pass asked for alone. The real run (a step of `hermetic`, after the suite is built) ends with a control on the real stage2-contract.sh with its `main` count made wrong, which must be refused.

Shown on the real suite: all 23 arms agree today (stage2 `main` 64, contract `main` 70, `bindings` 3 and 5), and renaming one test out of `sweeper_` makes four arms fail with exit 1 (stage2 `main` 65 for 64 and `sweeper` 2 for 3, contract `main` 71 for 70 and `sweeper` 2 for 3). The file was restored and compared. The self-test passes under dash on this Mac, under the Mac's sh, and in an ubuntu:24.04 container (dash with GNU sed and grep).

The prose that had rotted in stage2-contract.sh is fixed with it: its usage line named 6 of its 13 passes, its header said `bindings` runs 5 tests where it runs 3, and `crontrigger`, `blast` and `ratelimit` had no entry. evidence-and-controls.md and contract-suite.md now say what enforces the rule they state, and status.md no longer says the count "has not been kept up".

Not run here: the new `hermetic` step on a runner. `cargo test -p thrust-contract-tests` unifies features differently from `--workspace`, so it may rebuild some dependencies there; the job's timeout is 30 minutes.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit 6b671cf into main Nov 15, 2026
68 of 70 checks passed
@aRustyDev
aRustyDev deleted the ci/contract-count-guard branch November 15, 2026 07:31
aRustyDev added a commit that referenced this pull request Nov 15, 2026
… into the OpenAPI Projects branch

#179 conflicted with main a third time, once the three small PRs it was opened with had merged. One conflict, `docs/src/testing/status.md`, and it is one hunk because G-25 and G-26 are adjacent rows: this branch changed G-25 only (the schema diff), #180 changed G-26 only (`THRUST_RL_CREATE_ID`). Checked by hash against the merge base (G-25 4337a2f968e5 on main and the base, 55eb907971f4 here; G-26 bb75219068af on the base and here, 104945eb6fb9 on main), so the resolution is this branch's G-25 row and main's G-26 row, and each now has exactly those hashes.

`.github/workflows/ci.yml` merged without a conflict: `deps` has the count guard's self-test, the release step and the OpenAPI step; `hermetic` has the count check and the OpenAPI tests; `lint` has the OpenAPI clippy. #182's D-19 row and #181's sentence in G-33 are in `status.md`, no conflict marker is left anywhere in the tree, and `cargo metadata --locked` resolves.

Refs: #58
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