Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/cli/src/commands/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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()] : [],
Expand Down
44 changes: 44 additions & 0 deletions packages/cli/src/telemetry/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/telemetry/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -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),
});
}
Expand Down
14 changes: 13 additions & 1 deletion packages/cli/src/utils/checkBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -245,6 +245,7 @@ export async function preResolveHostileMediaProxies(
html: string,
autoProxyOverride?: boolean,
budgetMs?: number,
record?: (facts: MediaCopyFacts) => void,
): Promise<ProxyPreResolution> {
const none: ProxyPreResolution = {
findings: [],
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 } : {}));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocker: when the copy wait throws CheckCopiesUnfinishedError, checkPipeline.ts:1750 builds skipped: Object.keys(found).length === 0 from the partial. found is now { mediaCopies }, so browserSkipped becomes false even though Chrome never launched. The human report then drops the "Browser session never ran — … empty placeholders, not a clean pass" warning (commands/check.ts:688), and the JSON report and artifact metadata show browserSkipped: false over empty layout/motion/contrast sections.

Fix: carry mediaCopies outside keepPartial, or have line 1750 ignore mediaCopies when deciding skipped. Then add a check.test.ts case where runBrowserCheck reports copy facts and then throws CheckCopiesUnfinishedError, asserting browserSkipped === true and that copies_* are sent.

const {
findings: drafts,
failedPaths,
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/utils/checkPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/utils/checkTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
Loading