Skip to content

chore(ci): repeat a PR's changed Bun test files under CPU load before merge (#4109) - #4118

Closed
schlessera wants to merge 6 commits into
mainfrom
chore/4109-test-determinism-gate
Closed

schlessera wants to merge 6 commits into
mainfrom
chore/4109-test-determinism-gate

Conversation

@schlessera

@schlessera schlessera commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #4109

What changed

A Bun test file that a pull request adds or modifies is now run several times under CPU load before it merges. bun scripts/test-determinism.ts --base <ref> [--json] selects those files against the merge base and runs them in one invocation of the offline test wrapper with --rerun-each=<n> --bail=1, while one busy loop per CPU runs. It fails on the first failing repetition and names the file, the repetition and the case. The planner selects a new hosted determinism job whenever the change touches such a file, at every pull-request cadence including draft and in draft heavy feedback. draft gates, proof, the feedback aggregate and the merge path require it when selected and require its intentional skip otherwise. check:pr never runs it and names the command in --plan.

Why this shape

  • One wrapper invocation with --rerun-each, not N invocations. Checked against the pinned Bun 1.4.2: each file runs n times in a row in one process, the module is evaluated again for each run, globalThis and process state persist, and a run with output is headed <file>: (run #k) on stderr, also under GITHUB_ACTIONS=true. One invocation keeps the wrapper's single preparation build. The cost is that a file leaking state into its next run fails too, which is recorded as a known limit in the decision.
  • A passing run must show its repetitions. The command reads Bun's JUnit report and fails if any file ran fewer repetitions than planned, so a flag that silently stops repeating cannot pass.
  • Budget in reviewed-weight seconds. 600 seconds of scripts/test-shard-costs.json weights. Over the last 150 merges on main, 142 selections fit five repetitions inside it. Reduction is uniform, never below two, and a selection too heavy for the floor still runs every file twice and is reported over budget.
  • Burners that cannot leak. Each is killed by PID on completion, error, signal and process exit, and exits by itself within 200 ms if its parent is killed (checked with SIGKILL on Bun 1.4.2 and 1.4.4).
  • Never on main. The planner records the selection only for pull-request planning, so a main push never selects the job and the red-main categories are unchanged. determinism is not in POST_MERGE_CATEGORIES.
  • The job reuses ci-proof.ts for the unit job's prerequisites: copyfile install, ci-runtime-setup.sh, the real-Chrome cold start and BRAIN_REQUIRE_CHROME=1.

Decision record: docs/decisions/ci-utility.md, "Changed tests repeat under load before merge" (maintainer ruling of 2026-11-16).

Proof

bun run check:pr --base origin/main

Tested head 19f8e2d1a, merge base 78e326c80. Passed: 1,230 tests across 56 files.

The PR's own determinism job is the live proof that the job works, because this PR changes eight Bun test files.

  • First run, head e906643d1: failed, and it was right to. https://github.com/schlessera/brain-kit/actions/runs/43986946575/job/133717889783. On the draft the planner selected determinism and no other proof category. The job set up real Chrome, started four burners on four CPUs and repeated seven changed files five times each (552 s for about 174 weighted s). It then failed in the gate's own test file: under GitHub Actions, Bun 1.4.2 prints each run header as ::group::<file>: (run #k), which the failure parser did not read, so the racy fixture's failure was reported as unknown file, repetition unknown. draft gates failed with it. A coding agent's environment switches Bun to a third output form, which is why local runs did not show it.
  • Fix, head 19f8e2d1a. The parser reads both header forms. Failing first: a GitHub Actions group header names the file and repetition too and under the GitHub Actions log groups reporter the racy fixture's failure still names its file and repetition were red on HOSTED_GROUP_HEADER_READ and FAILURE_NAMED_UNDER_LOG_GROUPS before the parser change, green after, and red again with the change reverted. The receipt now runs under both reporters, on Bun 1.4.2 and 1.4.4.
  • Run on the fixed head 19f8e2d1a: https://github.com/schlessera/brain-kit/actions/runs/43989701310/job/133727305304. In progress when this body was last edited; the metadata job passed and determinism is the only selected proof job. The criterion is met only when it is green.

Local run of the gate on this PR's own files (Bun 1.4.2, two burners to spare the shared host): bun scripts/test-determinism.ts --base origin/main --burners 2 --json passed, 8 files, 5 of 5 repetitions observed for each, 320.9 s for 174.2 weighted s.

Acceptance receipts, all in tests/test-determinism.test.ts, which runs the real command through the real offline wrapper in a scratch Git checkout:

Criterion Case Result
A racy fixture fails, file and repetition named a racy fixture that fails one run in three fails the gate… exit 1, FAILED: tests/landing.test.ts, repetition 3 of 5: "the crew is aboard before the tide turns"
The same fixture made deterministic passes the same fixture made deterministic passes all five repetitions… exit 0, repetitions: 5, observed: 5
No Bun test file changed, job not selected, aggregates do not require it a change that touches no Bun test file never selects it… and the aggregate refuses published outputs that drop a selected repetition or add an unselected one (tests/ci-plan.test.ts), the aggregate requires repeated-run proof when selected and an intentional skip otherwise (tests/hosted-proof.test.ts), the repetition-skipped merge scenario (tests/integration-command.test.ts) selection false at all six cadences; proofProblems is empty for an unselected skip; a selected one that did not pass is refused by the aggregate and by integrate.ts merge
Five do not fit: reduced count reported, each file still runs twice a selection that cannot fit five repetitions… repetitions: 3, observed: 3; then at a smaller budget repetitions: 2, overBudget: true, observed: 2 per file
Offline preload active the repetitions run under the offline preload… exit 1, Offline test guard: attempted real network access, fetch https://oracle.example.invalid/prophecy

The racy fixture is a real-time race with a fixed schedule: a 150 ms timer against work that takes 600 ms on every third run. It is deterministic on purpose, so the gate's own test is not a flake.

Mutation receipts (break the guard, named test red on the expected assertion, restore):

Mutation Red test and assertion
One run only: --rerun-each=1, with the repetition-evidence check also removed The racy fixture passes its single run (1 pass, 0 fail); a racy fixture that fails one run in three… fails on expect(run.code).toBe(1). With only the flag changed, the same test fails on RACY_FIXTURE_FAILS_AT_ITS_THIRD_REPETITION and the command reports ran 1 of 5 repetitions
Bypass the wrapper: bun test in place of bun run test the repetitions run under the offline preload… fails on OFFLINE_PRELOAD_ACTIVE
No floor: Math.max(1, …) FLOOR_OF_TWO_HOLDS and FLOOR_STILL_RUNS
Burners never killed BURNER_KILLED_BY_PID
Drafts skip the job: !draft && EVERY_PULL_REQUEST_CADENCE (draft: false)
Deleted files selected ADDED_AND_MODIFIED_BUN_TESTS_ONLY
Main pushes plan it MAIN_PUSH_PLANS_NO_REPETITION
determinism removed from PROOF_JOBS SELECTED_REPETITION_MUST_PASS, and the merge-path scenarios in tests/integration-command.test.ts
Parser ignores ::group:: headers HOSTED_GROUP_HEADER_READ, FAILURE_NAMED_UNDER_LOG_GROUPS

The offline receipt first could not go red: the test process's own network guard adds its preload to every bun it spawns, so bypassing the wrapper still printed the refusal. The harness now starts the command through an alias the guard does not recognise, as tests/test-network-guard.test.ts does, and the mutation above is from after that fix.

{"version":1,"kind":"brain-check-pr-receipt","head":"19f8e2d1a9b6f03802d923458b5bb43316462c97","base":"origin/main","mode":"focused","startedAt":"2026-11-17T00:39:09.088Z","finishedAt":"2026-11-17T00:41:28.843Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":21593.320197999998},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":197.07719599999837},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":151.81996499999877},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":20.243202000001475},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":117773.66745300002}]}

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof.
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see.
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved.
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed.
  • Provider history stays append-only (docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed.

Anything left open

  • "The job passes on the PR that adds it": the first hosted run failed on a defect in the gate, fixed in 19f8e2d1a. The criterion is met only when the determinism job on the current head is green.
  • Vitest browser, layout, endurance and story specs are out of scope: ci: repeat a PR's changed Vitest browser, layout and story specs in the pinned container #4116 (needs scoping, not agent-ready).
  • A selection too heavy for two repetitions inside the job's 40-minute step limit fails visibly by timeout. 4 of the last 150 merges were that large: ci: a determinism selection too heavy for two repetitions can exceed the job's step limit #4117 (needs scoping).
  • scripts/test-determinism.ts is not in the proof-system path set, which changes only by maintainer ruling. This PR is a proof-system change through its workflow, scripts/ci-* and check-pr.ts edits.
  • A branch that confirms or merges after this lands needs it merged in: its integrate.ts otherwise expects a job inventory without determinism.

🤖 Generated with Claude Code

schlessera and others added 3 commits November 17, 2026 00:17
Add bun scripts/test-determinism.ts. It selects the Bun test files a change
adds or modifies against its merge base and runs them through the offline
test wrapper with --rerun-each and --bail=1 while one busy loop per CPU runs.
Five repetitions by default, reduced uniformly to a floor of two when the
reviewed weights exceed the 600-second budget; no selected file is skipped and
the report lists each with its repetitions. Burners are killed by PID on every
exit path and exit by themselves when their parent dies.

The planner records the selection for pull requests and selects determinism at
every pull-request cadence, drafts included, and never on main.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…4109)

