fix(cli): show copy file names in check progress lines as visible text (#8407)

The still-copying heartbeat that check prints while it makes
browser-playable copies now passes the video's file name through
terminalText, so control characters show as escapes and the line stays
on one line. check --prepare-media prints a failed file's name the same
way, while the reason keeps its own lines.

The printed-text wiring test now also covers the media-copy progress
lines in checkBrowser.ts.
This commit is contained in:
Michael Wang
2026-11-21 23:03:59 +00:00
committed by GitHub
parent 08bd7fc126
commit 4a5a5eb27e
5 changed files with 102 additions and 6 deletions
+12
View File
@@ -478,6 +478,18 @@ describe("check --prepare-media", () => {
consumeCommandResult();
});
it("keeps a failed media file's name on its line and the reason's own lines", async () => {
const { log } = await runPrepare(
[{ file: "a\nb.mov", state: "failed", reason: "ffmpeg: bad\nsecond line" }],
["--prepare-media"],
);
expect(log.mock.calls.map(([line]) => String(line))).toContain(
" a\\x0ab.mov: ffmpeg: bad\nsecond line",
);
consumeCommandResult();
});
it("prints snapshot paths 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);
+2 -1
View File
@@ -491,7 +491,8 @@ async function runPrepareMedia(
console.log(
`${mark} Browser-playable copies: ${files.length - failed.length}/${files.length} ready`,
);
for (const file of failed) console.log(terminalLines(` ${file.file}: ${file.reason}`));
for (const file of failed)
console.log(` ${terminalText(file.file)}: ${terminalLines(file.reason ?? "")}`);
}
setCommandExitCode(failed.length === 0 ? 0 : 1);
}
@@ -149,8 +149,11 @@ const handsOverAHelper = (node: ts.Node) =>
ts.isCallExpression(node) &&
node.arguments.some((each) => ts.isIdentifier(each) && SHOWS_TEXT_AS_WRITTEN.has(each.text));
const countOf = (node: ts.Node) =>
ts.isPropertyAccessExpression(node) && node.name.text === "length";
function readsAnyValue(node: ts.Node, written: Set<string>): boolean {
if (shownAsWritten(node) || handsOverAHelper(node)) return false;
if (shownAsWritten(node) || handsOverAHelper(node) || countOf(node)) return false;
if (ts.isConditionalExpression(node))
return readsAnyValue(node.whenTrue, written) || readsAnyValue(node.whenFalse, written);
if (ts.isIdentifier(node))
@@ -161,7 +164,24 @@ function readsAnyValue(node: ts.Node, written: Set<string>): boolean {
return !!ts.forEachChild(node, (child) => readsAnyValue(child, written) || undefined);
}
function valuesPrintedAsTheyCame(name: string, text: string, writtenByCli: string[]): string[] {
function functionsNamed(file: ts.SourceFile, names: readonly string[]): ts.Node[] {
const found: ts.FunctionDeclaration[] = [];
const visit = (node: ts.Node): void => {
if (ts.isFunctionDeclaration(node) && node.name && names.includes(node.name.text))
found.push(node);
ts.forEachChild(node, visit);
};
visit(file);
expect(found.map((each) => each.name?.text).sort()).toEqual([...names].sort());
return found;
}
function valuesPrintedAsTheyCame(
name: string,
text: string,
writtenByCli: string[],
within?: readonly string[],
): string[] {
const file = ts.createSourceFile(name, text, ts.ScriptTarget.Latest, true);
const written = new Set(writtenByCli);
const found: string[] = [];
@@ -174,7 +194,7 @@ function valuesPrintedAsTheyCame(name: string, text: string, writtenByCli: strin
found.push(`${name}:${file.getLineAndCharacterOfPosition(node.getStart()).line + 1}`);
ts.forEachChild(node, visit);
};
visit(file);
for (const root of within ? functionsNamed(file, within) : [file]) visit(root);
return found;
}
@@ -185,6 +205,28 @@ it("prints a value in the files that run before a command only through the text
expect(sites).toEqual([]);
});
const MEDIA_COPY_PRINTERS = ["startCopyHeartbeat", "preResolveHostileMediaProxies"];
const MEDIA_COPY_NAMES_WRITTEN_BY_CLI = [
"Date",
"Math",
"done",
"doneSeconds",
"elapsedText",
"finished",
"settled",
"startedAt",
"toMake",
"total",
];
it("prints the media-copy progress lines only through the text helpers", () => {
const name = "utils/checkBrowser.ts";
const text = readFileSync(join(SRC, name), "utf8");
expect(
valuesPrintedAsTheyCame(name, text, MEDIA_COPY_NAMES_WRITTEN_BY_CLI, MEDIA_COPY_PRINTERS),
).toEqual([]);
});
it("finds a value printed as it came in a file that runs before a command", () => {
const found = valuesPrintedAsTheyCame(
"sample.ts",
@@ -195,8 +237,10 @@ it("finds a value printed as it came in a file that runs before a command", () =
"console.error(build(terminalText));",
"console.error(short ? terminalText(text) : text);",
"console.log(JSON.stringify({ error: text }));",
"console.error(`${files.length} copies; ${files[0].file} first`);",
"console.error(`${files.length} copies`);",
].join("\n"),
["group"],
);
expect(found).toEqual(["sample.ts:1", "sample.ts:5"]);
expect(found).toEqual(["sample.ts:1", "sample.ts:5", "sample.ts:7"]);
});
@@ -1705,6 +1705,45 @@ describe("preResolveHostileMediaProxies", () => {
}
});
it("shows control characters in a copy's file name as visible escapes, on one line", async () => {
vi.useFakeTimers();
try {
const projectDir = mkProjectDir();
// Built rather than written: a literal control character in the source is a lint error.
const esc = String.fromCharCode(27);
mocks.scanProjectMediaCodecMap.mockResolvedValue({
[`/clip${esc}[2J\nx.mov`]: {
codecName: "hevc",
browserHostile: true,
representativeMime: null,
hasAlpha: false,
},
});
let finish: (() => void) | undefined;
mocks.resolveProxy.mockImplementation(
() => new Promise<string>((done) => (finish = () => done("/cache/clip.mp4"))),
);
mocks.proxyProgress.feed = (report) => report(0, { doneSeconds: 30, totalSeconds: 120 });
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined);
const pending = preResolveHostileMediaProxies(projectDir, "<html></html>");
await vi.advanceTimersByTimeAsync(10_000);
mocks.proxyProgress.feed = undefined;
finish?.();
await pending;
const heartbeat = errorSpy.mock.calls
.map(([line]) => String(line))
.filter((line) => line.startsWith("[hyperframes] making browser-playable copies:"));
expect(heartbeat).toEqual([
"[hyperframes] making browser-playable copies: 0 of 1 done. clip\\x1b[2J\\x0ax.mov: 25% (10s so far)",
]);
} finally {
mocks.proxyProgress.feed = undefined;
vi.useRealTimers();
}
});
it("copies only the stretch of a long video the composition plays", async () => {
const projectDir = mkProjectDir();
mocks.scanProjectMediaCodecMap.mockResolvedValue({
+1 -1
View File
@@ -187,7 +187,7 @@ function startCopyHeartbeat(
? `${Math.min(100, Math.floor((doneSeconds / totalSeconds) * 100))}%`
: "";
console.error(
`[hyperframes] making browser-playable copies: ${finished} of ${total} done. ${sources[index]!.file}: ${done || `${Math.floor(doneSeconds)}s done`} (${elapsedText(Date.now() - startedAt)} so far)`,
`[hyperframes] making browser-playable copies: ${finished} of ${total} done. ${terminalText(sources[index]!.file)}: ${done || `${Math.floor(doneSeconds)}s done`} (${elapsedText(Date.now() - startedAt)} so far)`,
);
}
}, COPY_HEARTBEAT_MS);