diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx index 78ab78c2dc..789c72bf05 100644 --- a/docs/packages/cli.mdx +++ b/docs/packages/cli.mdx @@ -1343,6 +1343,10 @@ npx hyperframes check [dir] --at 1.5,4,7.25 npx hyperframes check [dir] --strict # warnings fail too ``` +When `check` or the deprecated `validate` fails because no browser can be set up +on Linux ARM64, the reason stays on the failure line and the setup commands +follow it on lines of their own, ready to copy. `--json` output is unchanged. + `check` runs the linter first. A lint error fails the check but does not stop it: the browser checks still run and both are reported, unless the lint error leaves no composition to load (a root with no `data-composition-id`). diff --git a/packages/cli/src/browser/manager.ts b/packages/cli/src/browser/manager.ts index 693b780e95..57c6c9a066 100644 --- a/packages/cli/src/browser/manager.ts +++ b/packages/cli/src/browser/manager.ts @@ -24,7 +24,11 @@ import { } from "@hyperframes/engine/chrome-host-ceiling"; import { getFreeDiskMb } from "../telemetry/system.js"; import { BrowserDownloadStalledError, installInChild } from "./installInChild.js"; -import { normalizeErrorMessage, SetupStepsError } from "../utils/errorMessage.js"; +import { + LINUX_ARM_BROWSER_STEPS, + normalizeErrorMessage, + SetupStepsError, +} from "../utils/errorMessage.js"; import { runRenderSetupWorker } from "../utils/cancellableProcess.js"; import { unzipArchive } from "./unzipArchive.js"; import { @@ -526,10 +530,7 @@ async function ensureLinuxArmBrowser(options?: EnsureBrowserOptions): Promise
({ import { contrastRatio, parseColorRGBA } from "./contrast-bg.js"; import { createCheckCommand, parseCheckRange, parseSafeZone } from "./check.js"; import { assertKnownFlags } from "../utils/reject-unknown-flags.js"; +import { LINUX_ARM_BROWSER_STEPS } from "../utils/errorMessage.js"; import { readConfig } from "../telemetry/config.js"; import { CheckCopiesUnfinishedError, @@ -528,6 +529,72 @@ describe("check --prepare-media", () => { expect(human).toContain("video\\x1b]0;x\\x07\\x1b[2J"); consumeCommandResult(); }); + + // fails without the fix: the setup commands were joined to the reason with `\x0a` + it("prints the setup commands of a failed check on lines of their own", async () => { + const reason = `No browser\nhere\n\n${LINUX_ARM_BROWSER_STEPS} (while launching)`; + const error = vi.spyOn(console, "error").mockImplementation(() => undefined); + const log = vi.spyOn(console, "log").mockImplementation(() => undefined); + const run = (rawArgs: string[]) => + runCommand( + createCheckCommand({ + resolveProject: () => PROJECT, + runPipeline: vi.fn(async () => Promise.reject(new Error(reason))), + prepareMedia: vi.fn(async () => []), + withMeta: (value) => value, + }), + { rawArgs }, + ).then(consumeCommandResult); + await run([]); + await run(["--json"]); + const { report } = await runScenario(fakeDriver()); + const finding = { ...runtimeError(), code: "check_runtime_failure", message: reason }; + await runCommand( + createCheckCommand({ + resolveProject: () => PROJECT, + runPipeline: async () => ({ + ...report, + runtime: { ...report.runtime, ok: false, errorCount: 1, findings: [finding] }, + }), + prepareMedia: vi.fn(), + withMeta: (value) => value, + }), + { rawArgs: [] }, + ).then(consumeCommandResult); + const human = log.mock.calls.map((call) => call.join(" ")).join("\n"); + expect(human).toContain("check_runtime_failure: No browser\\x0ahere (while launching)\n"); + expect(human).toContain(`\n\n${LINUX_ARM_BROWSER_STEPS}\n`); + + const printed = error.mock.calls.map((call) => call.join(" ")).join("\n"); + expect(printed).toContain( + `Check failed: No browser\\x0ahere (while launching)\n\n${LINUX_ARM_BROWSER_STEPS}\n`, + ); + const answer = log.mock.calls.map((call) => String(call[0])).find((text) => text[0] === "{"); + expect(JSON.parse(answer!).error.message).toBe(reason); + }); + + it("keeps a finding with another code on one line even when it carries the setup text", async () => { + const message = `From the page\n\n${LINUX_ARM_BROWSER_STEPS}`; + const log = vi.spyOn(console, "log").mockImplementation(() => undefined); + const { report } = await runScenario(fakeDriver()); + const finding = { ...runtimeError(), message }; + expect(finding.code).not.toBe("check_runtime_failure"); + await runCommand( + createCheckCommand({ + resolveProject: () => PROJECT, + runPipeline: async () => ({ + ...report, + runtime: { ...report.runtime, ok: false, errorCount: 1, findings: [finding] }, + }), + prepareMedia: vi.fn(), + withMeta: (value) => value, + }), + { rawArgs: [] }, + ).then(consumeCommandResult); + const human = log.mock.calls.map((call) => call.join(" ")).join("\n"); + expect(human).toContain(`${finding.code}: ${message.replaceAll("\n", "\\x0a")}\n`); + expect(human).not.toContain(LINUX_ARM_BROWSER_STEPS); + }); }); describe("skip contrast in motion", () => { diff --git a/packages/cli/src/commands/check.ts b/packages/cli/src/commands/check.ts index 9a4bcd0940..e3acde2790 100644 --- a/packages/cli/src/commands/check.ts +++ b/packages/cli/src/commands/check.ts @@ -20,7 +20,7 @@ import type { Example } from "./_examples.js"; import { parseAt } from "./layout.js"; import { c } from "../ui/colors.js"; import { registerBrowserSessionCleanup } from "../browser/launch.js"; -import { normalizeErrorMessage } from "../utils/errorMessage.js"; +import { normalizeErrorMessage, splitStepsWrittenByCli } from "../utils/errorMessage.js"; import { CliUsageError, failUsage, setCommandExitCode } from "../utils/commandResult.js"; import { swallowedFlagUsageError } from "../utils/reject-unknown-flags.js"; import { formatLayoutIssue } from "../utils/layoutAudit.js"; @@ -422,7 +422,9 @@ function reportCheckFailure( const code = usage ? error.code : "runtime_error"; console.log(JSON.stringify(addMeta(jsonFailure(code, message)), null, 2)); } else { - console.error(`${c.error("✗")} Check failed: ${terminalText(message)}`); + const { summary, stepsWrittenByCli } = splitStepsWrittenByCli(message); + console.error(`${c.error("✗")} Check failed: ${terminalText(summary)}`); + if (stepsWrittenByCli) console.error(`\n${stepsWrittenByCli}\n`); } if (usage) failUsage(); setCommandExitCode(1); @@ -902,10 +904,13 @@ function printSnapshotSection(report: CheckReport): void { function printFinding(finding: CheckFinding): void { const where = `${terminalText(finding.sourceFile)} ${terminalText(finding.selector)} ${formatFindingTimes(finding)}`; - console.log( - ` ${findingIcon(finding)} ${terminalText(finding.code)}: ${terminalText(finding.message)}`, - ); + const { summary, stepsWrittenByCli } = + finding.code === "check_runtime_failure" + ? splitStepsWrittenByCli(finding.message) + : { summary: finding.message, stepsWrittenByCli: undefined }; + console.log(` ${findingIcon(finding)} ${terminalText(finding.code)}: ${terminalText(summary)}`); console.log(` ${c.dim(where)}`); + if (stepsWrittenByCli) console.log(`\n${stepsWrittenByCli}\n`); if (finding.fixHint) console.log(` ${c.dim(`Fix: ${terminalText(finding.fixHint)}`)}`); } diff --git a/packages/cli/src/commands/validate.test.ts b/packages/cli/src/commands/validate.test.ts index dcbaa35c46..bfdc1b9b6b 100644 --- a/packages/cli/src/commands/validate.test.ts +++ b/packages/cli/src/commands/validate.test.ts @@ -22,6 +22,7 @@ import { shouldIgnoreHttpError, } from "./validate.js"; import { waitForPreferredSeekTarget } from "../capture/captureCompositionFrame.js"; +import { LINUX_ARM_BROWSER_STEPS } from "../utils/errorMessage.js"; import type { ProjectLintResult } from "../utils/lintProject.js"; // validateInBrowser lazy-loads the producer localize helpers via loadProducer; @@ -441,6 +442,24 @@ describe("validate text report", () => { } }); + // fails without the fix: the setup commands were joined to the reason with `\x0a` + it("prints the setup commands of a failed run on lines of their own", () => { + const reason = `No browser\nhere\n\n${LINUX_ARM_BROWSER_STEPS}`; + const error = vi.spyOn(console, "error").mockImplementation(() => {}); + const log = vi.spyOn(console, "log").mockImplementation(() => {}); + try { + emitFailureReport(reason, false); + emitFailureReport(reason, true); + expect(error.mock.calls.map((args) => args.join(" ")).join("\n")).toContain( + `No browser\\x0ahere\n\n${LINUX_ARM_BROWSER_STEPS}\n`, + ); + expect(JSON.parse(String(log.mock.calls.at(-1)![0])).error.message).toBe(reason); + } finally { + error.mockRestore(); + log.mockRestore(); + } + }); + it("prints a failure message with control characters as visible escapes", () => { const error = vi.spyOn(console, "error").mockImplementation(() => {}); try { diff --git a/packages/cli/src/commands/validate.ts b/packages/cli/src/commands/validate.ts index b782ef385c..9093945607 100644 --- a/packages/cli/src/commands/validate.ts +++ b/packages/cli/src/commands/validate.ts @@ -12,7 +12,7 @@ import { tmpdir } from "node:os"; import { join, dirname } from "node:path"; import { fileURLToPath } from "node:url"; import { resolveProject, type ProjectDir } from "../utils/project.js"; -import { normalizeErrorMessage } from "../utils/errorMessage.js"; +import { normalizeErrorMessage, splitStepsWrittenByCli } from "../utils/errorMessage.js"; import type { ProjectLintResult } from "../utils/lintProject.js"; import { resolveCompositionViewportFromHtml } from "../utils/compositionViewport.js"; import { @@ -657,7 +657,9 @@ export function emitFailureReport(message: string, asJson: boolean): void { ); return; } - console.error(`${c.error("✗")} ${terminalText(message)}`); + const { summary, stepsWrittenByCli } = splitStepsWrittenByCli(message); + console.error(`${c.error("✗")} ${terminalText(summary)}`); + if (stepsWrittenByCli) console.error(`\n${stepsWrittenByCli}\n`); } export default defineCommand({ diff --git a/packages/cli/src/utils/errorMessage.ts b/packages/cli/src/utils/errorMessage.ts index 547fb0d76f..bf3d0438cc 100644 --- a/packages/cli/src/utils/errorMessage.ts +++ b/packages/cli/src/utils/errorMessage.ts @@ -21,6 +21,25 @@ export class SetupStepsError extends Error { } } +export const LINUX_ARM_BROWSER_STEPS = + `Install Chromium manually and point hyperframes to it:\n\n` + + ` sudo apt-get install -y chromium-browser\n` + + ` export HYPERFRAMES_BROWSER_PATH=$(which chromium-browser)\n\n` + + `Then re-run your command. The HYPERFRAMES_BROWSER_PATH env var persists for the session.`; + +export function splitStepsWrittenByCli(message: string): { + summary: string; + stepsWrittenByCli?: string; +} { + const joined = `\n\n${LINUX_ARM_BROWSER_STEPS}`; + const at = message.indexOf(joined); + if (at === -1) return { summary: message }; + return { + summary: message.slice(0, at) + message.slice(at + joined.length), + stepsWrittenByCli: LINUX_ARM_BROWSER_STEPS, + }; +} + export function normalizeErrorMessage(error: unknown): string { if (error instanceof Error) return namedAfterCrash(error.message); if (typeof error === "string") return error;