browser audio detection phase 4
This commit is contained in:
@@ -10,6 +10,7 @@ test("disabled beta returns the original file without loading policy", async ()
|
||||
globalThis.fetch = () => { throw new Error("fetch must not run"); };
|
||||
try {
|
||||
const processor = new BrowserSubmissionProcessor({ browserProcessingBeta: false });
|
||||
processor.setEnabled(true);
|
||||
assert.equal(processor.isEnabled(), false);
|
||||
assert.equal(processor.canProcess(file), false);
|
||||
assert.deepEqual(await processor.prepare(file), { file, metadata: null, gate: "unavailable" });
|
||||
@@ -23,6 +24,7 @@ test("enabled shell checks current server policy and never claims processing occ
|
||||
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 });
|
||||
processor.setEnabled(true);
|
||||
const result = await processor.prepare(file);
|
||||
assert.equal(result.file, file);
|
||||
assert.equal(result.metadata.browser_processing_used, false);
|
||||
@@ -35,6 +37,7 @@ test("enabled shell checks current server policy and never claims processing occ
|
||||
test("admin-disabled policy and fetch failure both fall back to the original file", async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const processor = new BrowserSubmissionProcessor({ browserProcessingBeta: true, policyUrl: "/browser-policy/", policyVersion: 1 });
|
||||
processor.setEnabled(true);
|
||||
try {
|
||||
globalThis.fetch = async () => ({ ok: true, json: async () => ({ browser_processing_beta_enabled: false, version: 1 }) });
|
||||
assert.deepEqual(await processor.prepare(file), { file, metadata: null, gate: "unavailable" });
|
||||
@@ -55,6 +58,7 @@ test("video routing is gated and audio never invokes FFmpeg", async () => {
|
||||
async () => { calls += 1; return new File(["wav"], "clip.wav", { type: "audio/wav" }); },
|
||||
{ prepareAudio: async () => new Float32Array(16000), classify: async () => [{ class: "Fireworks", score: .9 }] },
|
||||
);
|
||||
processor.setEnabled(true);
|
||||
await processor.prepare(file);
|
||||
assert.equal(calls, 0);
|
||||
const video = { type: "video/mp4", size: 123, name: "clip.mp4" };
|
||||
@@ -77,8 +81,32 @@ test("video conversion failure rejects instead of falling back to original video
|
||||
{ browserProcessingBeta: true, policyUrl: "/browser-policy/", policyVersion: 1 },
|
||||
async () => { throw new Error("decode failed"); },
|
||||
);
|
||||
processor.setEnabled(true);
|
||||
await assert.rejects(processor.prepare({ type: "video/mp4", name: "bad.mp4" }), /decode failed/);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
test("admin ON and user toggle OFF bypasses policy, FFmpeg and TensorFlow", async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = () => { throw new Error("policy must not load"); };
|
||||
const audio = new File(["audio"], "clip.wav", { type: "audio/wav" });
|
||||
const processor = new BrowserSubmissionProcessor(
|
||||
{ browserProcessingBeta: true, policyUrl: "/policy", policyVersion: 1 },
|
||||
async () => { throw new Error("FFmpeg must not load"); },
|
||||
{ prepareAudio: async () => { throw new Error("audio preparation must not run"); },
|
||||
classify: async () => { throw new Error("TensorFlow must not load"); } },
|
||||
);
|
||||
try {
|
||||
assert.equal(processor.isAvailable(), true);
|
||||
assert.equal(processor.isEnabled(), false);
|
||||
assert.deepEqual(await processor.process(audio), { file: audio, metadata: null, gate: "unavailable" });
|
||||
processor.setEnabled(true);
|
||||
assert.equal(processor.isEnabled(), true);
|
||||
processor.setEnabled(false);
|
||||
assert.equal(processor.isEnabled(), false);
|
||||
assert.deepEqual(await processor.process(audio), { file: audio, metadata: null, gate: "unavailable" });
|
||||
} finally { globalThis.fetch = originalFetch; }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user