feat(report): merge finished shard reports
What
e2e merge-reports <directories...> --output <dir> turns a complete set of shard outputs into one report with working trace links. It runs finished-run reporters once and gives --last-failed a report for the whole matrix.
Why
A CI matrix produces separate reports. The final job needs one verdict and enough evidence to see what failed and rerun it.
How it works
- Read each shard's
report.jsonand prefer matching folded rerun history (readReportalways throws;readHistoryreturns nothing for a missing or stale file). Ajv and ajv-formats move to runtime dependencies at their existing versions, so the installed command can validate inputs against the shipped schema. The validated wire document is normalized into a newReport1Documentwith the defaults older rows need. - Check the shards before merging. Every shard index must be present, and project, runner version, targets and their environments, and test and agent selection must match.
- Two different recorded commits are refused. A shard that recorded no commit (a git call that timed out) only warns, and the merged run keeps the commit the others recorded.
- On a literal loopback host (
127.0.0.1,[::1]) with the same config digest, a target's origin may differ only in its port, so free-port apps (http://127.0.0.1:0) merge. - A different engine version or capability list for a target warns. Different config digests warn. Different repeat counts are refused when fresh shards show them.
- Merge rows in three steps:
checkShardRowsfor input consistency,mergeSetups, andmergeTests.- Each shard gets a named state per test (
owner,other-shard,filtered-out). An inconsistent selection names each shard's state in the error. - A shared setup counts once, keeps each attempt with its shard index, and takes the worst verdict.
- Each shard gets a named state per test (
- Derive the verdict. A fresh shard keeps its own exit code, so a
--max-failuresor--max-durationstop stays exit 1. Only a test still owed in a folded rerun history makes the merged run exit 130.statusOfmoves toreport/build.ts, and one named rule keeps a mergeblockedonly when every non-passing shard was blocked. - Publish atomically (
publishMerged). Artifacts are copied intoshard-N/paths that the merge already wrote on each attempt, and their recorded sizes and digests are checked. Trace pages are regenerated from the recorded attempts and print the path each file will have after publishing. The output directory gets an ordinary mode, notmkdtemp's 0700. - Load finished-run reporters from the project config and call
finishReportersdirectly.--reporteracceptsjson,junitandmarkdown;list,dotandlineneed live events and are refused there. With--configin a subdirectory, reporters get the nearest default e2e config at or above it as the project root, so source links point at the tests. The merge job can omit test credentials (resolveAvailableSecrets) and still redacts the secrets it has. - A missing screenshot file is still marked
redaction: 'incomplete'when the report is written (report/build.ts). #2311 moves that fix to where the record is created; once it merges, this patch goes.
Not in this PR: combined run.changes and run.filters on the merged run. Each shard's filter counts cover only its slice, so they need a combining rule first; each shard's record stays in the e2e.merge extension.
Issue
Builds on #2151. Review fixes for kdy1's and okwasniewski's reviews; artifact record fix split into #2311.
Verified
-
Each of kdy1's findings reproduces on the old head
42038589ethrough the built CLI and passes on this head, as integration tests inmerge-reports.test.ts:Case 42038589ethis head --max-durationstop with a test runningmerged exit 130, interruptedexit 1, failed--workers 2 --max-failures 1with a slow test in another filemerged exit 130, interruptedexit 1, failedone shard with no commit shard 2 has a different commit, exit 2merges, warns two shards on http://127.0.0.1:0shard 2 has different targets, exit 2merges; a different fixed port still refused different engine metadata no warning warns merged directory mode 40700same as a shard's ( 40755)--config ci/publish.config.mjsproject root<project>/ci<project>backticked path on a trace page results/shard-1/...merged/results/shard-1/... -
merge-reports.test.ts: 22 passed. Reporter, port and merge suites (8 files): 65 passed. e2e unit: 4959 passed, 2 skipped. -
pnpm checkpassed after mergingmain.