Skip to content

Commit d360760

Browse files
committed
fix(cli): validate capture budget milliseconds
1 parent 49091e6 commit d360760

3 files changed

Lines changed: 38 additions & 26 deletions

File tree

‎packages/cli/src/capture/assetDownloader.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,10 @@ export async function downloadAndRewriteFonts(
264264

265265
if (fontUrls.size === 0) return css;
266266

267-
// Limit font downloads to avoid bloat. Google Fonts serves 20+ unicode-range
268-
// subsets per weight — we only need a few per family for video production.
267+
// Limit font download attempts to bound worst-case egress and latency. Google Fonts serves
268+
// 20+ unicode-range subsets per weight, so successes alone cannot be the bound: six transient
269+
// failures can intentionally suppress later URLs in that family. Latin-priority sorting below
270+
// makes the limited attempts useful while keeping this failure tradeoff explicit.
269271
const MAX_FONTS_PER_FAMILY = 6;
270272
const MAX_TOTAL_FONTS = 30;
271273
const familyCounts = new Map<string, number>();

‎packages/cli/src/commands/capture.test.ts‎

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ describe("capture command — vision control", () => {
5757
? Reflect.get(captureCommand.args, "capture-budget")
5858
: undefined;
5959
expect(captureBudgetArg).toMatchObject({ type: "string" });
60-
expect(captureBudgetArg?.description.toLowerCase()).toContain("post-navigation");
60+
const description = captureBudgetArg?.description.toLowerCase();
61+
expect(description).toContain("post-navigation");
62+
expect(description).toContain("cooperative");
63+
expect(description).toContain("not a hard wall-clock timeout");
64+
expect(description).toContain("already-started native/core work");
6165
expect(captureBudgetArg?.description).toContain("--timeout");
6266
});
6367

@@ -81,28 +85,34 @@ describe("capture command — vision control", () => {
8185
);
8286
});
8387

84-
it("plumbs a positive --capture-budget into the post-navigation budget", async () => {
85-
vi.spyOn(console, "log").mockImplementation(() => {});
86-
vi.spyOn(console, "error").mockImplementation(() => {});
87-
88-
await captureCommand.run!({
89-
args: {
90-
url: "https://example.com",
91-
output: "/tmp/hf-capture-budget-test",
92-
"skip-assets": false,
93-
"skip-vision": false,
94-
"capture-budget": "45000",
95-
json: true,
96-
},
97-
} as never);
88+
it.each([
89+
["1", 1],
90+
["45000", 45_000],
91+
])(
92+
"plumbs positive integer --capture-budget %s into the post-navigation budget",
93+
async (captureBudget, expectedBudget) => {
94+
vi.spyOn(console, "log").mockImplementation(() => {});
95+
vi.spyOn(console, "error").mockImplementation(() => {});
9896

99-
expect(captureWebsiteMock).toHaveBeenCalledWith(
100-
expect.objectContaining({ postNavigationBudgetMs: 45_000 }),
101-
undefined,
102-
);
103-
});
97+
await captureCommand.run!({
98+
args: {
99+
url: "https://example.com",
100+
output: "/tmp/hf-capture-budget-test",
101+
"skip-assets": false,
102+
"skip-vision": false,
103+
"capture-budget": captureBudget,
104+
json: true,
105+
},
106+
} as never);
107+
108+
expect(captureWebsiteMock).toHaveBeenCalledWith(
109+
expect.objectContaining({ postNavigationBudgetMs: expectedBudget }),
110+
undefined,
111+
);
112+
},
113+
);
104114

105-
it.each(["0", "-1", "Infinity", "not-a-number"])(
115+
it.each(["0", "-1", "0.5", "Infinity", "not-a-number"])(
106116
"rejects invalid --capture-budget %s before capture starts",
107117
async (captureBudget) => {
108118
vi.spyOn(console, "log").mockImplementation(() => {});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ function emitCapturePhase(event: CapturePhaseProgress): void {
1515
function parseCaptureBudget(raw: string | undefined): number | undefined {
1616
if (raw === undefined) return undefined;
1717
const parsed = Number(raw);
18-
if (!Number.isFinite(parsed) || parsed <= 0) {
19-
console.error("--capture-budget must be a positive finite number of milliseconds.");
18+
if (!Number.isInteger(parsed) || parsed <= 0) {
19+
console.error("--capture-budget must be a positive integer in milliseconds.");
2020
failCommand();
2121
}
2222
return parsed;
@@ -73,7 +73,7 @@ export default defineCommand({
7373
"capture-budget": {
7474
type: "string",
7575
description:
76-
"Post-navigation capture budget in ms (default: 120000); separate from page-load --timeout",
76+
"Cooperative post-navigation budget in ms (default: 120000), separate from page-load --timeout; not a hard wall-clock timeout and cannot interrupt already-started native/core work",
7777
},
7878
json: {
7979
type: "boolean",

0 commit comments

Comments
 (0)