feat(runner): start the tests a change is likeliest to break first

KD
22d ago
+1154-166
  • A test filter can score the tests it keeps: TestFilterResult.relevance maps test ids to a number from 0 to 1. With --changed-since, each target starts the files of the likeliest tests first, in bands at 75%, 50%, and 25%. Targets go by the band of their best file, ties in config order.
  • Inside a band the existing longest-first order still decides: with more than one worker, the file the timings history (#1639) holds longest starts first, and a file with no time starts before the timed ones. docs/filters.mdx, docs/reference/config.mdx, and docs/ci.mdx say how it combines with the bands.
  • decisionFilter() scores every test it hands back: 1 for a test whose file, setup file, or stored screenshots changed, the model's answer for one it judged: the higher of the test's rating and its setup's, where a rating the model did not give counts as 0.5. It asks the model nothing new.
  • A filter that fails can still score. The error it throws may carry relevance, which the run checks like a result's, and the failure still warns, leaves nothing out, and records outcome: failed. decisionFilter() puts the scores the change alone gives (1 for a test the change touches, 0.5 for the rest) on the error it throws when every call fails, so a run with no key, or with the model down, still starts the touched tests first.
  • The run prints ranked 7 of 12 tests by relevance, likeliest first when the scores put tests in more than one band. e2e list says nothing, since it starts nothing.
  • @e2e-dev/decision now needs e2e >=0.23.1. An older runner rejects the unknown relevance key and drops the whole filter, as the main column below shows.

This shortens the time to the first failure: --max-failures, maxDuration, Ctrl-C, and CI with its default single worker, where longest-first never applied. It does not shorten a run that finishes whole. With several workers it can lengthen one, since a likely short file now starts before an unlikely long one.

The sort key is the file's band (its likeliest test), then its time in the timings history (untimed first), then collection order. A target ranks by its best file, ties in config order. scheduler.ts is unchanged: it already drains targets and files in plan order, and scheduler.test.ts pins that. The report lists tests in the same order whatever starts first, and the report format is unchanged.

Verified

Ran it locally: yes

  • Surface: the built CLI on a scratch project with @e2e-dev/web (real Chromium) and a file-backed config whose local filter scores tests, main (0c1b3572) against this branch. The filter needs no model.
  • pnpm bench:ab --suite testbed -- tests/forms.e2e.ts, a run with no scores (4 pairs): every test ran the same steps with the same outcome on both builds, every counter matched, and the timings were the same (wall +1.3%, interval -2.0% to +1.7%). It ran before the last commit, which changes only what a failed filter leaves.
  • Not verified: the real Jev model, since there is no AI Gateway key here. The scripted-model tests cover the scores, and filter-runner.test.ts runs the real list on the decision filter's result. The band edges (75%, 50%, 25%) are my estimate until real scores are seen. The peer floor assumes the next release is 0.23.1.

e2e run --changed-since main --workers 1 --max-failures 1 on three tests: alpha and beta sleep 3 s, gamma fails at once and is collected last. The filter scores gamma 1.

mainthis branch
filter linewarning: likeliest returned an invalid result ... unknown key "relevance"ranked 1 of 3 tests by relevance, likeliest first
start orderalpha, beta, gammagamma
first failure at+6.5 s+0.3 s
alpha, betapassed, 3.3 s and 3.1 sskipped, failure-limit
wall time7.8 s1.2 s
main
ℹ judging 2 files changed since 60ed46c
ℹ warning: likeliest returned an invalid result, so it leaves nothing out: unknown key "relevance": a filter returns { exclude: { [test.id]: reason }, note? }, and every test it doesn't name runs
   ✓ |web| tests/alpha.e2e.ts > alpha 3.32s
   ✓ |web| tests/beta.e2e.ts > beta 3.06s
   × |web| tests/gamma.e2e.ts > gamma 131ms
stopped after 1 failure (--max-failures 1): the running tests end as interrupted, the rest are skipped

this branch
ℹ judging 2 files changed since 60ed46c
ℹ likeliest kept all 3 tests
ℹ ranked 1 of 3 tests by relevance, likeliest first
   × |web| tests/gamma.e2e.ts > gamma 343ms
   ↓ |web| tests/alpha.e2e.ts > alpha [run stopped after 1 failure (--max-failures 1)]
   ↓ |web| tests/beta.e2e.ts > beta [run stopped after 1 failure (--max-failures 1)]

e2e run --changed-since main --workers 1 --max-failures 1 with the real decisionFilter() on typesafe-ai/jev and no AI Gateway key, so every model call fails. The tests are the same three, and the change edits gamma's test file, so the change touches it. "Before" is this PR's previous head (d2c2217e), which dropped the scores of a failed filter.

beforethis branch
filter lineswarning: decision failed, so it leaves nothing out: AI Gateway authentication failed: No authentication provided.the same warning, then ranked 3 of 3 tests by relevance, likeliest first
run.filtersoutcome: failedoutcome: failed, same note
start orderalpha, beta, gammagamma
first failure at+6.5 s+0.3 s
alpha, betapassed, 3.3 s and 3.1 sskipped, failure-limit
wall time6.8 s0.6 s

e2e list with the same filter prints the warning and the three tests, and no ranking line, as before.

The same failure on the testbed's own config, which runs decisionFilter() on Jev: e2e run --changed-since HEAD --workers 1 tests/forms.e2e.ts tests/todos.e2e.ts with no key and an uncommitted comment added to todos.e2e.ts (reverted after), so the change touches that file. forms is collected first.

before (d2c2217e)this branch
filter linesthe decision failed warningthe same warning, then ranked 11 of 11 tests by relevance, likeliest first
first test startedfills, clears, and submits a profile (forms)adds todos with the button and the keyboard (todos)
the 7 todos tests started5th to 11th1st to 7th
result11 passed11 passed

e2e run --changed-since main --workers 2 right after a run that recorded the timings, on four tests: a 1 s, b 3 s, c 4 s, d 1 s. The filter scores d 0.9 and c 0.3. Both builds read the same recorded times. This table was taken before the timings history (#1639) landed on main.

mainthis branch
start orderb, c (together), a, dc, d (together), b, a
whylongest first, since main drops the scoresd is in the top band and c in a lower one, then b goes before a by time
wall time6.2 s6.2 s

After rebasing onto the timings history, the same four tests on this branch (a first run wrote timings.json, then --changed-since main --workers 2) start c, d, b, a again, in 5.7 s.

Two integration tests pin the wiring. In test-filters.test.ts, a filter that throws with scores still starts the failing test first under --max-failures 1, and its warning and outcome: failed stay. In parallel-workers.test.ts, a run with one worker ignores the timings history and a run with two workers uses it; that test fails when the runWorkers > 1 gate is removed or always on.

🤖 Generated with Claude Code