browser audio processing phase 1
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { BrowserSubmissionProcessor } from "../src/scripts/browser-submission-processor.js";
|
||||
|
||||
const file = { type: "audio/wav", size: 64 };
|
||||
|
||||
test("disabled beta returns the original file without loading policy", async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = () => { throw new Error("fetch must not run"); };
|
||||
try {
|
||||
const processor = new BrowserSubmissionProcessor({ browserProcessingBeta: false });
|
||||
assert.equal(processor.isEnabled(), false);
|
||||
assert.equal(processor.canProcess(file), false);
|
||||
assert.deepEqual(await processor.prepare(file), { file, metadata: null });
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test("enabled shell checks current server policy and never claims processing occurred", 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 });
|
||||
const result = await processor.prepare(file);
|
||||
assert.equal(result.file, file);
|
||||
assert.equal(result.metadata.browser_processing_used, false);
|
||||
assert.equal(result.metadata.browser_gate_result, "unavailable");
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
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 });
|
||||
try {
|
||||
globalThis.fetch = async () => ({ ok: true, json: async () => ({ browser_processing_beta_enabled: false, version: 1 }) });
|
||||
assert.deepEqual(await processor.prepare(file), { file, metadata: null });
|
||||
globalThis.fetch = async () => { throw new Error("offline"); };
|
||||
assert.deepEqual(await processor.prepare(file), { file, metadata: null });
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user