fix(run): keep --last-failed reruns honest: failure-limit skips, carried debts, kept evidence

Merged
OK
2mo ago
+1109-85

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-limit joins the undelivered skip causes (packages/e2e/src/run/last-run.ts). Before this, e2e run --max-failures 1 || e2e run --last-failed reran only the failed test and exited 0.

  • Owed tests are carried. A --last-failed rerun's report gets a new optional run.carried field (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/afterAll failures in their scope.

    lastFailedIds selects 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.

  • 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-failed still runs it. Before, ...current.run dropped 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 via rerunDir on the worker bootstrap;
    • no rerun attempt can overwrite attempt-0 of the run it folds.

    A full run still clears everything and keeps the same paths.

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/--agent left 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-limit skip left the fold green. Now anything carried turns the page red.
  • An unneeded setup has no report row, so its failed afterAll debt 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-repro for the rebase) with the real built CLI (node packages/e2e/dist/cli/bin.js). An api project covers D7. A web project (trace: 'on', github() reporter, faked GITHUB_ACTIONS env writing the job summary) has an afterAll that 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's sha256.
Scenariomainthis branch
D7: run --max-failures 1, then FIX_T1=1 run --last-failedexit 0, 1 test ran, T2/T3 never ranexit 1, all 3 ran (T2, T3 fail)
D7b: same, then --last-failed --grep T1, then --last-failedexit 0, then NO_TESTS exit 2exit 0 with T2, T3 in run.carried, then exit 1 running T2, T3
CI recipe run || FIX_B=1 run --last-failed: fold links4 ok, 4 sha mismatch (overwritten), 2 missing (deleted)10 ok
CI recipe: first-run files after the rerun4 changed, 2 goneunchanged; 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 2runs A, HOOK_FAILED, exit 1
D6: FIX_A=1 run --last-failedNO_TESTS, exit 2runs 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 lostT2 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-failedn/arerun 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 in tests/unit/schema-fixtures.test.ts, and github tests/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) and output.test.ts (evidence kept byte for byte, rerun-1/, then rerun-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.