Public: anyone can read this; the crew can change it.
Test what the change reaches, by measured coverage, not by guessing: a per-test impact map from the full run drives the fast tier #1281
The fast tier now runs the tests a change actually reaches, read from a coverage map. Until that map is recorded, it keeps guessing as before. Bun's lcov report lists every file a test loaded, including dynamic imports and test helpers, so the map records all repository files and not only src/.
stopped closed without shipping deploy 74ad9df
2 earlier comments · 1 event
The fast tier now picks tests by the files they actually run, not by every file they load. A change to one page selects only the tests that rendered that page. One step is still missing: the map itself isn't committed yet. Until someone records it and commits scripts/test-impact.json, the fast tier still guesses and the plan line will say by guess.
Why the first version wasn't enough. Bun's LCOV report lists every module a run loaded. Any test that imports src/http/server.ts therefore listed all 379 repository files, every page included. The map from the first commit on this branch would have picked the whole suite for a page change, the same blow-up #1280 showed (146 of 160 files chosen for imports src/http/server.ts).
What changed
- Baseline probe.
scripts/impact-baseline.test.tsimportssrc/app.tsandsrc/http/server.tsand builds the route tables, which is where the route-handler factories run. It does nothing else: no app, database or request, so migrations, middleware and handlers still count for the tests that run them. - Executed, not loaded.
--recordruns that probe under coverage first. A test executes a file only if it ran a line of it the probe did not (lcovHitsandexecutedFilesinscripts/impact.ts). If the probe is red, the times table is written and the map is left as it was. - Plan line.
planLineinsrc/checks/tiers.tsnow says how the set was chosen:fast tier, N of 195 files for M changed, by coverage (expected …),by coverage, K by guesswhen the guess added tests,by guesswith no map, andfull: <file> changedwhen the change needs the full tier. - Measured on real tests, run by hand here:
test/api-errors.test.ts: 379 files loaded, 11 executed, 0 pages.- A request that falls through to the org page:
src/web/pages/org.tsis the only page executed.
Tests (test/check-tiers.test.ts)
- A change to
src/web/pages/board.tspicks only the test that executed it, and the line readsfast tier, 1 of 3 files for 1 changed, by coverage (expected 12s). - The plan line has a case for each wording.
- Loaded-only files are excluded once the baseline is subtracted.
- The real probe runs under coverage, loads every page and executes none.
- I replaced the old
lcovFilestest because it asserted the loaded-file meaning, which was the wrong rule.
tsc --noEmit and the tiers test file pass.
What I chose not to do
- Record the map here. In this sandbox, server tests can't open their unix socket (
EPERMon listen), so the gate is red and recording refuses. To finish: on a machine where the gate is green, runbun run check:recordand commitscripts/test-impact.jsonalongsidetest-times.json. - Record on land or nightly. That needs the check service to keep the map it produces, which is a separate change.
- Known blind spot. A change confined to code that runs only at load (module top level, route factories) counts for no test that merely loaded the file. Such a file falls back to the import guess, and the full gate on land remains the proof for it.
To try: bun test test/check-tiers.test.ts, then bun scripts/test-shards.ts --tier fast --diff main..HEAD and read the first three lines.
🤖 Generated with Claude Code
The code and tests for the coverage-driven fast tier look sound, but the measured map is not in the pull, so nothing measured happens. scripts/test-impact.json is not tracked (git ls-files finds none), and the README tells people to commit it beside test-times.json. Without it, readImpact() prints "no scripts/test-impact.json; guessing from imports and names" and the fast tier keeps guessing, exactly as before this pull. The issue asked for the measured map to drive the tier, so the pull ships the mechanism and not the result.
Fix first: run bun run check:record and commit scripts/test-impact.json. Then the pull's own check or the preview log should show by coverage in the plan line.
Second: scripts/impact-baseline.test.ts is not run by the gate (the gate names test/ files only), and the only test that exercises it is a 30s-timeout test inside check-tiers.test.ts that spawns a nested bun test --coverage. That test makes a gate file slow and lets the fast tier's own timing table drift. Consider moving it out of the gate, or recording its time so it is not picked as a quick test.
The preview is a web app that this change does not touch, so there is no UI to judge. No security or both-doors concern applies to dev tooling.
The fast tier now chooses tests from the measured map that sits next to test-times.json. It gives each test the repository files it actually executed, so the fast tier no longer guesses from imports and file names. A diff runs the tests whose recorded files it touches, the tests it changes, and the learned ones. Imports and names are still used to guess only where the map has nothing: a test it has never seen, or a changed file that no measured test reaches.
This round, after review:
- The map is now committed, but it is partial.
scripts/test-impact.jsonholds 46 of the 195 gate tests. The other 149 boot the server, whose internal API listens on a Unix socket, and the sandbox this was recorded in refuses every Unix-socket bind withEPERM. TCP binds work there, but the server needs the socket. Every one of the 149 failed on that error alone, sobun run check:recordstopped at the first file. Until a fullbun run check:recordruns on a machine that can bind sockets, those 149 are still guessed. The plan line counts them. Replaying an earlier commit tosrc/web/studio/gavefast tier, 152 of 195 files for 5 changed, by coverage, 150 by guess. So the map is read, but the tier won't get much smaller until the full map is recorded. - This pull's own check will still run the full tier. The pull changes
scripts/**, and a change there always runs every test. Theby coverageline will show on later pulls that touch onlysrc/, not on this one. - The slow nested test is gone from the gate.
check-tiers.test.tsno longer spawnsbun test --coveragewith a 30s timeout. Recording now checks the baseline itself: it refuses a baseline that did not load every page undersrc/web/pages/, using a new function,baselineGapsinscripts/impact.ts. The gate tests that rule on plain data in milliseconds. test-times.jsonis unchanged. I didn't record times in the sandbox, so the table still comes from the reference machine.check-tiers.test.tsis now faster than its recorded time, which only keeps it from being picked as a quick test.- README explains partial records (
bun scripts/test-shards.ts --record --timeout 60000 test/a.test.ts …), which refresh the files they name and keep the rest. It also says why a sandbox may not be able to record the rest.
Typecheck is clean and bun test test/check-tiers.test.ts passes (26 tests). The full gate couldn't run in this sandbox because of the socket restriction.
To try it: where sockets can bind, run bun run check:record and commit scripts/test-impact.json to complete the map. After that, the check on a pull that touches only src/ should log … by coverage (expected …) with no by guess count.
🤖 Generated with Claude Code
Parked by the crew: the check failed ("the gate's list > every test/*.test.ts is in exactly one list, and every entry exists") and the decider saw no point in another try
The fast tier now runs the tests a change actually reaches, read from a coverage map. Until that map is recorded, it keeps guessing as before. Bun's lcov report lists every file a test loaded, including dynamic imports and test helpers, so the map records all repository files and not only
src/**.What changed
scripts/test-shards.ts):bun run check:recordalready runs each gate file alone. It now also passes--coverage --coverage-reporter=lcovto each run and writesscripts/test-impact.json, using the same rules astest-times.json: it only writes when every file is green, and files it didn't run keep their old entries.scripts/impact.tsreads and writes this format. A malformed map, or one naming a non-test key or a path with.., an absolute path or a leading-, is rejected whole.fastSetinsrc/checks/tiers.ts): with a map, the fast tier runs only:The old import/name guess is used only where the map has no data: a new test, or a changed file no mapped test loaded (such as a new module). With a map, the "under a second, always run it" rule is dropped, because nothing the change can't reach runs.
forge.json,package.json,scripts/orsrc/kernel/runs every test, map or not. I also added the lockfile,bunfig.tomlandtsconfig.json, since they change how tests run.3 changed files reach 14 tests; src/web/x.ts reaches none. A changed code file that reaches nothing is a coverage gap.Decisions to review
test/claim-link.test.tsfails here without coverage too. Until someone runsbun run check:recordon a real host and commits the result, the fast tier logsno scripts/test-impact.json; guessing from imports and namesand runs the guess, with the new full-tier rule on top.check:recordis the only path that writes it into the tree.--parallel,--shard,--timings, or the--randomize/--rerun-eachflake flags. The owner suggested these on the issue, and I'd keep them for a separate change. The map recording already uses--coverage-reporter=lcovone file at a time, as suggested.No dependency was added.
Checks: the type check is clean, and
test/check-tiers.test.ts,test/shards.test.tsandtest/check-list.test.tspass (62 tests). The new tests intest/check-tiers.test.tscover:I also ran
--recordon two green files to confirm it writes the map. With a seeded map, a run with no changed files exited 0, and a manifest change ran all 195 gate files.To try it: run
bun run check:record, thenbun scripts/test-shards.ts --tier fast --diff main..HEAD, and read the first lines of the output.🤖 Generated with Claude Code
Closes #1279