fix(producer): pass streaming encoder config (#1147)

This commit is contained in:
kshift
2026-06-01 11:15:44 -04:00
committed by GitHub
parent 9ead3a83b5
commit 00dad396db
2 changed files with 89 additions and 0 deletions
@@ -0,0 +1,88 @@
import { describe, expect, it, mock } from "bun:test";
type MinimalEngineConfig = {
forceScreenshot: boolean;
ffmpegStreamingTimeout: number;
};
const writeFrame = mock((_buffer: Buffer) => true);
const closeEncoder = mock(async () => ({ success: true, durationMs: 123, fileSize: 42 }));
const spawnStreamingEncoder = mock(async () => ({
writeFrame,
close: closeEncoder,
getExitStatus: () => "success",
}));
mock.module("@hyperframes/engine", () => ({
captureFrameToBuffer: async () => ({ buffer: Buffer.from("frame"), captureTimeMs: 1 }),
closeCaptureSession: async () => {},
createCaptureSession: async () => ({ isInitialized: false, browserConsoleBuffer: [] }),
createFrameReorderBuffer: () => ({
waitForFrame: async () => {},
advanceTo: () => {},
}),
distributeFrames: () => [],
executeParallelCapture: async () => {},
initializeSession: async (session: { isInitialized: boolean }) => {
session.isInitialized = true;
},
prepareCaptureSessionForReuse: () => {},
spawnStreamingEncoder,
}));
mock.module("@hyperframes/core", () => ({
CANVAS_DIMENSIONS: {},
}));
function createInput(cfg: MinimalEngineConfig) {
return {
fileServer: {
url: "http://127.0.0.1:4173",
port: 4173,
close: () => {},
addPreHeadScript: () => {},
},
workDir: "/tmp/hf-test-work",
framesDir: "/tmp/hf-test-frames",
videoOnlyPath: "/tmp/hf-test-video-only.mp4",
job: {
id: "streaming-config-test",
config: { fps: { num: 30, den: 1 }, quality: "draft" },
status: "queued",
progress: 0,
currentStage: "Streaming",
createdAt: new Date(0),
duration: 0,
},
totalFrames: 0,
cfg,
forceScreenshot: false,
log: {
error: () => {},
warn: () => {},
info: () => {},
debug: () => {},
},
workerCount: 1,
probeSession: null,
outputFormat: "mp4",
streamingEncoderOptions: { fps: { num: 30, den: 1 }, width: 1920, height: 1080 },
buildCaptureOptions: () => ({}),
createRenderVideoFrameInjector: () => null,
abortSignal: undefined,
assertNotAborted: () => {},
};
}
describe("runCaptureStreamingStage", () => {
it("passes the resolved engine config to spawnStreamingEncoder", async () => {
const { runCaptureStreamingStage } = await import("./captureStreamingStage.js");
const cfg = { forceScreenshot: false, ffmpegStreamingTimeout: 3_600_000 };
const input = createInput(cfg);
const result = await runCaptureStreamingStage(input);
expect(result.success).toBe(true);
expect(spawnStreamingEncoder.mock.calls[0]?.[3]).toBe(cfg);
});
});
@@ -160,6 +160,7 @@ export async function runCaptureStreamingStage(
videoOnlyPath,
streamingEncoderOptions,
abortSignal,
cfg,
);
assertNotAborted();
} catch (err) {