Add the hosted determinism job with the unit job's runtime prerequisites, and
the same job in the generated draft heavy feedback workflow. The proof and
draft gates aggregates, the feedback aggregate and the merge path require it
when selected and its intentional skip otherwise. check:pr never runs it and
names the command in --plan.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 17, 2026
@schlessera schlessera added type: chore Tooling, CI, release plumbing, dependencies. area: ci CI workflows, the gates they run, release scripts, packaging. labels Nov 17, 2026
…minism (#4109)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The command appends its table to GITHUB_STEP_SUMMARY. The fixture runs now
write to a scratch file, and the receipts assert on it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…n gate (#4109)

The first hosted determinism run failed in the gate's own test. Under
GITHUB_ACTIONS Bun 1.4.2 prints each run header as ::group::<file>: (run #k),
which the failure parser did not read, so a failure lost its file and
repetition. The parser reads both forms, and the racy-fixture receipt now runs
under the plain and the log-group reporter.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Superseded by #4134, which merged this branch together with its sibling proof-system change as one squash (be0bb0708). The issue is closed by that PR.

@schlessera schlessera closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci CI workflows, the gates they run, release scripts, packaging. type: chore Tooling, CI, release plumbing, dependencies.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: repeat a PR's changed Bun test files under CPU load before merge

1 participant