feat(reporters): add the ctrf reporter, writing the run in the Common Test Report Format

Merged
MI
1d ago
+2461-45

What

  • A new built-in reporter, ctrf, writes the run as <output>/ctrf.json in the Common Test Report Format 0.3.0. Any CTRF tool can then read e2e results: test report actions, Slack and Teams notifiers, dashboards.
  • Turn it on as an id or a factory, like junit:
import { ctrf, list } from 'e2e/reporters';

export default defineConfig({ targets, reporters: [list(), ctrf({ outputFile: 'reports/ctrf.json' })] });
npx e2e run --reporter list,ctrf

Why

junit.xml is what CI tools read today, but JUnit XML has no place for most of what e2e records:

  • a flaky pass is a text note;
  • earlier attempts and steps are dropped;
  • an interrupted test reads as skipped;
  • run-level errors become a made-up run suite.

CTRF has fields for each of these: flaky, retryAttempts, steps, rawStatus, results.errors, and extra for data it has no field for. Converting junit.xml to CTRF would carry over every loss, so the reporter reads the report-1 document directly.

How it works

flowchart LR
  A["a test's attempts<br/>(a serial member's from its group)"] --> V["outcome().verdict<br/>last attempt that reached the verdict"]
  V --> B["before it, ones the test ran<br/>→ retryAttempts, retries"]
  V --> R["the verdict attempt<br/>→ the test object's timing, message, steps, attachments<br/>(none when the test was skipped there)"]
  V --> C["after it, ones the test ran<br/>→ extra.cutAttempts"]
  1. The reporter (packages/e2e/src/report/ctrf.ts:449). ctrf() returns its file from reportFiles, behind the same run.reportPath guard as junit. It reads the report-1 document only: no test source and no app output. The one CI variable it reads is CI_PROJECT_DIR, through junit's attachmentBase.

    • Every free text it copies from the report goes through run.redact, then sanitizeRecordedText, then run.redact again (ctrf.ts:375). Taking out a terminal control can join the halves of a value.
    • An attachment link the redaction would change is left out, not written with a marker in it (ctrf.ts:200).
  2. One CTRF test per junit test case, outside the run suite (renderCtrfReport, ctrf.ts:371).

    • listedInCi (packages/e2e/src/report/outcome.ts:88) is now the selection rule junit and ctrf share (junit.ts:252).
    • name is file > title path [target], plus the agent when it is not default. The GitHub test reporter keys its history on name, and two files can share a title.
    • testId is the result id, which stays the same across runs. A title that holds > can make two names read alike; testId tells them apart, and the reporters page says so.
    • filePath and line come from the declaration (result.source), so a test declared in a module the test file imports points at that module. suite starts with the test file, and summary.suites counts test files, from suite[0].
    • No top-level runId: CTRF shares it across a run's shards, and run.id is minted per process. The run id stays in extra.
  3. One attempt per test object (representedAttempts, ctrf.ts:286). CTRF says duration, start, message and attachments describe one attempt, and retryAttempts holds only the ones before it. The test stands for outcome().verdict, the last attempt that reached the result's verdict, so a flaky test is its passing retry.

    • The attempts are split at the verdict, then each side keeps the ones the test ran.
    • retryAttempts is the side before, and retries is its length. Both are left out when it is empty.
    • The side after holds retries the run cut, and is counted as extra.cutAttempts.
    • A serial member whose verdict attempt skipped it keeps skipped and stands for that skipped attempt, with no timing or attachments. The attempts it ran before are retryAttempts, and CTRF allows a retry entry to be skipped, so the skipped attempt counts as the final one.
  4. Statuses and errors (ctrf.ts:136).

    • status uses CTRF's words, and rawStatus keeps e2e's word. timed-out is failed. interrupted, and a blocked or cancelled step, are other.
    • A harness failure stays failed, with its category in extra, so a check that reads failed counts still goes red.
    • A failed test with no error of its own (one that vanished before it ran) gets message: "failed", the word junit writes.
    • The test.fail mark in extra is the represented attempt's, so a retry the run cut after it does not drop it.
    • An earlier attempt gets a message and trace only when it failed, timed out or was interrupted (ctrf.ts:247). A serial member that passed would otherwise read its group's error, which is a sibling's.
    • The session named in a trace comes from failedStepOf, the same match junit makes (ctrf.ts:242).
  5. Run-level errors go in results.errors and are never counted as a test (ctrf.ts:415). CTRF 0.3.0 section 6.5 says global errors "MUST NOT be counted as test results". A tool that counts failed tests alone therefore reads as green a run whose only failure is, say, an afterAll error. docs/ci.mdx now says to keep e2e's exit code as the gate.

  6. Serial groups (outcome.ts:170, :200). A member's artifacts sit on its group's attempt. AttemptView gains owned:

    • the artifacts the member's own records name: a step's artifact ids, a step as producer, its failure screenshot and screen;
    • the group's artifacts no member names, such as the video, marked scope: 'serial-group';
    • nothing for a member the attempt never reached.

    owned is a getter on every attempt (outcome.ts:117, :142), and ownersOf works out the owners one time per group attempt. AttemptView also gains the attempt id, startedAt and ran. junit, markdown and the HTML reporter read none of these, so their output does not change.

  7. Attachments (ctrf.ts:188). The path is the first of these that exists:

    • the artifact's hosted url;
    • its store's http(s) ref;
    • its file, relative to $CI_PROJECT_DIR when that is set, else to the project root (attachmentBase, now exported from junit.ts).

    Downloads and artifacts with nowhere to open them are left out. Logs, such as the screen at a failure, are attached like screenshots. A video of a second session a serial member opened with launch() is registered on the group attempt with no step, so it is listed as the group's.

  8. Wiring and docs.

    • The id is in BuiltinReporter (packages/e2e/src/run-types.ts:11), BUILTIN_REPORTERS (report/builtin-id.ts:13) and the factory map (report/builtin.ts), and ctrf and CtrfReporterOptions are exported from e2e/reporters (packages/e2e/src/reporters.ts:13).
    • e2e init and the repository's .gitignore ignore .e2e/ctrf.json.
    • Docs: the reporters, config, CLI and errors reference pages; the CI gate note; telemetry; the Cypress and Playwright migration rows; the skill references and their plugin copies.

