|
| 1 | +import test from "brittle"; |
| 2 | +import path from "node:path"; |
| 3 | +import { fileURLToPath } from "node:url"; |
| 4 | + |
| 5 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 6 | +const nativeLoadErrorMarker = "QVAC_REPRO_NATIVE_LOAD_ERROR"; |
| 7 | + |
| 8 | +function collectErrorDetails(error: Error | undefined) { |
| 9 | + if (!error) return ""; |
| 10 | + |
| 11 | + const cause = (error as { cause?: unknown }).cause; |
| 12 | + const causeMessage = cause instanceof Error ? cause.message : ""; |
| 13 | + return `${error.message}\n${causeMessage}`; |
| 14 | +} |
| 15 | + |
| 16 | +test("loadModel() startup failure includes worker stderr in RPC init error cause", async function (t) { |
| 17 | + t.timeout(15_000); |
| 18 | + |
| 19 | + process.env["QVAC_WORKER_PATH"] = path.resolve( |
| 20 | + __dirname, |
| 21 | + "fixtures/native-load-failure-worker.mjs", |
| 22 | + ); |
| 23 | + |
| 24 | + const { loadModel } = await import("@/client/api/load-model"); |
| 25 | + const { close } = await import("@/client/rpc/rpc-client"); |
| 26 | + |
| 27 | + t.teardown(async () => { |
| 28 | + try { |
| 29 | + await close(); |
| 30 | + } catch {} |
| 31 | + delete process.env["QVAC_WORKER_PATH"]; |
| 32 | + }); |
| 33 | + |
| 34 | + let startupError: Error | undefined; |
| 35 | + try { |
| 36 | + await loadModel({ |
| 37 | + modelSrc: "/tmp/qvac-repro-model.gguf", |
| 38 | + modelType: "llamacpp-completion", |
| 39 | + }); |
| 40 | + t.fail("loadModel() resolved unexpectedly - expected worker startup failure"); |
| 41 | + } catch (error) { |
| 42 | + startupError = error as Error; |
| 43 | + } |
| 44 | + |
| 45 | + t.ok(startupError, "expected loadModel() to reject"); |
| 46 | + t.is( |
| 47 | + (startupError as { name?: string } | undefined)?.name, |
| 48 | + "RPC_INIT_TIMEOUT", |
| 49 | + `expected RPC_INIT_TIMEOUT, got name=${(startupError as { name?: string } | undefined)?.name}`, |
| 50 | + ); |
| 51 | + t.ok( |
| 52 | + collectErrorDetails(startupError).includes(nativeLoadErrorMarker), |
| 53 | + "expected SDK error details to include worker stderr", |
| 54 | + ); |
| 55 | +}); |
0 commit comments