Skip to content

Write HTML. Render video. Built for agents.

fix: unbreak the regression suite on Windows (PSNR filtergraph escaping + console window popups) (#3839)

Bforbtay9d6ca4585794
diff --git a/packages/core/src/mediaGradeAnalyzer.ts b/packages/core/src/mediaGradeAnalyzer.ts
index 522f68bde3..0d918793e2 100644
--- a/packages/core/src/mediaGradeAnalyzer.ts
+++ b/packages/core/src/mediaGradeAnalyzer.ts
@@ -124,7 +124,7 @@ function probeMedia(mediaPath: string, ffprobePath: string): GradeMediaProbe {
"--",
mediaPath,
],
- { encoding: "utf8", timeout: 5_000, stdio: ["ignore", "pipe", "pipe"] },
+ { encoding: "utf8", timeout: 5_000, stdio: ["ignore", "pipe", "pipe"], windowsHide: true },
);
const parsed = asRecord(JSON.parse(raw));
const streams = Array.isArray(parsed.streams) ? parsed.streams : [];
@@ -341,6 +341,7 @@ export function analyzeMediaGrade(
encoding: "utf8",
timeout: Number(process.env.HYPERFRAMES_ANALYZE_TIMEOUT_MS) || DEFAULT_TIMEOUT_MS,
stdio: ["ignore", "pipe", "pipe"],
+ windowsHide: true,
},
);
return summarizeMediaTreatmentAnalysis(probe, parseMediaTreatmentSignalStats(raw));
diff --git a/packages/engine/src/services/browserManager.ts b/packages/engine/src/services/browserManager.ts
index 5f26e0e47b..6eda90a05b 100644
--- a/packages/engine/src/services/browserManager.ts
+++ b/packages/engine/src/services/browserManager.ts
@@ -830,6 +830,7 @@ function probeNvidiaVramMb(): number | null {
timeout: 3000,
encoding: "utf-8",
stdio: ["pipe", "pipe", "pipe"],
+ windowsHide: true,
}).trim();
const mb = parseInt(out.split("\n")[0] ?? "", 10);
if (Number.isFinite(mb) && mb > 0) {
diff --git a/packages/engine/src/utils/psnr.ts b/packages/engine/src/utils/psnr.ts
index 675594ec47..389d686d99 100644
--- a/packages/engine/src/utils/psnr.ts
+++ b/packages/engine/src/utils/psnr.ts
@@ -24,7 +24,7 @@ export async function psnrDb(a: Buffer, b: Buffer): Promise<number> {
const { stderr } = await execFileP(
getFfmpegBinary(),
["-hide_banner", "-i", pa, "-i", pb, "-lavfi", "psnr", "-f", "null", "-"],
- { maxBuffer: 4 * 1024 * 1024 },
+ { maxBuffer: 4 * 1024 * 1024, windowsHide: true },
);
const m = /average:(inf|[\d.]+)/.exec(stderr);
if (!m) throw new Error(`psnr parse failed: ${stderr.slice(-300)}`);
diff --git a/packages/engine/src/utils/psnrFilterAvailability.ts b/packages/engine/src/utils/psnrFilterAvailability.ts
index def9e1c5ba..3e1941b29f 100644
--- a/packages/engine/src/utils/psnrFilterAvailability.ts
+++ b/packages/engine/src/utils/psnrFilterAvailability.ts
@@ -52,6 +52,7 @@ async function listFilters(): Promise<string | null> {
const { stdout } = await execFileP(getFfmpegBinary(), ["-hide_banner", "-filters"], {
maxBuffer: 4 * 1024 * 1024,
timeout: 5_000,
+ windowsHide: true,
});
return stdout;
} catch {
diff --git a/packages/producer/src/parity-harness.ts b/packages/producer/src/parity-harness.ts
index e390ac81f8..b0b7eb696f 100644
--- a/packages/producer/src/parity-harness.ts
+++ b/packages/producer/src/parity-harness.ts
@@ -116,7 +116,7 @@ function writeImageDiff(basePath: string, comparePath: string, outputPath: strin
"[0:v][1:v]blend=all_mode=difference",
outputPath,
],
- { stdio: "pipe" },
+ { stdio: "pipe", windowsHide: true },
);
if (ffmpeg.status !== 0) {
const stderr = (ffmpeg.stderr || Buffer.from("")).toString("utf-8");
diff --git a/packages/producer/src/plan-parity-analysis.ts b/packages/producer/src/plan-parity-analysis.ts
index 1d7579fc4c..bc15285ca8 100644
--- a/packages/producer/src/plan-parity-analysis.ts
+++ b/packages/producer/src/plan-parity-analysis.ts
@@ -40,6 +40,7 @@ function requireCommandSuccess(
encoding: "buffer",
maxBuffer,
stdio: ["ignore", "pipe", "pipe"],
+ windowsHide: true,
});
if (result.error) throw result.error;
if (result.status !== 0) {
@@ -218,7 +219,7 @@ async function canonicalPcmAudio(
"s16le",
"-",
],
- { stdio: ["ignore", "pipe", "pipe"] },
+ { stdio: ["ignore", "pipe", "pipe"], windowsHide: true },
);
const hash = createHash("sha256");
const stderr: Buffer[] = [];
diff --git a/packages/producer/src/regression-harness-psnr.test.ts b/packages/producer/src/regression-harness-psnr.test.ts
index 4b9572bbec..b65d6074a3 100644
--- a/packages/producer/src/regression-harness-psnr.test.ts
+++ b/packages/producer/src/regression-harness-psnr.test.ts
@@ -12,7 +12,7 @@
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
import { spawnSync } from "node:child_process";
-import { mkdtempSync, rmSync } from "node:fs";
+import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { frameIndexForCheckpoint, psnrAtCheckpoint, psnrAtFrames } from "./regression-harness.js";
@@ -168,6 +168,18 @@ describe("psnrAtFrames()", () => {
expect([...byFrame.keys()].sort((a, b) => a - b)).toEqual(SAMPLE_FRAMES);
});
+ it("writes its stats file under a temp dir whose path holds filtergraph syntax", () => {
+ const savedTmp = process.env.TMPDIR;
+ try {
+ process.env.TMPDIR = join(workDir, "tmp:with\\backslash, [o'brien];");
+ mkdirSync(process.env.TMPDIR, { recursive: true });
+ expect(psnrAtFrames(referenceVideo, degradedVideo, [0, 59]).size).toBe(2);
+ } finally {
+ if (savedTmp === undefined) delete process.env.TMPDIR;
+ else process.env.TMPDIR = savedTmp;
+ }
+ });
+
it("matches the per-checkpoint ffmpeg method it replaced", () => {
const byFrame = psnrAtFrames(referenceVideo, degradedVideo, SAMPLE_FRAMES);
// Sample across the whole range: the old method's cost grew with frame
diff --git a/packages/producer/src/regression-harness.ts b/packages/producer/src/regression-harness.ts
index 57eee5c9da..555b7520d0 100644
--- a/packages/producer/src/regression-harness.ts
+++ b/packages/producer/src/regression-harness.ts
@@ -539,11 +539,17 @@ function copyFixtureSupportFiles(suite: TestSuite, tempRoot: string): void {
// ── FFmpeg Utilities ─────────────────────────────────────────────────────────
-function runFfmpeg(args: string[], label: string): { stdout: Buffer; stderr: string } {
+function runFfmpeg(
+ args: string[],
+ label: string,
+ cwd?: string,
+): { stdout: Buffer; stderr: string } {
const result = spawnSync("ffmpeg", args, {
+ cwd,
stdio: ["ignore", "pipe", "pipe"],
maxBuffer: 256 * 1024 * 1024,
encoding: "buffer",
+ windowsHide: true,
});
const stderr = result.stderr.toString("utf-8");
if (result.status !== 0) {
@@ -582,6 +588,8 @@ export function frameIndexForCheckpoint(checkpointSec: number, fps: number): num
return Math.max(0, Math.round(checkpointSec * fps));
}
+const STATS_FILE_NAME = "psnr.log";
+
/**
* PSNR for a set of frame indices, in a single ffmpeg pass.
*
@@ -628,12 +636,8 @@ export function psnrAtFrames(
if (wanted.length === 0) return new Map();
const statsDir = mkdtempSync(join(tmpdir(), "hf-psnr-"));
- const statsFile = join(statsDir, "psnr.log");
+ const statsFile = join(statsDir, STATS_FILE_NAME);
try {
- // ffmpeg treats `:` and `\` in filter option values as syntax, so a temp
- // path containing either would break the filtergraph. mkdtemp under
- // tmpdir() does not produce those on POSIX, but escape defensively.
- const escaped = statsFile.replace(/\\/g, "\\\\").replace(/:/g, "\\:");
const selectExpr = wanted.map((frame) => `eq(n\\,${frame})`).join("+");
const stream = (index: number, label: string) =>
`[${index}:v]select='${selectExpr}',settb=1/1,setpts=N[${label}]`;
@@ -643,9 +647,9 @@ export function psnrAtFrames(
"-loglevel",
"error",
"-i",
- renderedVideo,
+ resolve(renderedVideo),
"-i",
- snapshotVideo,
+ resolve(snapshotVideo),
"-filter_complex",
// shortest=1:repeatlast=0 makes framesync stop at the first stream to
// end instead of holding its last frame. Without them, an input that
@@ -656,12 +660,14 @@ export function psnrAtFrames(
// [0,15,45] emit 3 rows under the defaults (row 3 comparing frame 45
// against a repeated frame 15, 16.65 dB) and 2 rows with these set.
`${stream(0, "rv")};${stream(1, "gv")};` +
- `[rv][gv]psnr=shortest=1:repeatlast=0:stats_file=${escaped}`,
+ `[rv][gv]psnr=shortest=1:repeatlast=0:stats_file=${STATS_FILE_NAME}`,
"-f",
"null",
"-",
],
"Checkpoint PSNR",
+ // A bare name in cwd keeps every path out of the filtergraph and its escaping rules.
+ statsDir,
);
const values: number[] = [];
diff --git a/packages/producer/src/services/mediaTypeTestFixtures.ts b/packages/producer/src/services/mediaTypeTestFixtures.ts
index a658c04791..d0fec208b4 100644
--- a/packages/producer/src/services/mediaTypeTestFixtures.ts
+++ b/packages/producer/src/services/mediaTypeTestFixtures.ts
@@ -1,7 +1,9 @@
import { spawnSync } from "node:child_process";
export function synthesizeMediaFixture(args: string[]): void {
- const result = spawnSync("ffmpeg", ["-y", "-hide_banner", "-loglevel", "error", ...args]);
+ const result = spawnSync("ffmpeg", ["-y", "-hide_banner", "-loglevel", "error", ...args], {
+ windowsHide: true,
+ });
if (result.status !== 0) {
throw new Error(`ffmpeg fixture synthesis failed: ${result.stderr.toString().slice(-400)}`);
}
diff --git a/packages/producer/src/services/render/audioPadTrim.ts b/packages/producer/src/services/render/audioPadTrim.ts
index b8481ad2b7..9b834b922b 100644
--- a/packages/producer/src/services/render/audioPadTrim.ts
+++ b/packages/producer/src/services/render/audioPadTrim.ts
@@ -651,7 +651,10 @@ async function runFfprobeJson<T>(args: string[], signal?: AbortSignal): Promise<
if (!args.includes("--")) {
throw new Error('[audioPadTrim] ffprobe args must terminate options with "--".');
}
- const proc = spawn(getFfprobeBinary(), args, { stdio: ["ignore", "pipe", "pipe"] });
+ const proc = spawn(getFfprobeBinary(), args, {
+ stdio: ["ignore", "pipe", "pipe"],
+ windowsHide: true,
+ });
trackChildProcess(proc);
let stdout = "";
proc.stdout.on("data", (data: Buffer) => {
diff --git a/packages/producer/src/utils/audioRegression.ts b/packages/producer/src/utils/audioRegression.ts
index 8017b0298a..2fc3bfc971 100644
--- a/packages/producer/src/utils/audioRegression.ts
+++ b/packages/producer/src/utils/audioRegression.ts
@@ -200,7 +200,7 @@ export function computeAudioResidualRmsDb(
"null",
"-",
],
- { encoding: "utf-8" },
+ { encoding: "utf-8", windowsHide: true },
);
// `spawnSync` swallows `ENOENT`, signal kills, and non-zero exits
@@ -318,7 +318,7 @@ function probeAudioDuration(file: string): { seconds: number; error?: string } {
"--",
file,
],
- { encoding: "utf-8" },
+ { encoding: "utf-8", windowsHide: true },
);
if (proc.error) {
return {