Files
hyperframes/packages/engine/src/utils/ffmpegBinaries.test.ts
T
Miguel Angel Simon Sierra 88c049f525 refactor(parsers): single shared FFmpeg/FFprobe binary resolver
The cli, engine, and lint packages each carried their own copy of the
ffmpeg/ffprobe lookup, annotated fallow-ignore code-duplication, and the
copies had drifted: the engine copy handled Windows PATHEXT and executed
which/where without a shell but lacked the Homebrew-dirs fallback for
GUI-spawned processes; the cli copy had the opposite. One resolver in
@hyperframes/parsers (the dependency-graph bottom) now carries the union
of both hardenings, and all three packages delegate to it. Every
consumer gets strictly more robust resolution; env-override semantics
per call site are preserved via configuredMustExist.
2026-07-16 18:36:40 -04:00

54 lines
2.0 KiB
TypeScript

import { resolve } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
assertConfiguredFfmpegBinariesExist,
getFfmpegBinary,
getFfprobeBinary,
} from "./ffmpegBinaries.js";
describe("ffmpeg binary env resolution", () => {
const originalFfmpegPath = process.env.HYPERFRAMES_FFMPEG_PATH;
const originalFfprobePath = process.env.HYPERFRAMES_FFPROBE_PATH;
const originalPath = process.env.PATH;
afterEach(() => {
vi.resetModules();
vi.doUnmock("child_process");
if (originalFfmpegPath === undefined) delete process.env.HYPERFRAMES_FFMPEG_PATH;
else process.env.HYPERFRAMES_FFMPEG_PATH = originalFfmpegPath;
if (originalFfprobePath === undefined) delete process.env.HYPERFRAMES_FFPROBE_PATH;
else process.env.HYPERFRAMES_FFPROBE_PATH = originalFfprobePath;
if (originalPath === undefined) delete process.env.PATH;
else process.env.PATH = originalPath;
});
it("uses configured absolute paths when env vars are set", () => {
process.env.HYPERFRAMES_FFMPEG_PATH = "/tools/ffmpeg.exe";
process.env.HYPERFRAMES_FFPROBE_PATH = "/tools/ffprobe.exe";
expect(getFfmpegBinary()).toBe(resolve("/tools/ffmpeg.exe"));
expect(getFfprobeBinary()).toBe(resolve("/tools/ffprobe.exe"));
});
it("throws a clear error when a configured FFmpeg path is missing", () => {
process.env.HYPERFRAMES_FFMPEG_PATH = "/missing/ffmpeg.exe";
expect(() => assertConfiguredFfmpegBinariesExist()).toThrow(
/FFmpeg binary not found at HYPERFRAMES_FFMPEG_PATH/,
);
});
it("accepts existing configured paths", () => {
process.env.HYPERFRAMES_FFMPEG_PATH = process.execPath;
process.env.HYPERFRAMES_FFPROBE_PATH = process.execPath;
expect(() => assertConfiguredFfmpegBinariesExist()).not.toThrow();
});
it("calls out a mangled replacement character in configured binary paths", () => {
process.env.HYPERFRAMES_FFMPEG_PATH = "/missing/ffmpeg.exe";
expect(() => assertConfiguredFfmpegBinariesExist()).toThrow(/replacement character|mangled/i);
});
});