Files
piik/tests/channel-wasm-init.test.ts
T
AAA ce6091a49a fix(core): keep independent operations recoverable
Scope file failures to their requests, preserve accurate route failures and validate Server settings before initialization. Repair source capability and observation lifetimes, restart failed WASM loading, and align playback, input and read-marker state with the owning operation.
2026-11-21 11:15:48 -05:00

24 lines
1.2 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { expect, test, vi } from "vitest";
import { initializeRuntime, createSessionSigner } from "../prototype/channel-browser/src/room-host";
test("concurrent callers share each WASM download and can retry a failed download", async () => {
const error = new TypeError("download interrupted");
const bytes = await readFile("prototype/channel-browser/pkg/piik_channel_browser_bg.wasm");
const fetch = vi.spyOn(globalThis, "fetch").mockRejectedValueOnce(error)
.mockResolvedValueOnce(new Response(new Uint8Array(bytes), { headers: { "Content-Type": "application/wasm" } }));
try {
const first = initializeRuntime();
expect(initializeRuntime()).toBe(first);
await expect(first).rejects.toBe(error);
const retry = initializeRuntime();
expect(initializeRuntime()).toBe(retry);
await retry;
await expect(first).rejects.toBe(error);
expect(initializeRuntime()).toBe(retry);
const signer = await createSessionSigner(new Uint8Array(32));
try { expect(signer.signing_key()).toHaveLength(32); } finally { signer.free(); }
expect(fetch).toHaveBeenCalledTimes(2);
} finally { fetch.mockRestore(); }
});