feat(reporters): add the ctrf reporter, writing the run in the Common Test Report Format
What
- A new built-in reporter,
ctrf, writes the run as<output>/ctrf.jsonin 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
runsuite.
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"]
-
The reporter (
packages/e2e/src/report/ctrf.ts:449).ctrf()returns its file fromreportFiles, behind the samerun.reportPathguard asjunit. It reads the report-1 document only: no test source and no app output. The one CI variable it reads isCI_PROJECT_DIR, throughjunit'sattachmentBase.- Every free text it copies from the report goes through
run.redact, thensanitizeRecordedText, thenrun.redactagain (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).
- Every free text it copies from the report goes through
-
One CTRF test per
junittest case, outside therunsuite (renderCtrfReport,ctrf.ts:371).listedInCi(packages/e2e/src/report/outcome.ts:88) is now the selection rulejunitandctrfshare (junit.ts:252).nameisfile > title path [target], plus the agent when it is notdefault. The GitHub test reporter keys its history onname, and two files can share a title.testIdis the result id, which stays the same across runs. A title that holds>can make two names read alike;testIdtells them apart, and the reporters page says so.filePathandlinecome from the declaration (result.source), so a test declared in a module the test file imports points at that module.suitestarts with the test file, andsummary.suitescounts test files, fromsuite[0].- No top-level
runId: CTRF shares it across a run's shards, andrun.idis minted per process. The run id stays inextra.
-
One attempt per test object (
representedAttempts,ctrf.ts:286). CTRF saysduration,start,messageandattachmentsdescribe one attempt, andretryAttemptsholds only the ones before it. The test stands foroutcome().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.
retryAttemptsis the side before, andretriesis 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
skippedand stands for that skipped attempt, with no timing or attachments. The attempts it ran before areretryAttempts, and CTRF allows a retry entry to beskipped, so the skipped attempt counts as the final one.
-
Statuses and errors (
ctrf.ts:136).statususes CTRF's words, andrawStatuskeeps e2e's word.timed-outisfailed.interrupted, and a blocked or cancelled step, areother.- A harness failure stays
failed, with its category inextra, 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 wordjunitwrites. - The
test.failmark inextrais the represented attempt's, so a retry the run cut after it does not drop it. - An earlier attempt gets a
messageandtraceonly 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 matchjunitmakes (ctrf.ts:242).
-
Run-level errors go in
results.errorsand 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, anafterAllerror.docs/ci.mdxnow says to keep e2e's exit code as the gate. -
Serial groups (
outcome.ts:170,:200). A member's artifacts sit on its group's attempt.AttemptViewgainsowned:- 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.
ownedis a getter on every attempt (outcome.ts:117,:142), andownersOfworks out the owners one time per group attempt.AttemptViewalso gains the attemptid,startedAtandran.junit,markdownand the HTML reporter read none of these, so their output does not change. - the artifacts the member's own records name: a step's artifact ids, a step as
-
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_DIRwhen that is set, else to the project root (attachmentBase, now exported fromjunit.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. - the artifact's hosted
-
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), andctrfandCtrfReporterOptionsare exported frome2e/reporters(packages/e2e/src/reporters.ts:13). e2e initand the repository's.gitignoreignore.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 id is in
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_URLcarries a job token. - The
aifield. snippet, because the test source file is not redacted.- stdout and stderr, because report-1 keeps no test output.
e2e explorefindings.
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:
| Test | ctrf.json | Attachments, each attempt |
|---|---|---|
| step 1 (passed both times) | passed, retries: 1. The earlier attempt is passed with no message | the group video (serial-group) |
| step 2 (failed both times) | failed with its message, retries: 1. The earlier attempt is failed with the same message | its 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
afterAllthat throws.- The run exits 1, and
ctrf.jsonvalidates against the CTRF 0.3.0 schema. - Its counts match
junit.xmlonce JUnit'srunsuite is set aside:tests= JUnit tests − run-suite cases, andfailed= failures + errors − run-suite errors. - The
HOOK_FAILEDerror is inresults.errorsonly.
- The run exits 1, and
--max-duration 1500stops a running test.- CTRF has it as
other(rawStatus: interrupted), and JUnit counts it asskipped. RUN_TIMEOUTis a run error.- This passed 5 runs out of 5.
- CTRF has it as
- A run whose app exits before its tests (
APP_UNREACHABLE, exit 3) writes no newctrf.json, as it writes no newreport.jsonorjunit.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
reportersin the config, noctrf.jsonis written. This guard passes onmaintoo, as its title says.
The new tests fail on main. The changed test files were run on fd488ca02:
- the new integration tests fail there (
ctrfis an unknown id,INVALID_CONFIG); - the guard passes there by design;
- the unit file cannot load there, because
report/ctrf.tsis 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
producernot 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
flakyignoring a timeout, set without a final pass, or taken from the group's status (in a flaky group and in a failed one); suitescounted from results the selection left out, or fromfilePathinstead of the test file;filePathtaken 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
refahead of a hostedurl, anyrefused as a URL, downloads kept, an absolute path; - the selection rule, in
ctrfand injunit; - a cut retry dropped from the count, counted when it never reached the member, or its steps, attachments or missing
test.failmark 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.jsonrow above. - A rendered docs screenshot. The docs site builds outside this repo.
pnpm docs:checkcompiles 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 > 0as flaky (itsrun-insights.ts), so a serial member the group retried shows there as flaky. The reporters page says so, andflakyitself 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/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.
🤖 Generated with Claude Code