Skip to content

Commit be6bacf

Browse files
committed
feat(cli): check_report names the finding that stopped the check
1 parent 6011d9d commit be6bacf

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎packages/cli/src/commands/check.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,6 +2562,9 @@ describe("check pipeline", () => {
25622562
expect(reached?.message).toMatch(
25632563
/^Check reached its --budget of 70 s while running the overlap pass .*Seconds per phase: /,
25642564
);
2565+
expect(trackCheckReport).toHaveBeenCalledWith(
2566+
expect.objectContaining({ ok: false, stopCode: "check_budget_reached" }),
2567+
);
25652568
expect(report.ok).toBe(false);
25662569
expect(report.layout.findings.some((finding) => finding.code === "container_overflow")).toBe(
25672570
true,
@@ -3626,6 +3629,7 @@ describe("check report telemetry", () => {
36263629
}),
36273630
);
36283631
expect(report.contrast.errorCount).toBe(1);
3632+
expect(trackCheckReport.mock.calls[0]?.[0].stopCode).toBeUndefined();
36293633
});
36303634

36313635
it("reports zero browser samples and timings after a lint short circuit", async () => {

‎packages/cli/src/telemetry/events.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,46 @@ describe("trackCheckReport", () => {
167167
});
168168
});
169169

170+
it("names the finding that stopped the check, and omits it when none did", () => {
171+
const props = {
172+
contrastGate: false,
173+
motionGate: false,
174+
captionZoneGate: false,
175+
frameCheckGate: false,
176+
snapshotsGate: false,
177+
lintErrors: 0,
178+
lintWarnings: 0,
179+
runtimeErrors: 1,
180+
runtimeWarnings: 0,
181+
layoutErrors: 0,
182+
layoutWarnings: 0,
183+
motionErrors: 0,
184+
motionWarnings: 0,
185+
contrastErrors: 0,
186+
contrastWarnings: 0,
187+
craftWarnings: 0,
188+
launchSettleMs: 0,
189+
renderReadyTimedOut: false,
190+
seekLoopMs: 0,
191+
contrastMs: 0,
192+
gridMs: 0,
193+
craftMs: 0,
194+
overlapMs: 0,
195+
durationSec: 0,
196+
gridPoints: 0,
197+
contrastPoints: 0,
198+
ok: false,
199+
exitCode: 1,
200+
};
201+
trackCheckReport({ ...props, stopCode: "media_copies_unfinished" });
202+
expect(trackEvent).toHaveBeenLastCalledWith(
203+
"check_report",
204+
expect.objectContaining({ stop_code: "media_copies_unfinished" }),
205+
);
206+
trackCheckReport(props);
207+
expect(trackEvent.mock.calls.at(-1)?.[1]).not.toHaveProperty("stop_code");
208+
});
209+
170210
it("omits run_id when no run ID is provided", () => {
171211
trackCheckReport({
172212
contrastGate: false,

‎packages/cli/src/telemetry/events.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,8 @@ export function trackCheckReport(props: {
11931193
contrastPoints: number;
11941194
ok: boolean;
11951195
exitCode: number;
1196+
/** The code of the finding that stopped the check, one of a closed set (checkPipeline's STOP_CODES). */
1197+
stopCode?: string;
11961198
runId?: string;
11971199
}): void {
11981200
trackEvent("check_report", {
@@ -1224,6 +1226,7 @@ export function trackCheckReport(props: {
12241226
contrast_points: props.contrastPoints,
12251227
ok: props.ok,
12261228
exit_code: props.exitCode,
1229+
...(props.stopCode && { stop_code: props.stopCode }),
12271230
...runIdField(props.runId),
12281231
});
12291232
}

‎packages/cli/src/utils/checkPipeline.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,7 @@ function buildReport(
21302130
contrastPoints: browser.contrastChecked,
21312131
ok: report.ok,
21322132
exitCode: checkExitCode(report),
2133+
stopCode: browser.runtimeFindings.find((finding) => STOP_CODES.has(finding.code))?.code,
21332134
runId: getRunId(),
21342135
});
21352136
return filterComponentReport(report, options);
@@ -2264,6 +2265,13 @@ function emptyBrowserResult(): CheckBrowserResult {
22642265
};
22652266
}
22662267

2268+
/** The codes `runtimeFailure` gives a finding that ends the browser check early; `check_report` sends the first one. */
2269+
const STOP_CODES: ReadonlySet<string> = new Set([
2270+
"media_copies_unfinished",
2271+
"check_budget_reached",
2272+
"check_runtime_failure",
2273+
]);
2274+
22672275
function runtimeFailure(error: unknown, code?: string): CheckFinding {
22682276
return findingAtRoot(
22692277
code ??

0 commit comments

Comments
 (0)