Skip to content

Commit a669316

Browse files
fix(cli): --timeout on check and snapshot takes units like 45s (#6521)
* fix(cli): check stops making video copies after 10 minutes, and --timeout takes units The copy phase of check had no overall limit: a source that kept moving was never stopped, and stdout stays silent the whole time. It now ends after 10 minutes with an error naming the files still unfinished and the elapsed seconds; finished copies are reused on the next run. The stderr progress lines are unchanged. --timeout on check and snapshot is milliseconds, so "--timeout 45" waited 45 ms. It now accepts 45s, 2m and 45000ms, and a bare number under 1000 warns on stderr that it is milliseconds. Output on stdout is unchanged. * chore(cli): cut the --timeout parser comment to the comment limit * fix(cli): drop the 10 minute wall clock on check's video copies A copy that keeps making progress must not be cut by a clock, and a re-run would only start it over. The copy already ends when ffmpeg stops reporting progress for 3 minutes (finished pieces are kept for the next run), so the phase is bounded on no progress. The --timeout warning now names the value actually used when check raises a small value to its 500 ms floor.
1 parent 808d642 commit a669316

4 files changed

Lines changed: 78 additions & 3 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
import type { CaptionZoneOptions, FrameCheckOptions, LayoutOptions } from "../utils/checkTypes.js";
3939
import { resolveLocalBrowserGpuMode } from "../browser/gpuPolicy.js";
4040
import { preResolveHostileMediaProxies, type PreparedMediaFile } from "../utils/checkBrowser.js";
41+
import { parseTimeoutMs } from "../utils/timeoutArg.js";
4142

4243
export const examples: Example[] = [
4344
["Run the full verification gate", "hyperframes check"],
@@ -207,7 +208,7 @@ const CHECK_COMMAND_ARGS = {
207208
timeout: {
208209
type: "string",
209210
description:
210-
"Initial render-ready timeout in ms; also sets the navigation minimum (10s floor, default: 3000)",
211+
"Initial render-ready timeout in ms, or with a unit (45s, 2m); also sets the navigation minimum (10s floor, default: 3000)",
211212
default: "3000",
212213
},
213214
contrast: {
@@ -391,7 +392,7 @@ function parseCheckOptions(args: Record<string, unknown>): CheckOptions {
391392
maxIssues: positiveInteger(args["max-issues"], DEFAULT_CHECK_OPTIONS.maxIssues),
392393
collapseStatic: args["collapse-static"] !== false,
393394
tolerance: nonNegativeNumber(args.tolerance, DEFAULT_CHECK_OPTIONS.tolerance),
394-
timeout: Math.max(500, positiveInteger(args.timeout, DEFAULT_CHECK_OPTIONS.timeout)),
395+
timeout: parseTimeoutMs(args.timeout, DEFAULT_CHECK_OPTIONS.timeout, 500),
395396
contrast: args.contrast !== false,
396397
...(checkReview()?.skipContrastInMotion ? { skipContrastInMotion: true } : {}),
397398
strict: args.strict === true,

‎packages/cli/src/commands/snapshot.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
extractMediaMetadata,
66
sdrCanvasColourFilters,
77
} from "@hyperframes/engine";
8+
import { parseTimeoutMs } from "../utils/timeoutArg.js";
89
import type { Page } from "puppeteer-core";
910
import { reportArtifacts } from "../utils/toolContext.js";
1011
import { withProjectLock } from "../utils/projectLock.js";
@@ -1456,7 +1457,7 @@ export default defineCommand({
14561457
}
14571458
failCommand();
14581459
}
1459-
const timeout = parseInt(args.timeout as string, 10) || RENDER_READY_TIMEOUT_MS;
1460+
const timeout = parseTimeoutMs(args.timeout, RENDER_READY_TIMEOUT_MS);
14601461
const describePrompt = resolveDescribePrompt(args.describe);
14611462

14621463
const camera = args.angle ? parseAngle(String(args.angle)) : undefined;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import { parseTimeoutMs } from "./timeoutArg.js";
3+
4+
describe("parseTimeoutMs", () => {
5+
it("reads a bare number as milliseconds and units as written", () => {
6+
const warn = vi.fn();
7+
expect(parseTimeoutMs("45000", 3000, 0, warn)).toBe(45_000);
8+
expect(parseTimeoutMs("45000ms", 3000, 0, warn)).toBe(45_000);
9+
expect(parseTimeoutMs("45s", 3000, 0, warn)).toBe(45_000);
10+
expect(parseTimeoutMs("2m", 3000, 0, warn)).toBe(120_000);
11+
expect(parseTimeoutMs("1.5s", 3000, 0, warn)).toBe(1_500);
12+
expect(warn).not.toHaveBeenCalled();
13+
});
14+
15+
it("falls back when absent, zero or not a duration", () => {
16+
const warn = vi.fn();
17+
expect(parseTimeoutMs(undefined, 3000, 0, warn)).toBe(3000);
18+
expect(parseTimeoutMs("0", 3000, 0, warn)).toBe(3000);
19+
expect(parseTimeoutMs("soon", 3000, 0, warn)).toBe(3000);
20+
expect(warn).toHaveBeenCalledTimes(1);
21+
expect(warn.mock.calls[0]![0]).toContain('"soon"');
22+
});
23+
24+
it("warns that a bare value under 1000 is milliseconds, and keeps it", () => {
25+
const warn = vi.fn();
26+
expect(parseTimeoutMs("45", 3000, 0, warn)).toBe(45);
27+
expect(warn).toHaveBeenCalledTimes(1);
28+
expect(warn.mock.calls[0]![0]).toContain("45 ms");
29+
expect(warn.mock.calls[0]![0]).toContain("45s");
30+
});
31+
32+
it("names the value actually used when the floor raises it", () => {
33+
const warn = vi.fn();
34+
expect(parseTimeoutMs("45", 3000, 500, warn)).toBe(500);
35+
expect(warn.mock.calls[0]![0]).toContain("so 500 ms is used");
36+
expect(parseTimeoutMs("200ms", 3000, 500, warn)).toBe(500);
37+
expect(warn).toHaveBeenCalledTimes(1);
38+
});
39+
40+
it("does not warn when a unit is given, even for a small value", () => {
41+
const warn = vi.fn();
42+
expect(parseTimeoutMs("500ms", 3000, 0, warn)).toBe(500);
43+
expect(warn).not.toHaveBeenCalled();
44+
});
45+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const UNIT_MS = { ms: 1, s: 1_000, m: 60_000 } as const;
2+
3+
/** Reads a `--timeout` as milliseconds, raised to `floorMs`; `45s`, `2m` and `45000ms` carry a unit.
4+
* A bare value under 1000 is kept but warned about: it is usually seconds. */
5+
export function parseTimeoutMs(
6+
raw: unknown,
7+
fallback: number,
8+
floorMs = 0,
9+
warn: (message: string) => void = console.error,
10+
): number {
11+
if (raw === undefined || raw === null || raw === "") return fallback;
12+
const text = String(raw).trim();
13+
const match = /^(\d+(?:\.\d+)?)\s*(ms|s|m)?$/i.exec(text);
14+
if (!match) {
15+
warn(`[hyperframes] --timeout "${text}" is not a duration; using ${fallback} ms.`);
16+
return fallback;
17+
}
18+
const unit = match[2]?.toLowerCase() as keyof typeof UNIT_MS | undefined;
19+
const ms = Math.round(Number(match[1]) * UNIT_MS[unit ?? "ms"]);
20+
if (ms <= 0) return fallback;
21+
const used = Math.max(ms, floorMs);
22+
if (!unit && ms < 1_000) {
23+
warn(
24+
`[hyperframes] --timeout ${text} is ${ms} ms, so ${used} ms is used. Write ${text}s for seconds.`,
25+
);
26+
}
27+
return used;
28+
}

0 commit comments

Comments
 (0)