diff --git a/src/adb/AdbProvider.test.ts b/src/adb/AdbProvider.test.ts index e37883926f2..9daed36c88d 100644 --- a/src/adb/AdbProvider.test.ts +++ b/src/adb/AdbProvider.test.ts @@ -726,7 +726,9 @@ exit 1`, captured_output: { stdout: expect.stringContaining("package:") }, }, }); - await expect(readFile(join(root, "pull-ran"))).rejects.toThrow(); + await expect(readFile(join(root, "pull-ran"))).rejects.toMatchObject({ + code: "ENOENT", + }); await expect(lstat(output)).rejects.toMatchObject({ code: "ENOENT" }); }); @@ -766,8 +768,10 @@ it.each([ }, }, }); - await expect(readFile(pullLog)).rejects.toThrow(); - await expect(lstat(packageDirectory)).rejects.toThrow(); + await expect(readFile(pullLog)).rejects.toMatchObject({ code: "ENOENT" }); + await expect(lstat(packageDirectory)).rejects.toMatchObject({ + code: "ENOENT", + }); return; } if (!result.ok) throw new Error(result.error.message); @@ -1562,7 +1566,9 @@ exit 0`, .message, ).toContain(reason); // No host directory and no adb invocation are effects of a refused pull. - await expect(readFile(join(root, "pull-ran"))).rejects.toThrow(); + await expect(readFile(join(root, "pull-ran"))).rejects.toMatchObject({ + code: "ENOENT", + }); await expect(lstat(output)).rejects.toMatchObject({ code: "ENOENT" }); }, ); @@ -2894,7 +2900,9 @@ sh -c "$*" entries: [], coverage: "complete", }); - await expect(readFile(join(root, "injected"))).rejects.toThrow(); + await expect(readFile(join(root, "injected"))).rejects.toMatchObject({ + code: "ENOENT", + }); }); it("preserves a screen output created while capture is running", async () => { diff --git a/src/artifacts/ArtifactProviderDirectoryCleanup.test.ts b/src/artifacts/ArtifactProviderDirectoryCleanup.test.ts index c299b4021e9..49bf23627a4 100644 --- a/src/artifacts/ArtifactProviderDirectoryCleanup.test.ts +++ b/src/artifacts/ArtifactProviderDirectoryCleanup.test.ts @@ -32,11 +32,18 @@ it("keeps a directory inspection's failed cleanup retryable by the caller's life expect(inspected.ok).toBe(false); if (inspected.ok) return; - expect(inspected.error.cleanupResources?.length ?? 0).toBeGreaterThan(0); + expect(inspected.error.cleanupResources).toEqual([ + `artifact reader for ${root}`, + ]); expect(retained).toHaveLength(1); const [owner] = retained; // The owner stays retained while its cleanup keeps failing. - await expect(owner?.close()).rejects.toThrow(); + await expect(owner!.close()).rejects.toMatchObject({ + reason: "unavailable", + cleanup: expect.objectContaining({ + resources: [`artifact reader for ${root}`], + }), + }); close.mockRestore(); // A later close of the caller's lifetime releases exactly what remained. await expect(owner?.close()).resolves.toBeUndefined(); diff --git a/src/artifacts/ReleaseExposureReader.probeCleanup.test.ts b/src/artifacts/ReleaseExposureReader.probeCleanup.test.ts index 21eb9d126fb..4a61b8a7c62 100644 --- a/src/artifacts/ReleaseExposureReader.probeCleanup.test.ts +++ b/src/artifacts/ReleaseExposureReader.probeCleanup.test.ts @@ -63,7 +63,7 @@ describe("ReleaseExposureReader probe directory cleanup", () => { }); await expect(access(directory)).resolves.toBeUndefined(); await reader.close(); - await expect(access(directory)).rejects.toThrow(); + await expect(access(directory)).rejects.toMatchObject({ code: "ENOENT" }); } finally { vi.mocked(rm).mockImplementation(actual.rm); await reader.close(); diff --git a/src/artifacts/apple/KeyedArchiveReader.test.ts b/src/artifacts/apple/KeyedArchiveReader.test.ts index 2e4a5bc5d6e..64a3a9961d0 100644 --- a/src/artifacts/apple/KeyedArchiveReader.test.ts +++ b/src/artifacts/apple/KeyedArchiveReader.test.ts @@ -299,7 +299,15 @@ describe("inert keyed archive decoding", () => { offset: 0, limit: 1, }), - ).toThrow(); + ).toThrow( + expect.objectContaining({ + _tag: "ParseFailureError", + failure: expect.objectContaining({ + kind: "truncated", + format: "plist", + }), + }), + ); expect(() => decodeKeyedArchiveBytes(Buffer.from(build({ ...archive, $top: {} })), { offset: 0, diff --git a/src/electron/ElectronFuseCleanup.test.ts b/src/electron/ElectronFuseCleanup.test.ts index af9bb00ef13..4c84bbdefd2 100644 --- a/src/electron/ElectronFuseCleanup.test.ts +++ b/src/electron/ElectronFuseCleanup.test.ts @@ -61,7 +61,9 @@ it("retains the exact rejected fuse descriptor until its owner can close it", as expect(result.error.cleanupIncomplete).toBe(true); denyClose = false; await provider.close(); - expect(() => fstatSync(descriptors[0]!)).toThrow(); + expect(() => fstatSync(descriptors[0]!)).toThrow( + expect.objectContaining({ code: "EBADF" }), + ); expect(result.error.cleanupIncomplete).toBe(false); } finally { denyClose = false; @@ -576,7 +578,9 @@ it("releases successful descriptor peers while retaining the failed owner's exac cleanupIncomplete: true, cleanupResources: [paths[1]], }); - expect(() => fstatSync(first.descriptor)).toThrow(); + expect(() => fstatSync(first.descriptor)).toThrow( + expect.objectContaining({ code: "EBADF" }), + ); expect(fstatSync(second.descriptor)).toBeDefined(); expect(results[0]).toMatchObject({ error: { cleanupIncomplete: false, cleanupResources: [] }, @@ -593,7 +597,9 @@ it("releases successful descriptor peers while retaining the failed owner's exac expect(results[1]).toMatchObject({ error: { cleanupIncomplete: false, cleanupResources: [] }, }); - expect(() => fstatSync(second.descriptor)).toThrow(); + expect(() => fstatSync(second.descriptor)).toThrow( + expect.objectContaining({ code: "EBADF" }), + ); } finally { for (const control of controls.values()) { control.allowed = true; diff --git a/src/evm/EvmoleInterfaceAdapter.test.ts b/src/evm/EvmoleInterfaceAdapter.test.ts index 38615c8bec6..963b5ebe6a0 100644 --- a/src/evm/EvmoleInterfaceAdapter.test.ts +++ b/src/evm/EvmoleInterfaceAdapter.test.ts @@ -63,19 +63,42 @@ it("admits reported metadata and the binding's disabled undefined facets", () => ).toEqual([]); }); it.each([ - { storage: [] }, - { functions: [{ selector: "bad", bytecodeOffset: 0, dispatch: "abi" }] }, - { - functions: [{ selector: "aabbccdd", bytecodeOffset: -1, dispatch: "abi" }], - }, - { metadata: {} }, - { - metadata: { - bytecodeOffset: 1, - cborLength: 4, - entries: [{ key: "reported", value: { type: "integer", value: 1.5 } }], + [{ storage: [] }, ["storage"], "invalid_type"], + [ + { functions: [{ selector: "bad", bytecodeOffset: 0, dispatch: "abi" }] }, + ["functions", 0, "selector"], + "invalid_format", + ], + [ + { + functions: [ + { selector: "aabbccdd", bytecodeOffset: -1, dispatch: "abi" }, + ], }, + ["functions", 0, "bytecodeOffset"], + "too_small", + ], + [{ metadata: {} }, ["metadata", "bytecodeOffset"], "invalid_type"], + [ + { + metadata: { + bytecodeOffset: 1, + cborLength: 4, + entries: [{ key: "reported", value: { type: "integer", value: 1.5 } }], + }, + }, + ["metadata", "entries", 0, "value", "value"], + "custom", + ], +] as const)( + "rejects producer representations outside the selected profile", + (raw, path, code) => { + expect(() => evmoleInterfaceReplySchema.parse(raw)).toThrow( + expect.objectContaining({ + issues: expect.arrayContaining([ + expect.objectContaining({ path, code }), + ]), + }), + ); }, -])("rejects producer representations outside the selected profile", (raw) => { - expect(() => evmoleInterfaceReplySchema.parse(raw)).toThrow(); -}); +); diff --git a/src/firmware/FirmwareDeadline.test.ts b/src/firmware/FirmwareDeadline.test.ts index 13e95a16365..4d5dbde2cde 100644 --- a/src/firmware/FirmwareDeadline.test.ts +++ b/src/firmware/FirmwareDeadline.test.ts @@ -37,7 +37,13 @@ it.each(["inspect_firmware_regions", "extract_firmware"] as const)( value, ); for (const value of [0, -1, 0.5, 2_147_483_648, null, "120000"]) - expect(() => parse({ analysis_timeout_ms: value })).toThrow(); + expect(() => parse({ analysis_timeout_ms: value })).toThrow( + expect.objectContaining({ + issues: [ + expect.objectContaining({ path: ["input", "analysis_timeout_ms"] }), + ], + }), + ); }, ); @@ -82,7 +88,15 @@ it("defaults and preserves the caller's publication budget at the shared contrac publication_timeout_ms: 345_678, }); for (const value of [0, -1, 0.5, 2_147_483_648, null, "120000"]) - expect(() => parse({ publication_timeout_ms: value })).toThrow(); + expect(() => parse({ publication_timeout_ms: value })).toThrow( + expect.objectContaining({ + issues: [ + expect.objectContaining({ + path: ["input", "publication_timeout_ms"], + }), + ], + }), + ); }); /** A selected-file read that the phase signal cancelled with `reason`. */ diff --git a/src/ghidra/GhidraCheckpoint.test.ts b/src/ghidra/GhidraCheckpoint.test.ts index c161499e7ab..043f1aa6f3d 100644 --- a/src/ghidra/GhidraCheckpoint.test.ts +++ b/src/ghidra/GhidraCheckpoint.test.ts @@ -396,7 +396,7 @@ it.skipIf(process.platform === "win32")( }); await expect( f.owner.publish(await edit(f, "edited"), undefined, forced.signal), - ).rejects.toThrow(); + ).rejects.toMatchObject({ _tag: "AnalysisCancelledError" }); expect(await readFile(manifest, "utf8")).toBe(committed); // The acquired lease was released by the publication's cleanup. expect(f.owner.hasResources).toBe(false); @@ -736,11 +736,17 @@ it.skipIf(process.platform === "win32")( ); await expect( resolveGhidraCheckpoint(f.root, target, profile, f.resources), - ).rejects.toThrow(); + ).rejects.toMatchObject({ + _tag: "ConfigurationError", + message: expect.stringContaining("the manifest is malformed"), + }); await writeFile(manifestPath, "{"); await expect( resolveGhidraCheckpoint(f.root, target, profile, f.resources), - ).rejects.toThrow(); + ).rejects.toMatchObject({ + _tag: "ConfigurationError", + message: expect.stringContaining("the manifest is malformed"), + }); }, ); @@ -919,7 +925,10 @@ it.skipIf(process.platform === "win32")( }); await expect( f.owner.publish(f.packed, controller.signal), - ).rejects.toThrow(); + ).rejects.toMatchObject({ + name: "ArtifactReaderFailure", + reason: "cancelled", + }); expect(f.owner.observation.source).not.toBeNull(); expect( (await resolveGhidraCheckpoint(f.root, target, profile, f.resources)) @@ -977,7 +986,7 @@ it.skipIf(process.platform === "win32")( ); await expect( access(join(f.root, "selected", selection.key, "current.json")), - ).rejects.toThrow(); + ).rejects.toMatchObject({ code: "ENOENT" }); const alias = await resolveGhidraCheckpoint( join(f.root, "physical", "selected"), target, diff --git a/src/ghidra/GhidraTemporaryDirectory.test.ts b/src/ghidra/GhidraTemporaryDirectory.test.ts index d10918fbac5..46089ee8d5e 100644 --- a/src/ghidra/GhidraTemporaryDirectory.test.ts +++ b/src/ghidra/GhidraTemporaryDirectory.test.ts @@ -97,7 +97,10 @@ describe("Ghidra temporary directory probe", () => { throw new Error("Expected an owned probe awaiting removal"); const { retainedPath } = result; await expect(fs.access(retainedPath)).resolves.toBeUndefined(); - await expect(resources.close()).rejects.toThrow(); + await expect(resources.close()).rejects.toMatchObject({ + reason: "unavailable", + cleanup: expect.objectContaining({ resources: [retainedPath] }), + }); await expect(fs.access(retainedPath)).resolves.toBeUndefined(); if (writeFails) await actual.unlink(retainedPath); await expect(resources.close()).resolves.toBeUndefined(); diff --git a/src/gpu/PtxKernels.test.ts b/src/gpu/PtxKernels.test.ts index 2721ddf9902..bc0065cc1bd 100644 --- a/src/gpu/PtxKernels.test.ts +++ b/src/gpu/PtxKernels.test.ts @@ -235,7 +235,13 @@ it("counts numeric percent-prefixed PTX register names", () => { it.each(["0", "%"])("rejects malformed PTX register identifier %s", (name) => { expect(() => [ ...readPtxKernels(`.entry kernel() { .reg .b32 ${name}; ret; }`, "object"), - ]).toThrow(); + ]).toThrow( + expect.objectContaining({ + _tag: "ParseFailureError", + kind: "malformed", + message: "PTX register declaration has no type or name", + }), + ); }); it("does not round overflowing register totals or accept truncated ranges", () => { for (const declaration of [ @@ -266,16 +272,22 @@ it("retains overlong unsupported register type prefixes within the PTX text", () expect(row!.coverage).toBe("partial"); }); it.each([ - "/* unfinished", - ".entry broken(", - ".entry k", - ".entry k ) { ret; }", - ".entry k() {", - ".entry k() .pragma; { ret; }", - ".entry k() {.reg .u32 %x}", - ".entry k() {.reg %x;}", -])("rejects incomplete PTX %s", (text) => { - expect(() => [...readPtxKernels(text, "object")]).toThrow(); + ["/* unfinished", "Unterminated PTX comment"], + [".entry broken(", "Truncated PTX entry declaration"], + [".entry k", "Truncated PTX entry declaration"], + [".entry k ) { ret; }", "Malformed PTX entry name or parameters"], + [".entry k() {", "Truncated PTX entry declaration"], + [".entry k() .pragma; { ret; }", "Malformed PTX entry pragma"], + [".entry k() {.reg .u32 %x}", "Malformed PTX resource declaration"], + [".entry k() {.reg %x;}", "PTX register declaration has no type or name"], +])("rejects incomplete PTX %s", (text, message) => { + expect(() => [...readPtxKernels(text, "object")]).toThrow( + expect.objectContaining({ + _tag: "ParseFailureError", + kind: "malformed", + message, + }), + ); }); it("does not label unrelated malformed quoted text as a recognized PTX artifact", () => { diff --git a/src/ida/IdaMcpConnection.test.ts b/src/ida/IdaMcpConnection.test.ts index ca5d155d28d..2699f509d1a 100644 --- a/src/ida/IdaMcpConnection.test.ts +++ b/src/ida/IdaMcpConnection.test.ts @@ -815,17 +815,21 @@ it("keeps error, truncation and native-text precedence ahead of structured JSON }); it("requires a valid content array even when IDA supplies structured evidence", () => { - for (const content of [ - "invalid", - undefined, - null, - {}, - [null], - [{ type: "text", text: 42 }], - ]) + for (const [content, path] of [ + ["invalid", ["content"]], + [undefined, ["content"]], + [null, ["content"]], + [{}, ["content"]], + [[null], ["content", 0]], + [[{ type: "text", text: 42 }], ["content", 0, "text"]], + ] as const) expect(() => decodeIdaToolResult({ content, structuredContent: { observed: true } }), - ).toThrow(); + ).toThrow( + expect.objectContaining({ + issues: [expect.objectContaining({ path, code: "invalid_type" })], + }), + ); }); it("selects structured IDA evidence ahead of text while admitting mixed content", () => { @@ -841,13 +845,22 @@ it("selects structured IDA evidence ahead of text while admitting mixed content" content: [image, { type: "text", text: '{"fallback":true}' }], }), ).toEqual({ fallback: true }); - for (const structuredContent of [null, [], "invalid", { observed: Infinity }]) + for (const [structuredContent, path] of [ + [null, ["structuredContent"]], + [[], ["structuredContent"]], + ["invalid", ["structuredContent"]], + [{ observed: Infinity }, []], + ] as const) expect(() => decodeIdaToolResult({ content: [{ type: "text", text: "fallback" }], structuredContent, }), - ).toThrow(); + ).toThrow( + expect.objectContaining({ + issues: [expect.objectContaining({ path, code: "custom" })], + }), + ); expect(() => decodeIdaToolResult({ content: [image] })).toThrow( "empty observation", ); @@ -862,13 +875,24 @@ it("selects structured IDA evidence ahead of text while admitting mixed content" }); it("requires complete native IDA JSON text despite usable structured content", () => { - for (const content of [[], [{ type: "text", text: "plain text" }]]) + for (const [content, refusal] of [ + [[], "Native IDA MCP omitted its complete JSON text result."], + [ + [{ type: "text", text: "plain text" }], + "IDA MCP returned malformed JSON text.", + ], + ] as const) expect(() => decodeIdaToolResult( { content, structuredContent: { observed: true } }, "native", ), - ).toThrow(); + ).toThrow( + expect.objectContaining({ + _tag: "AnalysisProtocolError", + message: refusal, + }), + ); }); const turn = () => new Promise((resolve) => setImmediate(resolve)); diff --git a/src/ida/IdaOperationRunner.test.ts b/src/ida/IdaOperationRunner.test.ts index 0b8ed30949d..e98f5e4074e 100644 --- a/src/ida/IdaOperationRunner.test.ts +++ b/src/ida/IdaOperationRunner.test.ts @@ -28,7 +28,9 @@ it("rejects invalid string addresses before reading and resolves canonical selec await expect( runner.run("list_strings", { address: "invalid" }), - ).rejects.toThrow(); + ).rejects.toMatchObject({ + issues: [expect.objectContaining({ path: [], code: "invalid_format" })], + }); expect(producer.calls).toEqual([]); expect(await runner.run("list_strings", { address: "0X0010" })).toEqual([ { address: "0x10", value: "selected" }, diff --git a/src/javascript/sourceMaps/TraceSourceMap.test.ts b/src/javascript/sourceMaps/TraceSourceMap.test.ts index ab70b23589d..0d30e2d5c01 100644 --- a/src/javascript/sourceMaps/TraceSourceMap.test.ts +++ b/src/javascript/sourceMaps/TraceSourceMap.test.ts @@ -290,12 +290,23 @@ describe("source-map section-boundary candidates", () => { }); describe("source-map layout admission", () => { - it.each(["g", "!", "AA", "D"])( - "rejects malformed VLQ/components: %s", - (mappings) => { - expect(() => trace({ ...leaf, mappings })).toThrow(); - }, - ); + it.each([ + ["g", "Source-map VLQ ends with an unfinished continuation."], + ["!", expect.stringContaining('"mappings"')], + ["AA", "Source-map segment requires one, four or five VLQ components."], + [ + "D", + "Decoded local or absolute position, source index or name index is invalid.", + ], + ])("rejects malformed VLQ/components: %s", (mappings, message) => { + expect(() => trace({ ...leaf, mappings })).toThrow( + expect.objectContaining({ + _tag: "ParseFailureError", + kind: "malformed", + message, + }), + ); + }); it.each([",", ",AAAA", "AAAA,,A", "AAAA,", "AAAA,;A"])( "rejects empty mapping segments around commas: %s", (mappings) => { diff --git a/src/jeb/JebMcpConnection.test.ts b/src/jeb/JebMcpConnection.test.ts index 644e4fedb88..9a58f39142e 100644 --- a/src/jeb/JebMcpConnection.test.ts +++ b/src/jeb/JebMcpConnection.test.ts @@ -120,7 +120,9 @@ it("refuses HTTP redirects before sending requests to another endpoint", async ( new URL(`http://127.0.0.1:${address.port}/mcp`), ); try { - await expect(connection.connect()).rejects.toThrow(); + await expect(connection.connect()).rejects.toThrow( + "JEB MCP catalog failed", + ); expect(followed).toBe(false); } finally { await connection.close(); @@ -245,10 +247,19 @@ it("accepts omitted JEB content only when structured evidence establishes an obs decodeJebToolResult({ structuredContent: { result: "ordinary field" } }), ).toEqual({ result: "ordinary field" }); expect(() => decodeJebToolResult({})).toThrow("empty observation"); - for (const content of [null, {}, [null], [{ type: "text", text: 42 }]]) + for (const [content, path] of [ + [null, ["content"]], + [{}, ["content"]], + [[null], ["content", 0]], + [[{ type: "text", text: 42 }], ["content", 0, "text"]], + ] as const) expect(() => decodeJebToolResult({ content, structuredContent: { success: true } }), - ).toThrow(); + ).toThrow( + expect.objectContaining({ + issues: [expect.objectContaining({ path, code: "invalid_type" })], + }), + ); }); it("selects structured JEB evidence ahead of text while admitting mixed content", () => { @@ -264,13 +275,22 @@ it("selects structured JEB evidence ahead of text while admitting mixed content" content: [image, { type: "text", text: '{"fallback":true}' }], }), ).toEqual({ fallback: true }); - for (const structuredContent of [null, [], "invalid", { observed: Infinity }]) + for (const [structuredContent, path] of [ + [null, ["structuredContent"]], + [[], ["structuredContent"]], + ["invalid", ["structuredContent"]], + [{ observed: Infinity }, []], + ] as const) expect(() => decodeJebToolResult({ content: [{ type: "text", text: "fallback" }], structuredContent, }), - ).toThrow(); + ).toThrow( + expect.objectContaining({ + issues: [expect.objectContaining({ path, code: "custom" })], + }), + ); expect(() => decodeJebToolResult({ content: [image] })).toThrow( "empty observation", ); diff --git a/src/native/metadata/BinaryContainer.test.ts b/src/native/metadata/BinaryContainer.test.ts index 08b774415a3..db8c9d72766 100644 --- a/src/native/metadata/BinaryContainer.test.ts +++ b/src/native/metadata/BinaryContainer.test.ts @@ -284,18 +284,20 @@ it("maps a span crossing adjacent ranges with one consistent file translation", expect(mappedFileOffset(mappings, 102n, 4)).toBe(2); expect(mappedFileOffset(mappings, 108n, 0)).toBe(8); }); -it.each( - [ - [{ address: 105n, offset: 5, size: 3 }], - [{ address: 104n, offset: 7, size: 4 }], - [...mappings, { address: 103n, offset: 7, size: 2 }], - ].map((ranges) => [ranges] as const), -)( +it.each([ + [[{ address: 105n, offset: 5, size: 3 }], "unmapped"], + [[{ address: 104n, offset: 7, size: 4 }], "ambiguous"], + [[...mappings, { address: 103n, offset: 7, size: 2 }], "ambiguous"], +] as const)( "refuses gaps or inconsistent translations across the selected span", - (ranges) => { - expect(() => - mappedFileOffset([mappings[0]!, ...ranges], 102n, 4), - ).toThrow(); + (ranges, reason) => { + expect(() => mappedFileOffset([mappings[0]!, ...ranges], 102n, 4)).toThrow( + expect.objectContaining({ + _tag: "ParseFailureError", + kind: "malformed", + reason, + }), + ); }, ); it("refuses a zero-fill alias inside a span spanning multiple mappings", () => { diff --git a/src/server/environment/serveEnvironment.test.ts b/src/server/environment/serveEnvironment.test.ts index b766a3acbd8..ce7b02fcf6c 100644 --- a/src/server/environment/serveEnvironment.test.ts +++ b/src/server/environment/serveEnvironment.test.ts @@ -482,6 +482,6 @@ describe("serveEnvironment", () => { await entry.close(); await expect( fetch(new URL(ENVIRONMENT_CARD_PATH, entry.url)), - ).rejects.toThrow(); + ).rejects.toThrow("fetch failed"); }); }); diff --git a/src/server/http/serveStreamableHttp.test.ts b/src/server/http/serveStreamableHttp.test.ts index d445e4d8542..e39ea9d3689 100644 --- a/src/server/http/serveStreamableHttp.test.ts +++ b/src/server/http/serveStreamableHttp.test.ts @@ -261,7 +261,9 @@ it("announces the bound URL and serves one session at a time on one live instanc const second = await connect(served.url); expect(second.transport.sessionId).toEqual(expect.any(String)); expect(second.transport.sessionId).not.toBe(sessionId); - await expect(echo(first.client, "stale")).rejects.toThrow(); + await expect(echo(first.client, "stale")).rejects.toThrow( + "Session not found", + ); await expect(echo(second.client, "live")).resolves.toEqual([ { type: "text", text: "live" }, ]); diff --git a/src/wasm/WabtArtifactProvider.test.ts b/src/wasm/WabtArtifactProvider.test.ts index a7451248421..06ac60f85d9 100644 --- a/src/wasm/WabtArtifactProvider.test.ts +++ b/src/wasm/WabtArtifactProvider.test.ts @@ -1720,7 +1720,9 @@ const runOwnedArtifactOutcome = async ( if (acquiredPid === undefined) throw new Error("The cancelled command did not report an acquired PID"); const pid = acquiredPid; - expect(() => process.kill(pid, 0)).toThrow(); + expect(() => process.kill(pid, 0)).toThrow( + expect.objectContaining({ code: "ESRCH" }), + ); } }; diff --git a/src/wasm/WabtOutput.test.ts b/src/wasm/WabtOutput.test.ts index 3bc9ee331b2..29237cceae4 100644 --- a/src/wasm/WabtOutput.test.ts +++ b/src/wasm/WabtOutput.test.ts @@ -303,7 +303,9 @@ it("preserves leading U+FEFF as custom-name data, not a debug-name marker", () = "", ]); expect(parsed.debugModuleNames).toEqual([]); - expect(() => parseWabtWat('(module (@custom "\\ff" "payload"))')).toThrow(); + expect(() => parseWabtWat('(module (@custom "\\ff" "payload"))')).toThrow( + expect.objectContaining({ code: "ERR_ENCODING_INVALID_ENCODED_DATA" }), + ); }); it("extracts recorded WAT forms and refuses malformed outer framing", async () => { const text = await readFile( diff --git a/src/windows/WindowsPrivateRuntime.test.ts b/src/windows/WindowsPrivateRuntime.test.ts index 8df6e7a7248..8b7f424a5bf 100644 --- a/src/windows/WindowsPrivateRuntime.test.ts +++ b/src/windows/WindowsPrivateRuntime.test.ts @@ -424,7 +424,13 @@ it("refuses an oversized admitted runtime file before reading and still closes i }); const runtime = WindowsPrivateRuntime.create("C:\\", "rea-"); try { - expect(() => runtime.readFile("endpoint", 64)).toThrow(); + expect(() => runtime.readFile("endpoint", 64)).toThrow( + expect.objectContaining({ + name: "ArtifactReaderFailure", + reason: "limit", + message: "Private runtime file exceeds its 64-byte bound", + }), + ); expect(operations).toEqual(["runtime_create", "runtime_open", "close"]); } finally { await runtime.close(); @@ -546,8 +552,12 @@ it("seals runtime admission as cleanup begins", async () => { }); const runtime = WindowsPrivateRuntime.create("C:\\", "rea-"); const closing = runtime.close(); - expect(() => runtime.readFile("endpoint", 64)).toThrow(); - await expect(runtime.snapshot("C:\\input", "snapshot")).rejects.toThrow(); + expect(() => runtime.readFile("endpoint", 64)).toThrow( + "Windows private runtime cleanup is in progress or complete", + ); + await expect(runtime.snapshot("C:\\input", "snapshot")).rejects.toMatchObject( + { message: "Windows private runtime cleanup is in progress or complete" }, + ); expect(operations).not.toContain("runtime_open"); expect(operations).not.toContain("runtime_snapshot"); await closing; @@ -586,9 +596,13 @@ it("keeps runtime cleanup retryable and admission sealed after a file owner rele await expect(runtime.close()).rejects.toBe(runtimeFailure); expect(cleanup.cleanupIncomplete).toBe(false); expect(windowsPrivateRuntime(observation.path)).toBe(runtime); - expect(() => runtime.readFile("endpoint", 64)).toThrow(); + expect(() => runtime.readFile("endpoint", 64)).toThrow( + "Windows private runtime cleanup is in progress or complete", + ); await runtime.close(); expect(fileCloses).toBe(2); expect(rootCloses).toBe(2); - expect(() => windowsPrivateRuntime(observation.path)).toThrow(); + expect(() => windowsPrivateRuntime(observation.path)).toThrow( + `No native private runtime owns ${observation.path}`, + ); });