Skip to content

Commit 021c04e

Browse files
committed
fix(cli): type stop_code as a closed union instead of a comment
1 parent be6bacf commit 021c04e

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { BrowserInstallFacts } from "../browser/installFacts.js";
2+
import type { StopCode } from "../utils/checkPipeline.js";
23
import type { OutputResolutionIssueKind } from "@hyperframes/core";
34
import { redactTelemetryString } from "@hyperframes/core/telemetry-redaction";
45
import type { SubTimelineWaitOutcome } from "@hyperframes/engine";
@@ -1193,8 +1194,7 @@ export function trackCheckReport(props: {
11931194
contrastPoints: number;
11941195
ok: boolean;
11951196
exitCode: number;
1196-
/** The code of the finding that stopped the check, one of a closed set (checkPipeline's STOP_CODES). */
1197-
stopCode?: string;
1197+
stopCode?: StopCode;
11981198
runId?: string;
11991199
}): void {
12001200
trackEvent("check_report", {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,9 @@ 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,
2133+
stopCode: browser.runtimeFindings
2134+
.map((finding) => finding.code)
2135+
.find((code): code is StopCode => (STOP_CODES as readonly string[]).includes(code)),
21342136
runId: getRunId(),
21352137
});
21362138
return filterComponentReport(report, options);
@@ -2265,12 +2267,12 @@ function emptyBrowserResult(): CheckBrowserResult {
22652267
};
22662268
}
22672269

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+
export const STOP_CODES = [
22702271
"media_copies_unfinished",
22712272
"check_budget_reached",
22722273
"check_runtime_failure",
2273-
]);
2274+
] as const;
2275+
export type StopCode = (typeof STOP_CODES)[number];
22742276

22752277
function runtimeFailure(error: unknown, code?: string): CheckFinding {
22762278
return findingAtRoot(

0 commit comments

Comments
 (0)