The CTRF 0.3.0 schema is vendored under packages/e2e/tests/fixtures/ctrf/, byte for byte from tag v0.3.0 (commit 6cafa1e), with its MIT license. Every rendered document in the tests is validated against it, plus the retries/retryAttempts rules the schema cannot express.

Not in this PR:

  • CI build links. They need CI variables, and GitLab's CI_REPOSITORY_URL carries a job token.
  • The ai field.
  • snippet, because the test source file is not redacted.
  • stdout and stderr, because report-1 keeps no test output.
  • e2e explore findings.

Issue

Internal design and decision record. No GitHub issue.

Verified

Ran it locally: yes

Review fixes at 70dd58b7f. A scratch project whose one-line tests/cart.e2e.ts imports tests/cases.ts, which declares three tests in two describe blocks. On 669fa2962 ctrf.json wrote filePath: tests/cart.e2e.ts with line: 5, a line that file does not have; on 70dd58b7f it writes tests/cases.ts lines 5, 7 and 10, suite still starts with tests/cart.e2e.ts, and summary.suites is 1. The new unit test fails on 669fa2962. pnpm check passes, and so do 149 tests in report-ctrf, report-junit, schema-fixtures, ctrf-reporter, test-source and plain-string-secrets. The testbed run below is from 669fa2962; the review fixes do not change its output, since its tests are declared in their own files.

The built CLI on the testbed (apps/testbed). The serial group in tests/wizard.e2e.ts was run with video on:

$ node node_modules/e2e/dist/cli/bin.js run tests/wizard.e2e.ts --reporter list,junit,ctrf --video on
   ✓ |web| tests/wizard.e2e.ts > workspace wizard > step 1: name the workspace 155ms
   ✓ |web| tests/wizard.e2e.ts > workspace wizard > step 2: pick a plan 66ms
   ✓ |web| tests/wizard.e2e.ts > workspace wizard > step 3: confirm with state from earlier members 45ms

      JUnit  .e2e/junit.xml
       CTRF  .e2e/ctrf.json

In ctrf.json the group's one video (producer: attempt in report.json) is listed under all three tests with scope: serial-group.

A throwaway copy of that group made its second test fail, with --retries 1, and the file was deleted afterwards:

Testctrf.jsonAttachments, each attempt
step 1 (passed both times)passed, retries: 1. The earlier attempt is passed with no messagethe group video (serial-group)
step 2 (failed both times)failed with its message, retries: 1. The earlier attempt is failed with the same messageits failure screen log, its failure screenshot, the group video (serial-group)

The passing test lists neither the failing test's files nor its error.

