diff --git a/packages/cli/src/commands/check.test.ts b/packages/cli/src/commands/check.test.ts index 7e691afbce..b23ff13bce 100644 --- a/packages/cli/src/commands/check.test.ts +++ b/packages/cli/src/commands/check.test.ts @@ -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); diff --git a/packages/cli/src/commands/check.ts b/packages/cli/src/commands/check.ts index e3acde2790..b11f02dc32 100644 --- a/packages/cli/src/commands/check.ts +++ b/packages/cli/src/commands/check.ts @@ -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); } diff --git a/packages/cli/src/printedFailureText.wiring.test.ts b/packages/cli/src/printedFailureText.wiring.test.ts index 0776c9c89e..10ce55513f 100644 --- a/packages/cli/src/printedFailureText.wiring.test.ts +++ b/packages/cli/src/printedFailureText.wiring.test.ts @@ -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): 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): 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"]); }); diff --git a/packages/cli/src/utils/checkBrowser.test.ts b/packages/cli/src/utils/checkBrowser.test.ts index 95f4a2c5b4..1c04b07fbc 100644 --- a/packages/cli/src/utils/checkBrowser.test.ts +++ b/packages/cli/src/utils/checkBrowser.test.ts @@ -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((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, ""); + 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({ diff --git a/packages/cli/src/utils/checkBrowser.ts b/packages/cli/src/utils/checkBrowser.ts index 282106e780..3548bb81ff 100644 --- a/packages/cli/src/utils/checkBrowser.ts +++ b/packages/cli/src/utils/checkBrowser.ts @@ -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);