mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-26 00:57:05 +00:00
* 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>
104 lines
4.2 KiB
TypeScript
104 lines
4.2 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const producerMocks = vi.hoisted(() => ({
|
|
loadProducer: vi.fn(async () => ({
|
|
injectDeterministicFontFaces: async (html: string) => `${html}<!--bundled-producer-->`,
|
|
})),
|
|
}));
|
|
|
|
vi.mock("@hyperframes/core/compiler", () => ({
|
|
bundleToSingleHtml: vi.fn(async () => "<html><body>bundled</body></html>"),
|
|
}));
|
|
|
|
vi.mock("./producer.js", () => ({
|
|
loadProducer: producerMocks.loadProducer,
|
|
}));
|
|
|
|
import {
|
|
__resetFontLocalizationWarningsForTests,
|
|
bundleWithLocalizedFonts,
|
|
localizeWithProducer,
|
|
} from "./bundleWithLocalizedFonts.js";
|
|
|
|
afterEach(() => {
|
|
__resetFontLocalizationWarningsForTests();
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe("bundleWithLocalizedFonts (call-site integration)", () => {
|
|
it("runs the injected font localizer over the plain bundle", async () => {
|
|
const localize = vi.fn(async (html: string) => html.replace("bundled", "bundled+fonts"));
|
|
const html = await bundleWithLocalizedFonts("/project", localize);
|
|
expect(localize).toHaveBeenCalledOnce();
|
|
expect(localize).toHaveBeenCalledWith("<html><body>bundled</body></html>");
|
|
expect(html).toBe("<html><body>bundled+fonts</body></html>");
|
|
});
|
|
|
|
it("returns the localizer output verbatim (localization is the last step)", async () => {
|
|
const html = await bundleWithLocalizedFonts("/project", async () => "<html>embedded</html>");
|
|
expect(html).toBe("<html>embedded</html>");
|
|
});
|
|
});
|
|
|
|
describe("localizeWithProducer", () => {
|
|
it("loads the injector through the producer module bundled with the CLI", async () => {
|
|
const out = await localizeWithProducer("<html></html>");
|
|
expect(producerMocks.loadProducer).toHaveBeenCalledOnce();
|
|
expect(out).toBe("<html></html><!--bundled-producer-->");
|
|
});
|
|
|
|
it("embeds fonts when the injector is available", async () => {
|
|
const inject = vi.fn(async (html: string) => `${html}<!--fonts-->`);
|
|
const warn = vi.fn();
|
|
const out = await localizeWithProducer("<html></html>", async () => inject, warn);
|
|
expect(out).toBe("<html></html><!--fonts-->");
|
|
expect(warn).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("fails open silently when producer is unavailable (module absent → null)", async () => {
|
|
const warn = vi.fn();
|
|
const out = await localizeWithProducer("<html>plain</html>", async () => null, warn);
|
|
// Never worse than a plain bundle; benign absence is not a warning.
|
|
expect(out).toBe("<html>plain</html>");
|
|
expect(warn).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("fails open WITH a diagnostic when the injector itself throws", async () => {
|
|
const warn = vi.fn();
|
|
const boom: () => Promise<never> = () => Promise.reject(new Error("fetch layer down"));
|
|
const out = await localizeWithProducer("<html>plain</html>", async () => boom, warn);
|
|
expect(out).toBe("<html>plain</html>");
|
|
expect(warn).toHaveBeenCalledOnce();
|
|
expect(warn.mock.calls[0]?.[0]).toContain("fetch layer down");
|
|
});
|
|
|
|
it("dedups repeated identical injector failures across re-bundles", async () => {
|
|
const warn = vi.fn();
|
|
const boom: () => Promise<never> = () => Promise.reject(new Error("same failure"));
|
|
for (let i = 0; i < 5; i++) {
|
|
await localizeWithProducer("<html></html>", async () => boom, warn);
|
|
}
|
|
// 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");
|
|
});
|
|
});
|