feat(report): record the shard, mark other shards' tests, keep reruns folded
What
- A sharded run's report records which shard it was, as
run.shard: { index, total }. - Every row this run's
--shardcut gives another shard carriesskip.otherShard: true, so a reader no longer parses the reason textoutside the shard. That includes an explicitly skipped test assigned to another shard by this run's cut. - A
--last-failedrerun writesreport-with-reruns.jsonbesidereport.json. It holds the first run and every rerun since as one report-1 document, with the same run id asreport.json: the attempts of tests still collected, the first run's shard, and the usage of all the runs added up. - Reporters get that same history as
FinishedRun.lastRun. A second rerun therefore still sees the first run's passes, and it keeps the first run's artifact files on disk. foldLastRunmoves from@e2e-dev/githubintoe2eand is exported from the main entrypoint. The runner's summary count and the fold share one function.@e2e-dev/githubimports the fold, and itse2epeer floor is now>=0.25.0 <1.
Why
This is the report side of merging shard reports (ENG-1239), from the review of the proposal (ENG-1418). Changes 1, 2 and 5 of that review are here. e2e merge-reports itself (changes 3, 4 and 6) is the next PR.
- The rerun is lossy today. A rerun's
report.jsonlists the first run's passes as unselected. Only@e2e-dev/githubrestored them, in memory, by folding the rerun into the one report it selected from. After a second rerun, that report is the first rerun, so the comment showed every test that passed on the first run as not run, and a flaky test lost its first attempt. A shard merge reading the output directory would lose the same passes. - The merge needs to know each report's shard. A report did not record its shard, and the only sign that another shard owned a row was its reason text.
- There were two copies of the tally.
@e2e-dev/githubkept its own copy of the summary count.
How it works
-
applyShardsetsotherShard: trueon both kinds of row the cut gives another shard: an item outside the slice, and an explicit skip that this cut assigns to another shard (packages/e2e/src/collect/select.ts:820and:824).SkipDetailin@e2e-dev/coregains the field (packages/core/src/run/records.ts).describeShardcounts the cut rows by the marker instead of by the reason text. The cut is this run's: with--last-failed --shard, it slices the tests the last run did not pass, and the marks name that cut. Shards that rerun their own failures can cut different sets of tests. -
buildReportwritesrun.shardfrom the run's--shardoption. The runner passes the option only after the config load has validated it (runner.ts:691), so an invalid--shard 3/2never reaches the report. -
The report-1 schema gains
run.shard(index and total, integers from 1) andskip.otherShard(const: true). Both fixtures cover them: the valid one has a shard and a marked row, and the invalid one hasindex: 0andotherShard: false. -
summarizeResults(packages/e2e/src/report/summary.ts) countsrun.summaryfrom the serialized rows.buildReportuses it in place of its count over in-memory records, and so does the fold. -
foldLastRun(packages/e2e/src/report/fold.ts) is the fold frompackages/github/src/merge.ts, with changes forlastRunbeing a fold itself:- a row the run before holds a result for wins over the row the rerun carries for the same test (
rowsById), since a folded row has every attempt and a carried row only the last run's; - a test that was already flaky stays flaky when it passes again;
- a test the rerun never reached (interrupted, or skipped by a failed setup, predecessor, or hook, or a run limit) keeps its earlier verdict (failed, flaky, or passed, with no skip) and the serial group its attempts live on, so a later pass after a failure is flaky.
--last-failedand the fold read one list of those skips (UNDELIVERED_SKIPSinlast-run.ts); - a failed shared setup still widens a plain
--last-failedrerun to every consumer of its session. The fold keeps tests assigned to another shard out of the first shard's totals across all repeats. If one failed, the folded report and GitHub comment show the failure as a run error; - a serial member's result lists no attempts, since they live on its group, even when the test was not serial before;
- a row an older report wrote without
selectedcounts as selected, in the fold and insummarizeResults, the way the page reads it; - the group of a serial member's further
--repeat-eachrepeat folds into the group of the result the plain rerun ran; - attempts are numbered again from 0;
- the shard is the first run's, or none when the first run was not sharded;
usageis the runs' totals added and the larger per-step maximum (addUsage).
@e2e-dev/githubimports the fold frome2e, itsmerge.tsis deleted, and its tests import the fold frome2e. - a row the run before holds a result for wins over the row the rerun carries for the same test (
-
At the start of a rerun, the runner reads
report-with-reruns.jsonwithreadWithReruns(last-run.ts:110, called atrunner.ts:978;e2e list --last-faileddoes not read it). It is used only when it is a report-1 document with the fields the fold reads (the run's project, start, and usage, each result's test, target, agent, and repeat, each serial group's id, repeat, and attempt members) and the same run id asreport.json. After reading history, the runner drops rows for deleted tests, keeping tests in files collection could not read. A file left over from another run, for example beside areport.jsondownloaded from CI, is ignored. Otherwise the history isreport.json, as today. Test selection (lastFailedIds) andrun.carriedstill readreport.json. -
The runner hands that history to reporters as
lastRun(runner.ts:883). The rerun keeps the artifacts bothreport.jsonand the history name (runner.ts:1164). After writing its report, it writesfoldLastRun(report, history)toreport-with-reruns.json(runner.ts:792). A run without--last-failedremoves the file. A failed write is one line on stderr, like the trace pages, never a run error. The next rerun then finds no history with that run id and falls back toreport.json, which is what every rerun does today.
Two limits:
- When a test changes from standalone to a serial member between the runs, its earlier attempts are not in the fold: report-1 lists a serial member's attempts on its group, in a shape a standalone attempt does not fit. Its earlier failure still makes the later pass flaky.
- A failed write of the history file leaves the next rerun with
report.jsonalone, as described in step 7.
The fold is kept in a separate file rather than written into report.json. An older @e2e-dev/github (its peer range allowed >=0.15.0) would fold the rerun into an already folded report and show every attempt twice, and the exit code would no longer match the report.
Issue
Part of ENG-1239. Follows the approved design in ENG-1418.
Verified
Ran locally. The built CLI and the renderer used by the GitHub reporter were checked on the final tree.
| Case | Previous PR head | Current head |
|---|---|---|
| A rerun fails on another shard's test | History exits 1 and has no failure to explain why | History exits 1 and names the failure as a run error |
The same rerun with --repeat-each 2 | The extra repeat counts as a failure of the first shard | Neither repeat counts against the first shard |
Delete failing y, then rerun twice until x passes | History stays failed because it still includes y | History passes and shows x as flaky with all three attempts |
The CLI and output suites also cover a second rerun keeping the first run's passes, a sharded report recording its shard, and history that stays valid when a rerun stops before reaching an earlier failure. The GitHub tests cover a serial failure from another shard that a later rerun filters out.
pnpm checkand the focused CLI, output, rerun, schema, and GitHub reporter suites passed.- The built CLI ran the testbed's todo suite in Chromium. All tests in that file passed.
- The tests caught five deliberate regressions in a separate worktree. Those hid the failure, matched ownership by repeat id, retained the deleted test, retained a foreign serial group, or hid a carried foreign failure.
- The added report error kept a synthetic secret out of the CLI output, folded JSON, and rendered Markdown.