feat(report): merge finished shard reports

Merged
MI
4d ago
+1639-76

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

  1. Read each shard's report.json and prefer matching folded rerun history (readReport always throws; readHistory returns 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 new Report1Document with the defaults older rows need.
  2. 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.
  3. Merge rows in three steps: checkShardRows for input consistency, mergeSetups, and mergeTests.
    • 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.
  4. Derive the verdict. A fresh shard keeps its own exit code, so a --max-failures or --max-duration stop stays exit 1. Only a test still owed in a folded rerun history makes the merged run exit 130. statusOf moves to report/build.ts, and one named rule keeps a merge blocked only when every non-passing shard was blocked.
  5. Publish atomically (publishMerged). Artifacts are copied into shard-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, not mkdtemp's 0700.
  6. Load finished-run reporters from the project config and call finishReporters directly. --reporter accepts json, junit and markdown; list, dot and line need live events and are refused there. With --config in 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.
  7. 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 42038589e through the built CLI and passes on this head, as integration tests in merge-reports.test.ts:

    Case42038589ethis head
    --max-duration stop with a test runningmerged exit 130, interruptedexit 1, failed
    --workers 2 --max-failures 1 with a slow test in another filemerged exit 130, interruptedexit 1, failed
    one shard with no commitshard 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 metadatano warningwarns
    merged directory mode40700same as a shard's (40755)
    --config ci/publish.config.mjs project root<project>/ci<project>
    backticked path on a trace pageresults/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 check passed after merging main.