Better tests and more user feedback while doing transcription; WIP.

This commit is contained in:
Lucas Winther
2026-07-14 14:44:01 +02:00
parent 18acead43c
commit be82ecfe57
19 changed files with 447 additions and 138 deletions
+52
View File
@@ -1,6 +1,7 @@
import { describe, test, expect } from "bun:test";
import {
applyLoadProgress,
deviceAttempts,
initialLoadProgress,
isUiToWorkerMessage,
isWorkerToUiMessage,
@@ -103,6 +104,57 @@ describe("isWorkerToUiMessage", () => {
});
});
describe("deviceAttempts (D-004, D-017)", () => {
test("auto resolves WebNN → WebGPU → WASM when everything is available", () => {
expect(deviceAttempts("auto", { webnn: true, webgpu: true })).toEqual([
"webnn",
"webgpu",
"wasm",
]);
});
test("auto skips backends the probe ruled out, in order", () => {
expect(deviceAttempts("auto", { webnn: false, webgpu: true })).toEqual([
"webgpu",
"wasm",
]);
expect(deviceAttempts("auto", { webnn: true, webgpu: false })).toEqual([
"webnn",
"wasm",
]);
expect(deviceAttempts("auto", { webnn: false, webgpu: false })).toEqual(["wasm"]);
});
test("explicit webgpu falls back to WASM only", () => {
expect(deviceAttempts("webgpu", { webnn: true, webgpu: true })).toEqual([
"webgpu",
"wasm",
]);
expect(deviceAttempts("webgpu", { webnn: true, webgpu: false })).toEqual(["wasm"]);
});
test("explicit webnn falls back to WASM only (no WebGPU detour)", () => {
expect(deviceAttempts("webnn", { webnn: true, webgpu: true })).toEqual([
"webnn",
"wasm",
]);
expect(deviceAttempts("webnn", { webnn: false, webgpu: true })).toEqual(["wasm"]);
});
test("wasm is honored as-is and every chain ends in WASM", () => {
expect(deviceAttempts("wasm", { webnn: true, webgpu: true })).toEqual(["wasm"]);
for (const preference of ["auto", "webnn", "webgpu", "wasm"] as const) {
for (const webnn of [true, false]) {
for (const webgpu of [true, false]) {
const attempts = deviceAttempts(preference, { webnn, webgpu });
expect(attempts.length).toBeGreaterThan(0);
expect(attempts.at(-1)).toBe("wasm");
}
}
}
});
});
describe("applyLoadProgress", () => {
test("tracks per-file byte progress without mutating previous state", () => {
const p1: LoadProgressMessage = { type: "load-progress", status: "initiate", file: "a.onnx" };