--reporter ctrf through the CLI (tests/integration/ctrf-reporter.test.ts):

  • One run holds a pass, a flaky retry, a failure, a timeout, a skip, and an afterAll that throws.
    • The run exits 1, and ctrf.json validates against the CTRF 0.3.0 schema.
    • Its counts match junit.xml once JUnit's run suite is set aside: tests = JUnit tests − run-suite cases, and failed = failures + errors − run-suite errors.
    • The HOOK_FAILED error is in results.errors only.
  • --max-duration 1500 stops a running test.
    • CTRF has it as other (rawStatus: interrupted), and JUnit counts it as skipped.
    • RUN_TIMEOUT is a run error.
    • This passed 5 runs out of 5.
  • A run whose app exits before its tests (APP_UNREACHABLE, exit 3) writes no new ctrf.json, as it writes no new report.json or junit.xml (packages/e2e/src/run/runner.ts:792-799). A file from an earlier run stays in place, so the exit code is the signal.
  • With no reporters in the config, no ctrf.json is written. This guard passes on main too, as its title says.

The new tests fail on main. The changed test files were run on fd488ca02:

  • the new integration tests fail there (ctrf is an unknown id, INVALID_CONFIG);
  • the guard passes there by design;
  • the unit file cannot load there, because report/ctrf.ts is new.

Hand-written mutants: 57 of 57 killed by an assertion in tests/unit/report-ctrf.test.ts or tests/unit/report-junit.test.ts. They cover:

  • run errors added to failed;
  • the member artifact rule: every group artifact to every member, shared artifacts dropped or not marked, failure ids, step artifact ids or a step's producer not counted as a member's own, and an unreached member given the group's;
  • the final attempt instead of the verdict, and the represented attempt inside retryAttempts;
  • a member a retry skipped standing for its earlier failed attempt, and a retry the run cut after that skip listed as an earlier attempt;
  • a sibling's error on a passing member's earlier attempt;
  • the trace naming the last failed step's session;
  • retries numbered from 0, and earlier attempts losing their attachments;
  • a member's flaky ignoring a timeout, set without a final pass, or taken from the group's status (in a flaky group and in a failed one);
  • suites counted from results the selection left out, or from filePath instead of the test file;
  • filePath taken from the collected file instead of the declaration, or written without the redaction;
  • a member that skipped itself treated as one the group never reached, and a failed test with no error left without a message;
  • each status mapping;
  • the redaction left out, not repeated after control stripping, dropped from a step's name, actor, code or explanation, a failed test's message or trace, the commit, an attempt id or an attachment's media type, or not passed by the ctrf() factory; a link holding a secret kept, hosted or local; the OS string split before it is redacted;
  • a store ref ahead of a hosted url, any ref used as a URL, downloads kept, an absolute path;
  • the selection rule, in ctrf and in junit;
  • a cut retry dropped from the count, counted when it never reached the member, or its steps, attachments or missing test.fail mark used in place of the represented attempt's.

Cost for the other reporters. A report with one group attempt (100 members, 100 artifacts) and one plain attempt (100 artifacts): renderJunitReport and renderMarkdownReport read an artifact's producer 0 times. renderCtrfReport reads each group artifact's once or twice for the whole group attempt, 200 times here, where every artifact has a step as its producer.

Redaction test. tests/unit/report-ctrf.test.ts plants a value in the free text the file copies from the report, on the test object and on its earlier attempts: names, steps, errors, skip and test.fail reasons, the result and attempt ids, attachment names and media types, links, the branch, the commit, the OS and the tool version. It checks that the raw value is absent and that the output holds exactly 46 redaction markers.

Secret sweep. tests/integration/plain-string-secrets.test.ts now also writes ctrf.json. It searches every file under .e2e for the registered secret, as written and base64-encoded, and finds none. ctrf.json carries <secret:probe> where the title held the secret.

Not captured:

  • A terminal recording. VHS is not installed on this machine. The only terminal change is the CTRF .e2e/ctrf.json row above.
  • A rendered docs screenshot. The docs site builds outside this repo. pnpm docs:check compiles every page.
  • A CTRF consumer. No CTRF tool was run on the output. The GitHub test reporter's insights read a passed test with retries > 0 as flaky (its run-insights.ts), so a serial member the group retried shows there as flaky. The reporters page says so, and flaky itself is set only for a test that failed and then passed.

For maintainers

  • The keys under extra["e2e-inc.e2e"] (cutAttempts, expectedFailure, skipCause, errorCategory, scope, usage, and the step and attachment data) have no schema of their own, and the reporters page names only some of them. Should consumers be able to rely on them, or should the page call them unstable?
  • A terminal recording of the one new summary row was not captured (VHS is not installed here). Waive it, or I record it on another machine.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

🤖 Generated with Claude Code