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

Closed opened this in answer to
Closed without merging

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/.

Notes

stopped closed without shipping deploy 74ad9df

opened this

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

  • Recording (scripts/test-shards.ts): bun run check:record already runs each gate file alone. It now also passes --coverage --coverage-reporter=lcov to each run and writes scripts/test-impact.json, using the same rules as test-times.json: it only writes when every file is green, and files it didn't run keep their old entries. scripts/impact.ts reads 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.
  • Choosing tests (fastSet in src/checks/tiers.ts): with a map, the fast tier runs only:
    • tests that loaded a changed file;
    • tests the pull itself changed;
    • tests learned from an earlier red gate on land.

    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.

  • Full tier: a change to forge.json, package.json, scripts/ or src/kernel/ runs every test, map or not. I also added the lockfile, bunfig.toml and tsconfig.json, since they change how tests run.
  • Reach line: the log prints what the change reaches, e.g. 3 changed files reach 14 tests; src/web/x.ts reaches none. A changed code file that reaches nothing is a coverage gap.
  • Empty set: if the change reaches no test (a docs-only pull), the fast tier now exits green and says so. Before, an empty file list exited 2 and the check would have gone red.

Decisions to review

  • No map is committed. Recording needs every gate file green, and some aren't in this sandbox: test/claim-link.test.ts fails here without coverage too. Until someone runs bun run check:record on a real host and commits the result, the fast tier logs no scripts/test-impact.json; guessing from imports and names and runs the guess, with the new full-tier rule on top.
  • The full gate on land doesn't write the map. It runs in a throwaway cell, so anything it wrote would be lost. check:record is the only path that writes it into the tree.
  • The reach line is only in the check's log, not on the pull page's checks line, which would mean reading the log on every page render.
  • Not done: switching the runner's own sharding to Bun's --parallel, --shard, --timings, or the --randomize/--rerun-each flake flags. The owner suggested these on the issue, and I'd keep them for a separate change. The map recording already uses --coverage-reporter=lcov one 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.ts and test/check-list.test.ts pass (62 tests). The new tests in test/check-tiers.test.ts cover:

  • a seeded map picking exactly the tests for a one-file change;
  • an unmapped new test picked by the import rule;
  • a kernel, manifest or script change running the full tier;
  • the coverage gap line;
  • lcov parsing and rejecting a bad map.

I also ran --record on 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, then bun scripts/test-shards.ts --tier fast --diff main..HEAD, and read the first lines of the output.

🤖 Generated with Claude Code

Closes #1279

2 earlier comments · 1 event
commented

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.ts imports src/app.ts and src/http/server.ts and 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. --record runs that probe under coverage first. A test executes a file only if it ran a line of it the probe did not (lcovHits and executedFiles in scripts/impact.ts). If the probe is red, the times table is written and the map is left as it was.
  • Plan line. planLine in src/checks/tiers.ts now says how the set was chosen: fast tier, N of 195 files for M changed, by coverage (expected …), by coverage, K by guess when the guess added tests, by guess with no map, and full: <file> changed when 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.ts is the only page executed.

Tests (test/check-tiers.test.ts)

  • A change to src/web/pages/board.ts picks only the test that executed it, and the line reads fast 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 lcovFiles test 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 (EPERM on listen), so the gate is red and recording refuses. To finish: on a machine where the gate is green, run bun run check:record and commit scripts/test-impact.json alongside test-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

Changes requested — before the latest push

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.

commented

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.json holds 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 with EPERM. TCP binds work there, but the server needs the socket. Every one of the 149 failed on that error alone, so bun run check:record stopped at the first file. Until a full bun run check:record runs on a machine that can bind sockets, those 149 are still guessed. The plan line counts them. Replaying an earlier commit to src/web/studio/ gave fast 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. The by coverage line will show on later pulls that touch only src/, not on this one.
  • The slow nested test is gone from the gate. check-tiers.test.ts no longer spawns bun test --coverage with a 30s timeout. Recording now checks the baseline itself: it refuses a baseline that did not load every page under src/web/pages/, using a new function, baselineGaps in scripts/impact.ts. The gate tests that rule on plain data in milliseconds.
  • test-times.json is unchanged. I didn't record times in the sandbox, so the table still comes from the reference machine. check-tiers.test.ts is 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

commented

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

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs