feat(cli): check_report counts the browser-playable copies a check waited for (#7316)

* feat(cli): check_report counts the browser-playable copies a check waited for

* style(cli): shorten the copy facts comment under the line limit

* fix(cli): a check stopped by the copy wait stays browserSkipped; count only abort-caused unfinished

* style(cli): format the copy facts tests
This commit is contained in:
Miguel Ángel
2026-11-06 13:46:15 +00:00
committed by GitHub
parent 410a516cee
commit de2d21a8ab
6 changed files with 95 additions and 3 deletions
+21 -1
View File
@@ -16,7 +16,11 @@ import { contrastRatio, parseColorRGBA } from "./contrast-bg.js";
import { createCheckCommand, parseCheckRange } from "./check.js";
import { assertKnownFlags } from "../utils/reject-unknown-flags.js";
import { readConfig } from "../telemetry/config.js";
import { CheckDeadlineError, CheckStoppedError } from "../utils/checkDeadline.js";
import {
CheckCopiesUnfinishedError,
CheckDeadlineError,
CheckStoppedError,
} from "../utils/checkDeadline.js";
import { trackCommandFailures } from "../utils/command-failure-tracking.js";
import type { CommandDef } from "citty";
@@ -3612,6 +3616,22 @@ describe("check report telemetry", () => {
expect(report.ok).toBe(true);
});
it("a check stopped by the copy wait still sends the copy facts and stays browserSkipped", async () => {
const { deps } = dependencies(fakeDriver());
deps.runBrowserCheck = async (_project, _options, _motion, deadline) => {
deadline?.keepPartial(() => ({
mediaCopies: { total: 47, waitedMs: 120_000, unfinished: 12 },
}));
throw new CheckCopiesUnfinishedError(120_000, ["a.mp4 40%"]);
};
const report = await runCheckPipeline(PROJECT, DEFAULT_CHECK_OPTIONS, deps);
expect(report.browserSkipped).toBe(true);
expect(trackCheckReport).toHaveBeenCalledWith(
expect.objectContaining({ mediaCopies: { total: 47, waitedMs: 120_000, unfinished: 12 } }),
);
});
it("reports one failing contrast run with its section error count", async () => {
const collectContrast = vi.fn(async (time: number) => ({
entries: time === 0.5 ? [contrastEntry()] : [],
+44
View File
@@ -207,6 +207,50 @@ describe("trackCheckReport", () => {
expect(trackEvent.mock.calls.at(-1)?.[1]).not.toHaveProperty("stop_code");
});
it("sends what making browser-playable copies cost as counts and milliseconds, and omits it without videos", () => {
const props = {
contrastGate: false,
motionGate: false,
captionZoneGate: false,
frameCheckGate: false,
snapshotsGate: false,
lintErrors: 0,
lintWarnings: 0,
runtimeErrors: 0,
runtimeWarnings: 0,
layoutErrors: 0,
layoutWarnings: 0,
motionErrors: 0,
motionWarnings: 0,
contrastErrors: 0,
contrastWarnings: 0,
craftWarnings: 0,
launchSettleMs: 0,
renderReadyTimedOut: false,
seekLoopMs: 0,
contrastMs: 0,
gridMs: 0,
craftMs: 0,
overlapMs: 0,
durationSec: 0,
gridPoints: 0,
contrastPoints: 0,
ok: true,
exitCode: 0,
};
trackCheckReport({ ...props, mediaCopies: { total: 47, waitedMs: 120_000, unfinished: 12 } });
expect(trackEvent).toHaveBeenLastCalledWith(
"check_report",
expect.objectContaining({
copies_total: 47,
copies_waited_ms: 120_000,
copies_unfinished: 12,
}),
);
trackCheckReport(props);
expect(trackEvent.mock.calls.at(-1)?.[1]).not.toHaveProperty("copies_total");
});
it("omits run_id when no run ID is provided", () => {
trackCheckReport({
contrastGate: false,
+7
View File
@@ -1195,6 +1195,8 @@ export function trackCheckReport(props: {
ok: boolean;
exitCode: number;
stopCode?: StopCode;
/** Present when the project had videos Chrome cannot decode: counts and milliseconds only. */
mediaCopies?: { total: number; waitedMs: number; unfinished: number };
runId?: string;
}): void {
trackEvent("check_report", {
@@ -1227,6 +1229,11 @@ export function trackCheckReport(props: {
ok: props.ok,
exit_code: props.exitCode,
...(props.stopCode && { stop_code: props.stopCode }),
...(props.mediaCopies && {
copies_total: props.mediaCopies.total,
copies_waited_ms: props.mediaCopies.waitedMs,
copies_unfinished: props.mediaCopies.unfinished,
}),
...runIdField(props.runId),
});
}
+13 -1
View File
@@ -63,7 +63,7 @@ import {
resolveProxies,
type ProxyProgress,
} from "@hyperframes/studio-server/proxy-transcoder";
import { rectToBbox } from "./checkTypes.js";
import { rectToBbox, type MediaCopyFacts } from "./checkTypes.js";
import type {
AnchoredLayoutIssue,
CheckAnchor,
@@ -245,6 +245,7 @@ export async function preResolveHostileMediaProxies(
html: string,
autoProxyOverride?: boolean,
budgetMs?: number,
record?: (facts: MediaCopyFacts) => void,
): Promise<ProxyPreResolution> {
const none: ProxyPreResolution = {
findings: [],
@@ -333,6 +334,11 @@ export async function preResolveHostileMediaProxies(
const unfinished = sources.flatMap(({ file }, index) =>
results[index]!.status === "rejected" ? [`${file} ${heartbeat.percent(index)}`] : [],
);
record?.({
total,
waitedMs: Date.now() - startedAt,
unfinished: overBudget === undefined ? 0 : unfinished.length,
});
if (overBudget !== undefined && unfinished.length > 0) {
throw new CheckCopiesUnfinishedError(overBudget, unfinished);
}
@@ -439,6 +445,8 @@ export async function runBrowserCheck(
): Promise<CheckBrowserResult> {
const html = await loadCheckHtmlWithDeferredMedia(project.dir);
deadline?.enter("copies");
let mediaCopies: MediaCopyFacts | undefined;
deadline?.keepPartial(() => (mediaCopies ? { mediaCopies } : {}));
const {
findings: drafts,
failedPaths,
@@ -448,6 +456,9 @@ export async function runBrowserCheck(
html,
options.autoProxy,
Math.min(COPY_BUDGET_MS, deadline?.remainingMs() ?? COPY_BUDGET_MS),
(facts) => {
mediaCopies = facts;
},
);
deadline?.enter("launch");
const server = await serveStaticProjectHtml(
@@ -533,6 +544,7 @@ export async function runBrowserCheck(
const unreachable = await networkChangesStillFailing(merged);
return {
...result,
...(mediaCopies && { mediaCopies }),
timings: { ...result.timings, launchSettleMs },
renderReadyTimedOut: session.renderReadyTimedOut,
runtimeFindings: dropFailedProxyEchoes(
+3 -1
View File
@@ -1747,7 +1747,8 @@ export async function runCheckPipeline(
);
} catch (error) {
const found = deadline.partialResult();
browser = { ...emptyBrowserResult(), ...found, skipped: Object.keys(found).length === 0 };
const ran = Object.keys(found).filter((key) => key !== "mediaCopies");
browser = { ...emptyBrowserResult(), ...found, skipped: ran.length === 0 };
browser.runtimeFindings = [...browser.runtimeFindings, runtimeFailure(error)];
}
@@ -2133,6 +2134,7 @@ function buildReport(
stopCode: browser.runtimeFindings
.map((finding) => finding.code)
.find((code): code is StopCode => (STOP_CODES as readonly string[]).includes(code)),
mediaCopies: browser.mediaCopies,
runId: getRunId(),
});
return filterComponentReport(report, options);
+7
View File
@@ -322,7 +322,14 @@ export interface CheckTimings {
overlapMs: number;
}
export interface MediaCopyFacts {
total: number;
waitedMs: number;
unfinished: number;
}
export interface CheckBrowserResult {
mediaCopies?: MediaCopyFacts;
duration: number;
layoutSamples: number[];
transitionSamples: number[];