From de2d21a8abd786ef3d63a6818eda3cad844ea46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Fri, 6 Nov 2026 13:46:15 +0000 Subject: [PATCH] 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 --- packages/cli/src/commands/check.test.ts | 22 +++++++++++- packages/cli/src/telemetry/events.test.ts | 44 +++++++++++++++++++++++ packages/cli/src/telemetry/events.ts | 7 ++++ packages/cli/src/utils/checkBrowser.ts | 14 +++++++- packages/cli/src/utils/checkPipeline.ts | 4 ++- packages/cli/src/utils/checkTypes.ts | 7 ++++ 6 files changed, 95 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/check.test.ts b/packages/cli/src/commands/check.test.ts index 5b43dfd717..724f2b5a89 100644 --- a/packages/cli/src/commands/check.test.ts +++ b/packages/cli/src/commands/check.test.ts @@ -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()] : [], diff --git a/packages/cli/src/telemetry/events.test.ts b/packages/cli/src/telemetry/events.test.ts index 461e2e7c21..602d860e70 100644 --- a/packages/cli/src/telemetry/events.test.ts +++ b/packages/cli/src/telemetry/events.test.ts @@ -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, diff --git a/packages/cli/src/telemetry/events.ts b/packages/cli/src/telemetry/events.ts index 9ad85e492b..bd967366f1 100644 --- a/packages/cli/src/telemetry/events.ts +++ b/packages/cli/src/telemetry/events.ts @@ -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), }); } diff --git a/packages/cli/src/utils/checkBrowser.ts b/packages/cli/src/utils/checkBrowser.ts index 42566682f2..549bf0fa93 100644 --- a/packages/cli/src/utils/checkBrowser.ts +++ b/packages/cli/src/utils/checkBrowser.ts @@ -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 { 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 { 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( diff --git a/packages/cli/src/utils/checkPipeline.ts b/packages/cli/src/utils/checkPipeline.ts index fc4044b48b..1c79516b2d 100644 --- a/packages/cli/src/utils/checkPipeline.ts +++ b/packages/cli/src/utils/checkPipeline.ts @@ -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); diff --git a/packages/cli/src/utils/checkTypes.ts b/packages/cli/src/utils/checkTypes.ts index 17cf1b4ddb..92c2823c24 100644 --- a/packages/cli/src/utils/checkTypes.ts +++ b/packages/cli/src/utils/checkTypes.ts @@ -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[];