fix(cli): print project file names in check's stderr notes as visible escapes (#8485)

* fix(cli): print project file names in check's stderr notes as visible escapes (SECOPS-2752)

The text_over_face note printed the unread video's reason raw, and that
reason carries the project's file name and the decoder's own error text,
so a video named with ESC, BEL or CR could drive the terminal during
`hyperframes check`. The same check output path had four more lines
printing project-derived text raw: the project-lock waiting notice (the
holder is read from the project's lock file), the "images did not load"
warning (image addresses read back from the page), the font-localization
warning (the injector's error text), and the saved report's Revision line
(read from the project's history).

Each now goes through the existing @hyperframes/core terminal-text helper:
terminalLines where the text is an error message whose line breaks are
kept, terminalText for one-line notices. Plain names print as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): keep check's escape fix within the comment ratchet and testable on Windows (SECOPS-2752)

Drop the three comment lines the escape fix added to source files, which
raised their comment share. The text_over_face hostile-name test now feeds
the name through the candidate and an injected reader, so it runs on every
platform; the real-reader case, which needs a file named with control
characters, runs everywhere but Windows, whose file names cannot hold them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WaterrrForever
2026-11-22 16:56:27 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent c19d98d9a1
commit 4202462ca5
10 changed files with 211 additions and 7 deletions
@@ -19,6 +19,7 @@ import {
seekCompositionTimeline,
seekCompositionTimelineOnly,
settleCompositionSeek,
unloadedImagesWarning,
waitForRuntimeReady,
type CompositionSeekPage,
} from "./captureCompositionFrame.js";
@@ -103,6 +104,28 @@ describe("waitForRuntimeReady", () => {
});
});
describe("unloadedImagesWarning", () => {
// Built rather than written: a literal control character in the source is a lint error.
const esc = String.fromCharCode(27);
const sgr = new RegExp(`${esc}\\[[0-9;]*m`, "g");
// fails without the fix: the page's image address reached the terminal with its ESC and BEL raw
it("prints the page's image addresses with control characters as visible escapes", () => {
const line = unloadedImagesWarning(
5000,
`http://127.0.0.1/hero${esc}]0;owned${String.fromCharCode(7)}.png`,
).replace(sgr, "");
expect(line).not.toContain(esc);
expect(line).toContain("http://127.0.0.1/hero\\x1b]0;owned\\x07.png. They may show blank.");
});
it("prints plain addresses as they are", () => {
expect(unloadedImagesWarning(5000, "http://127.0.0.1/a.png, b.png").replace(sgr, "")).toBe(
" ⚠ Some images did not load within 5000ms: http://127.0.0.1/a.png, b.png. They may show blank.",
);
});
});
describe("seekCompositionTimeline", () => {
it("keeps the raced double-frame settle and adds a bounded font wait by default", async () => {
const { page, evaluate, waitForFunction } = fakeSeekPage();
@@ -6,6 +6,7 @@ import {
resolveManagedGpuMode,
} from "../browser/launch.js";
import { spawn } from "node:child_process";
import { terminalText } from "@hyperframes/core/terminal-text";
import type { Browser, Page } from "puppeteer-core";
import type { InProcessRequest, InProcessResponse } from "../utils/staticProjectServer.js";
import { c } from "../ui/colors.js";
@@ -271,13 +272,15 @@ async function waitForCompositionSettle(
const { resolveConfig, waitForImagesReady } = await import("@hyperframes/engine");
const imageTimeoutMs = resolveConfig().playerReadyTimeout;
await waitForImagesReady(page, imageTimeoutMs, (sources) =>
console.warn(
` ${c.warn("⚠")} Some images did not load within ${imageTimeoutMs}ms: ${sources}. They may show blank.`,
),
console.warn(unloadedImagesWarning(imageTimeoutMs, sources)),
);
return runtimeReady;
}
export function unloadedImagesWarning(timeoutMs: number, sources: string): string {
return ` ${c.warn("⚠")} Some images did not load within ${timeoutMs}ms: ${terminalText(sources)}. They may show blank.`;
}
async function waitForLateSubresources(page: Page, timeoutMs: number): Promise<void> {
let cap: ReturnType<typeof setTimeout> | undefined;
const deadline = Date.now() + timeoutMs;
+31
View File
@@ -521,6 +521,37 @@ describe("check --prepare-media", () => {
consumeCommandResult();
});
// fails without the fix: the revision read from the project's history reached stdout raw
it("prints the saved report's revision with control characters as visible escapes", async () => {
// Built rather than written: a literal control character in the source is a lint error.
const esc = String.fromCharCode(27);
const { report } = await runScenario(fakeDriver());
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
await runCommand(
createCheckCommand({
resolveProject: () => PROJECT,
runPipeline: async () => ({
...report,
saved: {
id: "check-1",
revision: `r1${esc}]0;owned${String.fromCharCode(7)}`,
report: "/work/.hyperframes/artifacts/checks/check-1.json",
attribution: "recorded-revision",
},
}),
prepareMedia: vi.fn(),
withMeta: (value) => value,
}),
{ rawArgs: [] },
);
const human = log.mock.calls.map((call) => call.join(" ")).join("\n");
expect(human.replace(new RegExp(`${esc}\\[[0-9;]*m`, "g"), "")).not.toContain(esc);
expect(human).toContain("Revision: r1\\x1b]0;owned\\x07 (recorded-revision)");
expect(human).toContain("Report: /work/.hyperframes/artifacts/checks/check-1.json");
consumeCommandResult();
});
it("prints a folder name with control characters as visible escapes", async () => {
// Built rather than written: a literal control character in the source is a lint error.
const esc = String.fromCharCode(27);
+3 -1
View File
@@ -371,7 +371,9 @@ export function createCheckCommand(
if (report.saved) {
console.log(terminalText(`Report: ${report.saved.report}`));
console.log(
`Revision: ${report.saved.revision ?? "none"} (${report.saved.attribution})`,
terminalText(
`Revision: ${report.saved.revision ?? "none"} (${report.saved.attribution})`,
),
);
}
}
@@ -81,4 +81,23 @@ describe("localizeWithProducer", () => {
// snapshot/check re-bundle per grid point; the warning must fire once.
expect(warn).toHaveBeenCalledOnce();
});
// fails without the fix: a font address from the project reached the terminal with its ESC raw
it("prints the injector's failure with control characters as visible escapes", async () => {
// Built rather than written: a literal control character in the source is a lint error.
const esc = String.fromCharCode(27);
const printed = vi.spyOn(console, "warn").mockImplementation(() => undefined);
const boom: () => Promise<never> = () =>
Promise.reject(
new Error(`cannot fetch fonts/brand${esc}]0;owned${String.fromCharCode(7)}.woff2`),
);
await localizeWithProducer("<html></html>", async () => boom);
const line = String(printed.mock.calls[0]?.[0]).replace(
new RegExp(`${esc}\\[[0-9;]*m`, "g"),
"",
);
printed.mockRestore();
expect(line).not.toContain(esc);
expect(line).toContain("cannot fetch fonts/brand\\x1b]0;owned\\x07.woff2");
});
});
@@ -1,4 +1,5 @@
import type { BundleOptions } from "@hyperframes/core/compiler";
import { terminalLines } from "@hyperframes/core/terminal-text";
import { normalizeErrorMessage } from "./errorMessage.js";
import { c } from "../ui/colors.js";
@@ -78,7 +79,7 @@ export function __resetFontLocalizationWarningsForTests(): void {
export async function localizeWithProducer(
html: string,
loadInjector: () => Promise<FontInjector | null> = loadFontInjector,
warn: (message: string) => void = (m) => console.warn(` ${c.warn("⚠")} ${m}`),
warn: (message: string) => void = (m) => console.warn(` ${c.warn("⚠")} ${terminalLines(m)}`),
): Promise<string> {
const inject = await loadInjector();
if (!inject) return html;
@@ -116,6 +116,40 @@ describe("withProjectLock", () => {
said.mockRestore();
});
// fails without the fix: the command named in the project's lock file reached stderr raw
it("prints the holder a project's lock file names with control characters as visible escapes", async () => {
// Built rather than written: a literal control character in the source is a lint error.
const esc = String.fromCharCode(27);
const dir = project();
const lock = projectLockPath(dir);
mkdirSync(dirname(lock), { recursive: true });
writeFileSync(
lock,
JSON.stringify({
pid: process.pid,
command: `render${esc}]0;owned${String.fromCharCode(7)}${esc}[2K${String.fromCharCode(13)}`,
startedAt: Date.now(),
}),
);
const said = vi.spyOn(console, "error").mockImplementation(() => undefined);
const base = Date.now();
const clock = vi
.spyOn(Date, "now")
.mockReturnValueOnce(base)
.mockReturnValue(base + 6_000);
await expect(withProjectLock(dir, "check", async () => "ran", locked(300))).rejects.toThrow(
ProjectLockTimeout,
);
clock.mockRestore();
const line = String(said.mock.calls[0]?.[0]);
said.mockRestore();
expect(line).not.toContain(esc);
expect(line).not.toContain(String.fromCharCode(13));
expect(line).toContain(
`waiting for render\\x1b]0;owned\\x07\\x1b[2K\\x0d (pid ${process.pid}, running `,
);
});
it("takes over a lock whose process has exited", async () => {
const dir = project();
hold(dir, 2 ** 22 + 12345);
+4 -1
View File
@@ -1,4 +1,5 @@
import { readFileSync, unlinkSync } from "node:fs";
import { terminalText } from "@hyperframes/core/terminal-text";
import { createFileAtomically } from "@hyperframes/core/atomic-file";
import { join } from "node:path";
import { setTimeout as sleep } from "node:timers/promises";
@@ -79,7 +80,9 @@ function sayWaiting(current: Holder | null, waitMs: number): void {
if (!current) return;
const running = Math.round((Date.now() - current.startedAt) / 1000);
console.error(
`[hyperframes] waiting for ${current.command} (pid ${current.pid}, running ${running}s) to finish with this project; waiting up to ${Math.round(waitMs / 1000)}s`,
terminalText(
`[hyperframes] waiting for ${current.command} (pid ${current.pid}, running ${running}s) to finish with this project; waiting up to ${Math.round(waitMs / 1000)}s`,
),
);
}
@@ -364,6 +364,91 @@ describe("findTextOverFace on a shipped playlist", () => {
);
});
describe("findTextOverFace's stderr note on a hostile file name", () => {
afterEach(() => vi.restoreAllMocks());
// Built rather than written: a literal control character in the source is a lint error.
const ESC = String.fromCharCode(27);
const BEL = String.fromCharCode(7);
const CR = String.fromCharCode(13);
// fails without the fix: the file name the candidate names reached stderr with its ESC, BEL and CR raw
it("prints a project file name with control characters as visible escapes", async () => {
const file = `/project/take${ESC}]0;owned${BEL}${ESC}[2K${CR}clean.mp4`;
const errors = vi.spyOn(console, "error").mockImplementation(() => undefined);
const facesIn = vi.fn<FaceFinder>(async (named) => {
throw new Error(`could not read every frame of ${named}`);
});
const { faceCheck } = await findTextOverFace(
[candidate({ video: { ...candidate().video, file } })],
facesIn,
);
expect(facesIn).toHaveBeenCalledWith(file, [7], expect.anything());
const line = String(errors.mock.calls[0]?.[0]);
for (const raw of [ESC, BEL, CR]) expect(line).not.toContain(raw);
expect(line).toBe(
"[hyperframes] check: text over a face was not looked for in 1 of 1 video(s): could not read every frame of /project/take\\x1b]0;owned\\x07\\x1b[2K\\x0dclean.mp4",
);
// The report keeps the reason as it was: JSON output escapes it on its own.
expect(faceCheck).toEqual({ ran: false, reason: `could not read every frame of ${file}` });
});
// Windows refuses control characters in a file name, so only other systems can ship one.
// fails without the fix: the real reader's refusal reached stderr with the name's ESC, BEL and CR raw
it.skipIf(process.platform === "win32")(
"escapes a hostile name the real reader refuses",
async () => {
const dir = mkdtempSync(join(tmpdir(), "hf-face-escape-"));
try {
// A playlist naming a file outside its folder is refused before ffprobe runs, by its name.
const file = join(dir, `take${ESC}]0;owned${BEL}${ESC}[2K${CR}clean.m3u8`);
writeFileSync(file, "#EXTM3U\n#EXTINF:1,\n../outside.ts\n#EXT-X-ENDLIST\n");
const errors = vi.spyOn(console, "error").mockImplementation(() => undefined);
const { faceCheck } = await findTextOverFace([
candidate({ video: { ...candidate().video, file } }),
]);
expect(errors).toHaveBeenCalledTimes(1);
const line = String(errors.mock.calls[0]?.[0]);
for (const raw of [ESC, BEL, CR]) expect(line).not.toContain(raw);
expect(line).toContain(`take\\x1b]0;owned\\x07\\x1b[2K\\x0dclean.m3u8 is not media`);
expect(faceCheck).toMatchObject({ ran: false, reason: expect.stringContaining(file) });
} finally {
rmSync(dir, { recursive: true, force: true });
}
},
);
it("keeps a plain reason, its line breaks included, exactly as before", async () => {
const errors = vi.spyOn(console, "error").mockImplementation(() => undefined);
const facesIn = vi.fn<FaceFinder>(async () => {
throw new Error("ffmpeg cannot read /project/take.mp4:\nInvalid data found");
});
await findTextOverFace([candidate()], facesIn);
expect(errors).toHaveBeenCalledWith(
"[hyperframes] check: text over a face was not looked for in 1 of 1 video(s): ffmpeg cannot read /project/take.mp4:\nInvalid data found",
);
});
// fails without the fix: an error text the decoder wrote reached stderr with its ESC raw
it("escapes control characters in the error text as well as the file name", async () => {
const errors = vi.spyOn(console, "error").mockImplementation(() => undefined);
const facesIn = vi.fn<FaceFinder>(async () => {
throw new Error(`decoder said ${ESC}[31mred${BEL}`);
});
await findTextOverFace([candidate()], facesIn);
expect(String(errors.mock.calls[0]?.[0])).toBe(
"[hyperframes] check: text over a face was not looked for in 1 of 1 video(s): decoder said \\x1b[31mred\\x07",
);
});
});
describe.skipIf(!findFFprobe())("findTextOverFace on a source the time limit stops", () => {
afterEach(() => {
stalled.file = "";
+4 -1
View File
@@ -7,6 +7,7 @@ import type {
FaceCheck,
TextOverVideoCandidate,
} from "./checkTypes.js";
import { terminalLines } from "@hyperframes/core/terminal-text";
import { normalizeErrorMessage } from "./errorMessage.js";
/** Below this share of the face a descender or a letter's corner touches it, which hides nothing. */
@@ -190,7 +191,9 @@ export async function findTextOverFace(
const reason = unread[0];
if (reason !== undefined) {
console.error(
`[hyperframes] check: text over a face was not looked for in ${unread.length} of ${timesByFile.size} video(s): ${reason}`,
terminalLines(
`[hyperframes] check: text over a face was not looked for in ${unread.length} of ${timesByFile.size} video(s): ${reason}`,
),
);
if (faces.size === 0) return { issues: [], faceCheck: { ran: false, reason } };
}