diff --git a/packages/cultmesh-ts/test/realtime-quic-consumer.test.ts b/packages/cultmesh-ts/test/realtime-quic-consumer.test.ts index 9b3104a9..8118d5a8 100644 --- a/packages/cultmesh-ts/test/realtime-quic-consumer.test.ts +++ b/packages/cultmesh-ts/test/realtime-quic-consumer.test.ts @@ -39,8 +39,11 @@ import { } from "../src/realtime-quic"; import { encodeRealtimeFrame, type CultMeshRealtimeFrame } from "../src/realtime-wire"; -const FIXTURE_P12 = join(__dirname, "fixtures", "quic-test.p12"); -const FIXTURE_DER = join(__dirname, "fixtures", "quic-test-cert.der"); +// __dirname at runtime is dist-test/test; fixtures are binary and are never +// compiled/copied there, so they are read from their source location, two +// levels up. +const FIXTURE_P12 = join(__dirname, "..", "..", "test", "fixtures", "quic-test.p12"); +const FIXTURE_DER = join(__dirname, "..", "..", "test", "fixtures", "quic-test-cert.der"); function nativeBridgeAvailable(): boolean { const dir = process.env.CULTMESH_QUIC_NATIVE_DIR; @@ -68,9 +71,18 @@ class RawQuicListener { static async open(): Promise { const runtime = await CultMeshQuicNativeRuntime.open(); - const pkcs12 = readFileSync(FIXTURE_P12); - const { listenerId, boundPort } = runtime.listenerOpen("127.0.0.1", 0, pkcs12, ""); - return new RawQuicListener(runtime, listenerId, boundPort); + try { + const pkcs12 = readFileSync(FIXTURE_P12); + const { listenerId, boundPort } = runtime.listenerOpen("127.0.0.1", 0, pkcs12, ""); + return new RawQuicListener(runtime, listenerId, boundPort); + } catch (error) { + // A runtime opened above and never handed to a caller would otherwise + // leak: the shared runtime's refcount never reaches zero, its MsQuic + // registration and worker threads never tear down, and a process that + // hits this on every one of several tests never exits on its own. + await runtime.release(); + throw error; + } } /** Waits for one inbound connection and returns its native connection id. */ diff --git a/packages/cultmesh-ts/test/realtime-quic-native.test.ts b/packages/cultmesh-ts/test/realtime-quic-native.test.ts index ebde8eea..8646fbe1 100644 --- a/packages/cultmesh-ts/test/realtime-quic-native.test.ts +++ b/packages/cultmesh-ts/test/realtime-quic-native.test.ts @@ -26,7 +26,10 @@ import { CULTMESH_QUIC_STREAM_RELIABLE, } from "../src/realtime-quic-native"; -const FIXTURE_P12 = join(__dirname, "fixtures", "quic-test.p12"); +// __dirname at runtime is dist-test/test; fixtures are binary and are never +// compiled/copied there, so they are read from their source location, two +// levels up. +const FIXTURE_P12 = join(__dirname, "..", "..", "test", "fixtures", "quic-test.p12"); function nativeBridgeAvailable(): boolean { const dir = process.env.CULTMESH_QUIC_NATIVE_DIR; @@ -140,11 +143,14 @@ test("negative grep: no koffi callbacks, .async only on nextEvent", () => { // __dirname at runtime is dist-test/test; the source lives two levels up, // in src/, since only .js output is mirrored under dist-test. const source = readFileSync(join(__dirname, "..", "..", "src", "realtime-quic-native.ts"), "utf8"); - const asyncUses = [...source.matchAll(/\.async\(/g)]; - assert.ok(asyncUses.length > 0, "expected at least one .async( use for nextEvent"); + // `.async` is referenced (not necessarily called with a literal "(" at the + // reference site: it is handed to `promisify`, which calls it) only for + // `nextEvent`, the ABI's single blocking export. + const asyncUses = [...source.matchAll(/\.async\b/g)]; + assert.ok(asyncUses.length > 0, "expected at least one .async use for nextEvent"); for (const match of asyncUses) { const before = source.slice(Math.max(0, match.index! - 40), match.index!); - assert.match(before, /nextEvent/, "the only .async( call site must be nextEvent"); + assert.match(before, /nextEvent/i, "the only .async reference must be nextEvent"); } assert.doesNotMatch(source, /koffi\.register/, "no koffi callbacks"); });