From 281f1a2a48137925d114dbd8b55e03d152bdf83d Mon Sep 17 00:00:00 2001 From: James Russo Date: Sat, 21 Nov 2026 14:20:57 +0000 Subject: [PATCH] fix(cli): print capture setup commands on their own lines (#8374) * fix(cli): print capture setup commands on their own lines When a capture fails because no browser can be set up on Linux ARM64, the reason stays on the `Capture failed:` line and the setup commands this CLI writes follow it on separate lines, instead of being joined to it with `\x0a`. The design style extraction notice now keeps its reason on one line like the other capture warnings. JSON output and BLOCKED.md are unchanged. Co-Authored-By: Claude Fable 5.2 * refactor(cli): name the setup lines field for what it holds Co-Authored-By: Claude Fable 5.2 --------- Co-authored-by: Claude Fable 5.2 --- docs/packages/cli.mdx | 6 ++- packages/cli/src/browser/manager.ts | 8 ++-- .../src/capture/coreExtractionPhase.test.ts | 42 ++++++++++++++----- .../cli/src/capture/coreExtractionPhase.ts | 4 +- packages/cli/src/commands/capture.test.ts | 30 +++++++++++++ packages/cli/src/commands/capture.ts | 6 ++- packages/cli/src/utils/errorMessage.ts | 9 ++++ 7 files changed, 86 insertions(+), 19 deletions(-) diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx index 6da7df871d..78ab78c2dc 100644 --- a/docs/packages/cli.mdx +++ b/docs/packages/cli.mdx @@ -430,7 +430,11 @@ you build. Each warning, and the reason on a `Capture failed:` line, is printed on one line: a line break inside the text is shown as `\x0a` instead of starting a new -terminal line. `--json` output is unchanged and carries the full text. +terminal line. `--json` output is unchanged and carries the full text. The +`Design style extraction failed` line printed during a capture follows the same +rule. When a capture fails because no browser can be set up on Linux ARM64, the +reason stays on the `Capture failed:` line and the setup commands follow it on +lines of their own, ready to copy. Downloaded fonts are saved under `assets/fonts/`, and their CSS references point to those local files. Distinct URLs such as `demo.woff2?v=1` and diff --git a/packages/cli/src/browser/manager.ts b/packages/cli/src/browser/manager.ts index b04c8ce844..693b780e95 100644 --- a/packages/cli/src/browser/manager.ts +++ b/packages/cli/src/browser/manager.ts @@ -24,7 +24,7 @@ import { } from "@hyperframes/engine/chrome-host-ceiling"; import { getFreeDiskMb } from "../telemetry/system.js"; import { BrowserDownloadStalledError, installInChild } from "./installInChild.js"; -import { normalizeErrorMessage } from "../utils/errorMessage.js"; +import { normalizeErrorMessage, SetupStepsError } from "../utils/errorMessage.js"; import { runRenderSetupWorker } from "../utils/cancellableProcess.js"; import { unzipArchive } from "./unzipArchive.js"; import { @@ -524,9 +524,9 @@ async function ensureLinuxArmBrowser(options?: EnsureBrowserOptions): Promise
({ remaining: 10000, expireLazy: false, throwCatalog: false })); +const control = vi.hoisted(() => ({ + remaining: 10000, + expireLazy: false, + throwCatalog: false, + styleError: "", +})); vi.mock("./lazyScrollForCapture.js", () => ({ lazyScrollForCapture: async () => { if (control.expireLazy) control.remaining = 0; @@ -35,15 +40,18 @@ vi.mock("./tokenExtractor.js", () => ({ }), })); vi.mock("./designStyleExtractor.js", () => ({ - extractDesignStyles: async () => ({ - typography: [], - spacing: { observed: [], baseUnit: 0 }, - radius: [], - shadows: [], - buttons: [], - cards: [], - nav: null, - }), + extractDesignStyles: async () => { + if (control.styleError) throw new Error(control.styleError); + return { + typography: [], + spacing: { observed: [], baseUnit: 0 }, + radius: [], + shadows: [], + buttons: [], + cards: [], + nav: null, + }; + }, })); vi.mock("./assetCataloger.js", () => ({ catalogAssets: async () => [] })); vi.mock("./htmlExtractor.js", () => ({ @@ -71,6 +79,8 @@ afterEach(() => { control.remaining = 10000; control.expireLazy = false; control.throwCatalog = false; + control.styleError = ""; + vi.restoreAllMocks(); }); const REFUSED = "Protocol error (Page.captureScreenshot): Unable to capture screenshot"; @@ -184,4 +194,16 @@ describe("core extraction screenshot budget", () => { "animation catalog evaluate timed out; continuing without animation catalog", ); }); + // fails without the fix: a line break in the reason started a line of its own + it("keeps the reason design styles could not be read on one line", async () => { + const error = vi.spyOn(console, "error").mockImplementation(() => {}); + control.styleError = "no styles\n ✓ Captured"; + const { warnings } = await extract(); + const line = String(error.mock.calls[0]![0]); + expect(line).toMatch( + /^ {2}⚠ Design style extraction failed: no styles\\x0a {2}✓ Captured\\x0a/, + ); + expect(line).not.toContain("\n"); + expect(warnings.join()).toContain("no styles\n ✓ Captured"); + }); }); diff --git a/packages/cli/src/capture/coreExtractionPhase.ts b/packages/cli/src/capture/coreExtractionPhase.ts index 95cc191b39..0b5ced7ebc 100644 --- a/packages/cli/src/capture/coreExtractionPhase.ts +++ b/packages/cli/src/capture/coreExtractionPhase.ts @@ -28,7 +28,7 @@ import { isDegradableEvaluateTimeoutError } from "./captureTimeout.js"; import { waitForPageReady } from "./navigateForCapture.js"; import { lazyScrollForCapture } from "./lazyScrollForCapture.js"; import { filterExtractedScripts } from "./filterExtractedScripts.js"; -import { terminalLines } from "@hyperframes/core"; +import { terminalText } from "@hyperframes/core"; export interface CoreExtractionInput { page1: Page; @@ -279,7 +279,7 @@ export async function runCoreExtraction(input: CoreExtractionInput): Promise ({ vi.mock("../capture/index.js", () => ({ captureWebsite: captureWebsiteMock })); import captureCommand from "./capture.js"; +import { SetupStepsError } from "../utils/errorMessage.js"; describe("capture command — vision control", () => { afterEach(() => { @@ -528,4 +529,33 @@ describe("capture command: what it prints", () => { } expect(printed(error)).toContain("Capture failed: no route\\x0a ✓ Captured"); }); + + // fails without the fix: the setup commands were joined to the reason with `\x0a` + it("prints the setup commands of a failed capture on lines of their own", async () => { + vi.useFakeTimers(); + registerRootExitRequester(() => {}); + const error = vi.spyOn(console, "error").mockImplementation(() => {}); + const log = vi.spyOn(console, "log").mockImplementation(() => {}); + const failure = new SetupStepsError( + "No browser\nhere", + "Install one:\n\n install-it\n use-it", + ); + captureWebsiteMock.mockRejectedValueOnce(failure).mockRejectedValueOnce(failure); + const output = mkdtempSync(join(tmpdir(), "hf-capture-steps-")); + const run = (args: object) => + captureCommand.run!({ args: { url: "https://example.com", output, ...args } } as never).catch( + () => {}, + ); + try { + await run({}); + await run({ json: true }); + } finally { + vi.useRealTimers(); + rmSync(output, { recursive: true, force: true }); + } + expect(printed(error)).toBe( + "\n ✗ Capture failed: No browser\\x0ahere\n\nInstall one:\n\n install-it\n use-it\n", + ); + expect(JSON.parse(String(log.mock.calls.at(-1)![0])).error.message).toBe(failure.message); + }); }); diff --git a/packages/cli/src/commands/capture.ts b/packages/cli/src/commands/capture.ts index b9acff6678..a844c28435 100644 --- a/packages/cli/src/commands/capture.ts +++ b/packages/cli/src/commands/capture.ts @@ -3,7 +3,7 @@ import { failCommand, scheduleCliExit, failUsage } from "../utils/commandResult. import { defineCommand } from "../utils/defineCommand.js"; import { resolve } from "node:path"; import type { Example } from "./_examples.js"; -import { normalizeErrorMessage } from "../utils/errorMessage.js"; +import { normalizeErrorMessage, SetupStepsError } from "../utils/errorMessage.js"; import { diag } from "../ui/diagnostics.js"; import type { CapturePhaseProgress } from "../capture/types.js"; import { parseCaptureDeadline } from "../capture/captureWatchdog.js"; @@ -359,7 +359,9 @@ export default defineCommand({ if (isJson) { console.log(JSON.stringify(jsonFailure("runtime_error", errMsg))); } else { - console.error(`\n ✗ Capture failed: ${terminalText(errMsg)}\n`); + const setup = err instanceof SetupStepsError ? err : undefined; + console.error(`\n ✗ Capture failed: ${terminalText(setup?.summary ?? errMsg)}\n`); + if (setup) console.error(`${setup.stepsWrittenByCli}\n`); } scheduleCliExit(1); failCommand(); diff --git a/packages/cli/src/utils/errorMessage.ts b/packages/cli/src/utils/errorMessage.ts index 6d79267789..547fb0d76f 100644 --- a/packages/cli/src/utils/errorMessage.ts +++ b/packages/cli/src/utils/errorMessage.ts @@ -12,6 +12,15 @@ function namedAfterCrash(message: string): string { : message; } +export class SetupStepsError extends Error { + constructor( + readonly summary: string, + readonly stepsWrittenByCli: string, + ) { + super(`${summary}\n\n${stepsWrittenByCli}`); + } +} + export function normalizeErrorMessage(error: unknown): string { if (error instanceof Error) return namedAfterCrash(error.message); if (typeof error === "string") return error;