fix(run): keep --last-failed reruns honest: failure-limit skips, carried debts, kept evidence
Partial --last-failed reruns could go green on tests that never ran, forget a failed hook, and destroy the evidence the GitHub comment links to.
-
failure-limit skips rerun.
failure-limitjoins the undelivered skip causes (packages/e2e/src/run/last-run.ts). Before this,e2e run --max-failures 1 || e2e run --last-failedreran only the failed test and exited 0. -
Owed tests are carried. A
--last-failedrerun's report gets a new optionalrun.carriedfield (report-v1.schema.json, valid fixture,sdk-types.ts). It holds:- owed results the rerun did not run: left out by
--grep,--tag,--target,--agent, or a positional; - the serial groups those results' attempts live on;
- unresolved
beforeAll/afterAllfailures in their scope.
lastFailedIdsselects carried tests, so a test stays owed across consecutive partial reruns until one runs it. A hook failure resolves once a rerun runs any test in its scope without the hook failing. The rerun's own exit code and summary still count only what it ran. - owed results the rerun did not run: left out by
-
The fold stays red.
foldLastRun(packages/github/src/merge.ts) shows carried rows in place of filtered ones and reads the previous run's carried rows as history. It appends carried hook errors and turns the page red while a carried test or hook failure is owed. A carried test the run before interrupted reached no verdict (#713), so it leaves the outcome alone and the page reads ⏹️, not red; the next--last-failedstill runs it. Before,...current.rundropped the previous run's errors. -
Evidence survives. The rerun no longer wipes
artifacts/:- it prunes the tree to the files the report it reruns names (
pruneArtifacts,reportArtifactPaths); - it claims a fresh
artifacts/rerun-<n>/(claimRerunDir, exclusive mkdir, numbered past any existing) and files its attempts there viarerunDiron the worker bootstrap; - no rerun attempt can overwrite
attempt-0of the run it folds.
A full run still clears everything and keeps the same paths.
- it prunes the tree to the files the report it reruns names (
flowchart LR
R0[run: report 0] -->|--last-failed --grep B| R1[rerun-1: B ran, A carried + HOOK_FAILED]
R1 -->|--last-failed| R2[rerun-2: A runs again]
R0 -. artifacts kept .-> R1
R1 -. artifacts kept .-> R2
Docs: reference/cli.mdx (--last-failed, --output), reference/config.mdx, reference/reporters.mdx, ci.mdx (the rerun no longer empties artifacts/, so one upload covers both steps), github.mdx, debugging.mdx, skills/e2e/references/running.md.
Review findings fixed before opening (fresh-context reviewer):
--target/--agentleft no row, so owed tests on unselected targets or agents were dropped. They are now carried while the test is collected and the target still exists.- A carried hook stayed carried after its scope reran and passed. It now resolves.
- A carried
failure-limitskip left the fold green. Now anything carried turns the page red. - An unneeded setup has no report row, so its failed
afterAlldebt was dropped. Existence is now checked against the run's collected test ids (Devin thread).
Verified
Ran it locally: yes
- Scratch project
/tmp/oskar-fix-rerun-integrity(rebuilt as/tmp/oskar-724-reprofor the rebase) with the real built CLI (node packages/e2e/dist/cli/bin.js). Anapiproject covers D7. Awebproject (trace: 'on',github()reporter, fakedGITHUB_ACTIONSenv writing the job summary) has anafterAllthat throws in A and a fixable B with screenshots. - Each rerun's fold is
foldLastRun(report, previous). The "fold links" column re-hashes every artifact the folded page links and checks it against the report'ssha256.
| Scenario | main | this branch |
|---|---|---|
D7: run --max-failures 1, then FIX_T1=1 run --last-failed | exit 0, 1 test ran, T2/T3 never ran | exit 1, all 3 ran (T2, T3 fail) |
D7b: same, then --last-failed --grep T1, then --last-failed | exit 0, then NO_TESTS exit 2 | exit 0 with T2, T3 in run.carried, then exit 1 running T2, T3 |
CI recipe run || FIX_B=1 run --last-failed: fold links | 4 ok, 4 sha mismatch (overwritten), 2 missing (deleted) | 10 ok |
| CI recipe: first-run files after the rerun | 4 changed, 2 gone | unchanged; rerun files under rerun-1/ |
D6: run, then FIX_B=1 run --last-failed --grep B: job summary | 🟢 e2e: 1 flaky, 1 passed, HOOK_FAILED lost, A's screenshot and trace gone | 🔴 e2e: 1 flaky, 1 passed + HOOK_FAILED (afterAll), all 10 links ok |
D6: next --last-failed (hook still broken) | NO_TESTS, exit 2 | runs A, HOOK_FAILED, exit 1 |
D6: FIX_A=1 run --last-failed | NO_TESTS, exit 2 | runs A, exit 0, nothing carried |
Uncollected: run, break t2's import, FIX_T1=1 run --last-failed tests/t1.e2e.ts, fix t2, run --last-failed | (this PR before c4b0c69d) T2 dropped from run.carried, debt lost | T2 carried as failed, then the next --last-failed runs T2 |
Interrupted carry (#713): SIGINT a run mid T4, then FIX_T1=1 run --last-failed --grep T1, then run --last-failed | n/a | rerun exit 0, T4 in run.carried as interrupted, fold ### ⏹️ e2e: 1 interrupted, 1 flaky (status passed, exit 0), next --last-failed runs T4 |
New regression tests:
- unit:
tests/unit/last-run.test.ts,tests/unit/rerun-artifacts.test.ts, the carried constraints intests/unit/schema-fixtures.test.ts, and githubtests/unit/merge.test.ts; - integration:
runner-lifecycle.test.ts(the failure limit and a filter carried across reruns, a hook carried until its scope runs, a test of a file a narrowed rerun could not import still carried) andoutput.test.ts(evidence kept byte for byte,rerun-1/, thenrerun-2/, and a full run back at the root).
Re-run on the rebase onto main 7f9ee108 (after #713, #741, #727): every row above matches.
The new fold tests fail against main's merge.ts. Locally green: pnpm check, e2e (unit and integration), github, testbed, web-benchmark.