feat(report): record the shard, mark other shards' tests, keep reruns folded

Merged
MI
6d ago
+1078-282

What

  • A sharded run's report records which shard it was, as run.shard: { index, total }.
  • Every row this run's --shard cut gives another shard carries skip.otherShard: true, so a reader no longer parses the reason text outside the shard. That includes an explicitly skipped test assigned to another shard by this run's cut.
  • A --last-failed rerun writes report-with-reruns.json beside report.json. It holds the first run and every rerun since as one report-1 document, with the same run id as report.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.
  • foldLastRun moves from @e2e-dev/github into e2e and is exported from the main entrypoint. The runner's summary count and the fold share one function. @e2e-dev/github imports the fold, and its e2e peer 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.json lists the first run's passes as unselected. Only @e2e-dev/github restored 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/github kept its own copy of the summary count.

How it works

  1. applyShard sets otherShard: true on 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:820 and :824). SkipDetail in @e2e-dev/core gains the field (packages/core/src/run/records.ts). describeShard counts 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.

  2. buildReport writes run.shard from the run's --shard option. The runner passes the option only after the config load has validated it (runner.ts:691), so an invalid --shard 3/2 never reaches the report.

  3. The report-1 schema gains run.shard (index and total, integers from 1) and skip.otherShard (const: true). Both fixtures cover them: the valid one has a shard and a marked row, and the invalid one has index: 0 and otherShard: false.

  4. summarizeResults (packages/e2e/src/report/summary.ts) counts run.summary from the serialized rows. buildReport uses it in place of its count over in-memory records, and so does the fold.

  5. foldLastRun (packages/e2e/src/report/fold.ts) is the fold from packages/github/src/merge.ts, with changes for lastRun being 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-failed and the fold read one list of those skips (UNDELIVERED_SKIPS in last-run.ts);
    • a failed shared setup still widens a plain --last-failed rerun 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 selected counts as selected, in the fold and in summarizeResults, the way the page reads it;
    • the group of a serial member's further --repeat-each repeat 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;
    • usage is the runs' totals added and the larger per-step maximum (addUsage).

    @e2e-dev/github imports the fold from e2e, its merge.ts is deleted, and its tests import the fold from e2e.

  6. At the start of a rerun, the runner reads report-with-reruns.json with readWithReruns (last-run.ts:110, called at runner.ts:978; e2e list --last-failed does 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 as report.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 a report.json downloaded from CI, is ignored. Otherwise the history is report.json, as today. Test selection (lastFailedIds) and run.carried still read report.json.

  7. The runner hands that history to reporters as lastRun (runner.ts:883). The rerun keeps the artifacts both report.json and the history name (runner.ts:1164). After writing its report, it writes foldLastRun(report, history) to report-with-reruns.json (runner.ts:792). A run without --last-failed removes 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 to report.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.json alone, 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.

CasePrevious PR headCurrent head
A rerun fails on another shard's testHistory exits 1 and has no failure to explain whyHistory exits 1 and names the failure as a run error
The same rerun with --repeat-each 2The extra repeat counts as a failure of the first shardNeither repeat counts against the first shard
Delete failing y, then rerun twice until x passesHistory stays failed because it still includes yHistory 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 check and 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.