browser audio detection phase 2

This commit is contained in:
Joren de Graaf
2026-10-02 16:57:12 +02:00
parent df837c240f
commit ff0d78ccba
17 changed files with 334 additions and 10 deletions
@@ -44,3 +44,40 @@ test("admin-disabled policy and fetch failure both fall back to the original fil
globalThis.fetch = originalFetch;
}
});
test("video routing is gated and audio never invokes FFmpeg", async () => {
const originalFetch = globalThis.fetch;
let calls = 0;
globalThis.fetch = async () => ({ ok: true, json: async () => ({ browser_processing_beta_enabled: true, version: 1 }) });
try {
const processor = new BrowserSubmissionProcessor(
{ browserProcessingBeta: true, policyUrl: "/browser-policy/", policyVersion: 1 },
async () => { calls += 1; return new File(["wav"], "clip.wav", { type: "audio/wav" }); },
);
await processor.prepare(file);
assert.equal(calls, 0);
const video = { type: "video/mp4", size: 123, name: "clip.mp4" };
const result = await processor.prepare(video);
assert.equal(calls, 1);
assert.equal(result.file.type, "audio/wav");
assert.equal(result.metadata.browser_processing_used, true);
const disabled = new BrowserSubmissionProcessor({ browserProcessingBeta: false }, async () => { throw new Error("must not run"); });
assert.deepEqual(await disabled.prepare(video), { file: video, metadata: null });
} finally {
globalThis.fetch = originalFetch;
}
});
test("video conversion failure rejects instead of falling back to original video", async () => {
const originalFetch = globalThis.fetch;
globalThis.fetch = async () => ({ ok: true, json: async () => ({ browser_processing_beta_enabled: true, version: 1 }) });
try {
const processor = new BrowserSubmissionProcessor(
{ browserProcessingBeta: true, policyUrl: "/browser-policy/", policyVersion: 1 },
async () => { throw new Error("decode failed"); },
);
await assert.rejects(processor.prepare({ type: "video/mp4", name: "bad.mp4" }), /decode failed/);
} finally {
globalThis.fetch = originalFetch;
}
});