From 8bb9c0a62fd3b6960f22cf12809d776e29a6708d Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 6 Dec 2026 10:05:29 +0800 Subject: [PATCH] test(gpu): share successful inspection assertions (#17354) --- tests/boundary/gpu/codeObjects.test.ts | 380 ++++++++++--------------- 1 file changed, 145 insertions(+), 235 deletions(-) diff --git a/tests/boundary/gpu/codeObjects.test.ts b/tests/boundary/gpu/codeObjects.test.ts index 7f12cd3a9b..bff60e3e60 100644 --- a/tests/boundary/gpu/codeObjects.test.ts +++ b/tests/boundary/gpu/codeObjects.test.ts @@ -54,6 +54,13 @@ const inspect = async ( onTestFinished(() => provider.close()); return provider.inspect({ path, analysis: "kernels", ...options }); }; + +const inspectSuccessfully = async (...args: Parameters) => { + const result = await inspect(...args); + if (!result.ok) throw result.error; + return result; +}; + it("refuses a missing GPU file as the shared selected-file input refusal", async () => { const root = await createTestTempDirectory("rea-gpu-missing-"); const provider = new GpuCodeObjectsProvider(); @@ -75,8 +82,7 @@ it("refuses a missing GPU file as the shared selected-file input refusal", async it("continues a retained PTX page before a split Unicode character", async () => { const source = ptxFixture.replace(".target", "// 😀\n.target"); - const result = await inspect(Buffer.from(source)); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(Buffer.from(source)); const artifact = result.value.ptx_artifacts[0]!; const boundary = source.indexOf("😀"); const parent = { @@ -154,8 +160,7 @@ it("reports a Zstandard frame-count refusal as an adjustable GPU limit", async ( it.each(["none", "zstd", "lz4"] as const)( "reads selected CUDA metadata and PTX with %s compression", async (compression) => { - const result = await inspect(cudaFixture(compression)); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(cudaFixture(compression)); expect(result.value.coverage).toMatchObject({ discovery: "complete", payloads: "complete", @@ -187,8 +192,7 @@ it.each(["none", "zstd", "lz4"] as const)( ); it("keeps each kernel resource location in its own payload", async () => { - const inspected = await inspect(cudaFixture("none")); - if (!inspected.ok) throw inspected.error; + const inspected = await inspectSuccessfully(cudaFixture("none")); const report = inspected.value; const kernelIndex = report.kernels.findIndex( ({ representation }) => representation === "cuda-elf-metadata", @@ -285,8 +289,7 @@ it("decodes a CUDA 0x2000 LZ4 entry to the exact declared payload", async () => // The fixture must really encode: a stored-profile fallback would leave the // LZ4 selection path unexercised while this control still passed. expect(bytes.readBigUInt64LE(entry + 40)).toBe(0x2011n); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.objects[0]).toMatchObject({ kind: "ptx", compression: "lz4", @@ -310,8 +313,7 @@ it("rejects a CUDA LZ4 entry whose declared decoded length disagrees", async () BigInt(Buffer.byteLength(ptxFixture) + 16), entry + 56, ); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.objects[0]).toMatchObject({ compression: "lz4", inspection: "malformed", @@ -329,8 +331,7 @@ it("preserves CUDA inventory and selection across an oversized declared decoded const declared = 1n << 53n; const encoded = bytes.readUInt32LE(firstEntry + 16); bytes.writeBigUInt64LE(declared, firstEntry + 56); - const inventory = await inspect(bytes, { analysis: "inventory" }); - if (!inventory.ok) throw inventory.error; + const inventory = await inspectSuccessfully(bytes, { analysis: "inventory" }); expect(inventory.value.artifact).toMatchObject({ path: expect.stringContaining("no-format-extension"), file_size: bytes.length, @@ -351,11 +352,10 @@ it("preserves CUDA inventory and selection across an oversized declared decoded [undefined, "capacity"], [["sm_80"], "not-selected"], ] as const) { - const result = await inspect( + const result = await inspectSuccessfully( bytes, targets ? { targets: [...targets] } : {}, ); - if (!result.ok) throw result.error; expect(result.value.objects).toMatchObject([ { id: inventory.value.objects[0]!.id, target: "sm_90", inspection }, { @@ -368,12 +368,11 @@ it("preserves CUDA inventory and selection across an oversized declared decoded } }); it("retains the unsupported legacy CUDA compression declaration and extents", async () => { - const result = await inspect( + const result = await inspectSuccessfully( cudaFixture("legacy", [ { kind: 1, target: 80, bytes: Buffer.from(ptxFixture), flags: 4 }, ]), ); - if (!result.ok) throw result.error; expect(result.value.objects[0]).toMatchObject({ compression: "unsupported", compression_id: expect.stringContaining("cuda-flags:0x1015"), @@ -391,8 +390,7 @@ it.each([1, 2, 3] as const)( "reads CCOB v%d zlib/Zstd and retains exact decoded provenance", async (version) => { for (const method of ["zlib", "zstd"] as const) { - const result = await inspect(ccobFixture(version, method)); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(ccobFixture(version, method)); expect(result.value.kernels[0]).toMatchObject({ name: "add_one", parameter_count: 2, @@ -433,8 +431,7 @@ it.each(["cubin", "ptx"] as const)( : Buffer.from(ptxFixture.replace("sm_80", "sm_90")), }, ]); - const result = await inspect(bytes, { targets: ["sm_80"] }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes, { targets: ["sm_80"] }); expect(result.value.objects[0]).toMatchObject({ target: "sm_80", payload_target: "sm_90", @@ -446,8 +443,7 @@ it.each(["cubin", "ptx"] as const)( expect(result.value.kernels[0]!.limitations.join(" ")).toContain( "inventory sm_80; payload sm_90", ); - const unexamined = await inspect(bytes, { targets: ["sm_90"] }); - if (!unexamined.ok) throw unexamined.error; + const unexamined = await inspectSuccessfully(bytes, { targets: ["sm_90"] }); expect(unexamined.value.objects[0]).toMatchObject({ target: "sm_80", payload_target: null, @@ -462,8 +458,7 @@ it("keeps CUBIN base-only agreement distinct from verified feature-profile agree { kind: 2, target: 90, bytes: cubinFixture({ architecture: 90 }) }, ]); bytes.writeBigUInt64LE(bytes.readBigUInt64LE(16 + 40) | 0x100000n, 16 + 40); - const result = await inspect(bytes, { targets: ["sm_90a"] }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes, { targets: ["sm_90a"] }); expect(result.value.objects[0]).toMatchObject({ target: "sm_90a", payload_target: "sm_90", @@ -480,8 +475,9 @@ it.each([ ])( "reads ABI-qualified CUDA target sm_%d from released NVIDIA header flags", async (architecture, flags) => { - const result = await inspect(cubinFixture({ osAbi: 0x41, flags })); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully( + cubinFixture({ osAbi: 0x41, flags }), + ); expect(result.value.objects[0]).toMatchObject({ target: `sm_${architecture}`, payload_target: `sm_${architecture}`, @@ -495,10 +491,9 @@ it.each([ }, ); it("keeps unsupported CUDA flag layouts unknown while retaining raw header evidence", async () => { - const result = await inspect( + const result = await inspectSuccessfully( cubinFixture({ osAbi: 0x41, flags: 0x06016402 }), ); - if (!result.ok) throw result.error; expect(result.value.objects[0]).toMatchObject({ target: null, payload_target: null, @@ -510,11 +505,10 @@ it("keeps unsupported CUDA flag layouts unknown while retaining raw header evide expect(result.value.kernels[0]!.limitations.join(" ")).toContain( "target encoding is unknown", ); - const inventory = await inspect( + const inventory = await inspectSuccessfully( cubinFixture({ osAbi: 0x41, flags: 0x06016402 }), { analysis: "inventory" }, ); - if (!inventory.ok) throw inventory.error; expect(inventory.value.coverage.discovery).toBe("partial"); }); it("discovers standalone AMD targets before exact selection", async () => { @@ -556,15 +550,13 @@ it("derives V3 AMDGPU processor identity from ELF flags when the note omits it", const bytes = amdFixture(false, undefined, null); // EF_AMDGPU_MACH=0x2c identifies gfx900; high bits include feature flags. bytes.writeUInt32LE(0x12c, 48); - const inventory = await inspect(bytes, { analysis: "inventory" }); - if (!inventory.ok) throw inventory.error; + const inventory = await inspectSuccessfully(bytes, { analysis: "inventory" }); expect(inventory.value.objects[0]).toMatchObject({ target: "gfx900", target_consistency: "single-source", inspection: "inventory", }); - const selected = await inspect(bytes, { targets: ["gfx900"] }); - if (!selected.ok) throw selected.error; + const selected = await inspectSuccessfully(bytes, { targets: ["gfx900"] }); expect(selected.value.objects[0]).toMatchObject({ payload_target: "gfx900", amd_pal_metadata: null, @@ -594,8 +586,7 @@ it("distinguishes an invalid MessagePack target from legacy note coverage", asyn ], [amdFixture(false, legacy), declared, "declared", /Legacy AMDGPU YAML/u], ] as const) { - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); const row = result.value.objects[0]!; expect(row).toMatchObject({ target, @@ -613,8 +604,7 @@ it("distinguishes an invalid MessagePack target from legacy note coverage", asyn it("keeps AMDGPU processor identity unknown when ELF flags are unassigned", async () => { const bytes = amdFixture(false, undefined, null); bytes.writeUInt32LE(0x17f, 48); - const result = await inspect(bytes, { analysis: "inventory" }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes, { analysis: "inventory" }); expect(result.value.objects[0]).toMatchObject({ target: null, target_consistency: "unknown", @@ -631,8 +621,7 @@ const palNote = (bytes: Buffer, metadata: Buffer) => ({ it("reports PAL-ABI target, ABI and declared pipeline facts without HSA kernels", async () => { const metadata = amdPalMetadataFixture(); const bytes = amdAbiFixture(65, metadata); - const inventory = await inspect(bytes, { analysis: "inventory" }); - if (!inventory.ok) throw inventory.error; + const inventory = await inspectSuccessfully(bytes, { analysis: "inventory" }); const header = { processor: "gfx1030", os_abi: 65, @@ -654,8 +643,7 @@ it("reports PAL-ABI target, ABI and declared pipeline facts without HSA kernels" limitations: [], }); expect(inventory.value.coverage.discovery).toBe("complete"); - const selected = await inspect(bytes, { targets: ["gfx1030"] }); - if (!selected.ok) throw selected.error; + const selected = await inspectSuccessfully(bytes, { targets: ["gfx1030"] }); expect(selected.value.objects[0]).toMatchObject({ target: "gfx1030", inspection: "complete", @@ -708,8 +696,9 @@ it("reports PAL-ABI target, ABI and declared pipeline facts without HSA kernels" }); it("keeps a PAL-ABI object without metadata unsupported with its target", async () => { for (const analysis of ["inventory", "kernels"] as const) { - const result = await inspect(amdAbiFixture(65, null), { analysis }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(amdAbiFixture(65, null), { + analysis, + }); expect(result.value.objects[0]).toMatchObject({ target: "gfx1030", inspection: "unsupported", @@ -733,8 +722,7 @@ it("keeps the version of an LLVM PAL note that omits amdpal.version null", async }, ], }); - const result = await inspect(amdAbiFixture(65, metadata)); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(amdAbiFixture(65, metadata)); expect(result.value.objects[0]).toMatchObject({ inspection: "complete", limitations: [], @@ -753,8 +741,7 @@ it("keeps an unexpected PAL scalar unknown and coverage partial", async () => { ], }), ); - const result = await inspect(amdAbiFixture(65, metadata)); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(amdAbiFixture(65, metadata)); const row = result.value.objects[0]!; expect(row.inspection).toBe("partial"); expect(row.amd_pal_metadata?.pipelines[0]?.hardware_stages).toMatchObject([ @@ -795,16 +782,16 @@ it.each([ ], ])("reports a PAL note with %s as malformed", async (label, metadata) => { for (const analysis of ["inventory", "kernels"] as const) { - const result = await inspect(amdAbiFixture(65, metadata()), { analysis }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(amdAbiFixture(65, metadata()), { + analysis, + }); expect(result.value.objects[0]).toMatchObject({ target: "gfx1030", inspection: "malformed", amd_target_metadata: { abi: "amdpal" }, }); } - const retained = await inspect(amdAbiFixture(65, metadata())); - if (!retained.ok) throw retained.error; + const retained = await inspectSuccessfully(amdAbiFixture(65, metadata())); // Pipelines decoded before the failure stay as declared facts. expect( retained.value.objects[0]!.amd_pal_metadata?.pipelines.map( @@ -830,8 +817,7 @@ it("shares one decoded-value allowance across a code object's PAL notes", async ]); bytes[7] = 65; // Inventory decodes every note, so the allowance applies before selection. - const result = await inspect(bytes, { analysis: "inventory" }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes, { analysis: "inventory" }); const row = result.value.objects[0]!; expect(row).toMatchObject({ inspection: "capacity", amd_pal_metadata: null }); expect(row.limitations.join(" ")).toContain("262144-value"); @@ -844,10 +830,9 @@ it.each([ async (osAbi, abi, limitation) => { // An HSA-shaped note under another ABI must not yield HSA kernels. const note = amdNoteFixture(); - const result = await inspect( + const result = await inspectSuccessfully( amdAbiFixture(osAbi, note.subarray(20, 20 + note.readUInt32LE(4))), ); - if (!result.ok) throw result.error; const row = result.value.objects[0]!; expect(row).toMatchObject({ target: "gfx1030", @@ -870,8 +855,7 @@ it.each([false, true])( const payload = llvmBitcodeFixture(wrapped), bytes = hipFixture(payload, "hip-amdgcn-amd-amdhsa--"); for (const analysis of ["inventory", "kernels"] as const) { - const result = await inspect(bytes, { analysis }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes, { analysis }); const row = result.value.objects.find(({ kind }) => kind === "amdgpu")!; expect(row).toMatchObject({ bundle_id: "hip-amdgcn-amd-amdhsa--", @@ -908,11 +892,10 @@ it.each([ const noteTarget = `${triple}-amd-amdhsa--${target}`; const payload = amdFixture(false, undefined, noteTarget); payload.writeUInt32LE(0x12c, 48); - const result = await inspect( + const result = await inspectSuccessfully( hipFixture(payload, `hipv4-amdgcn-amd-amdhsa--${target}`), { targets: [target] }, ); - if (!result.ok) throw result.error; expect( result.value.objects.find(({ kind }) => kind === "amdgpu"), ).toMatchObject({ @@ -931,8 +914,7 @@ it.each(["amdgcn", "amdgpu9.00"])( const declared = `${triple}-amd-amdhsa--gfx900:xnack+`; const bytes = amdFixture(false, undefined, declared); bytes.writeUInt32LE(0x141, 48); // EF_AMDGPU_MACH gfx1100 - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.objects[0]).toMatchObject({ target: null, payload_target: null, @@ -957,11 +939,10 @@ it.each([ ])( "retains the unrecognized AMDGPU note target %s without substituting ELF processor flags", async (noteTarget) => { - const result = await inspect( + const result = await inspectSuccessfully( hipFixture(amdFixture(false, undefined, noteTarget)), { targets: ["gfx900"] }, ); - if (!result.ok) throw result.error; const row = result.value.objects.find(({ kind }) => kind === "amdgpu"); expect(row).toMatchObject({ target: "gfx900", @@ -986,8 +967,7 @@ it("retains kernels from conflicting AMDGPU notes without choosing either note o const second = amdNoteFixture(false, "amdgcn-amd-amdhsa--gfx1100"); const bytes = amdFixture(false, second); const firstDescriptor = bytes.indexOf(first) + 20; - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.objects).toMatchObject([ { kind: "amdgpu", @@ -1029,8 +1009,7 @@ it("retains kernels from conflicting AMDGPU notes without choosing either note o { name: "add_one", parameter_bytes: 12, registers: { sgpr: 6, vgpr: 2 } }, ]); expect(new Set(result.value.kernels.map(({ id }) => id)).size).toBe(2); - const selected = await inspect(bytes, { targets: ["gfx900"] }); - if (!selected.ok) throw selected.error; + const selected = await inspectSuccessfully(bytes, { targets: ["gfx900"] }); expect(selected.value.objects[0]).toMatchObject({ target: null, payload_target: null, @@ -1068,8 +1047,9 @@ it.each( amdFixture(false, undefined, payloadTarget), `hipv4-amdgcn-amd-amdhsa--${inventoryTarget}`, ); - const result = await inspect(bytes, { targets: [inventoryTarget] }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes, { + targets: [inventoryTarget], + }); const row = result.value.objects.find((value) => value.kind === "amdgpu")!; expect(row.payload_target).toBe(payloadTarget); expect(result.value.kernels).toHaveLength(1); @@ -1103,15 +1083,15 @@ it.each([ "hipv4-amdgpu9.00-amd-amdhsa--gfx900", ])("keeps discovered HIP targets selectable for %s", async (targetId) => { const bytes = hipFixture(amdFixture(), targetId); - const inventory = await inspect(bytes, { analysis: "inventory" }); - if (!inventory.ok) throw inventory.error; + const inventory = await inspectSuccessfully(bytes, { analysis: "inventory" }); const row = inventory.value.objects.find((value) => value.kind === "amdgpu")!; const expectedTarget = targetId.endsWith("opaque") ? "amdgcn-amd-amdhsa--gfx900" : "gfx900"; expect(row.target).toBe(expectedTarget); - const selected = await inspect(bytes, { targets: [expectedTarget] }); - if (!selected.ok) throw selected.error; + const selected = await inspectSuccessfully(bytes, { + targets: [expectedTarget], + }); expect(selected.value.kernels).toHaveLength(1); expect( selected.value.objects.find((value) => value.kind === "amdgpu"), @@ -1131,8 +1111,7 @@ it.each(["gfx11-generic", "gfx9-4-generic"] as const)( const payload = amdFixture(false, undefined, noteTarget); payload.writeUInt32LE(processor === "gfx11-generic" ? 0x54 : 0x5f, 48); const bytes = hipFixture(payload, `hipv4-amdgcn-amd-amdhsa--${processor}`); - const result = await inspect(bytes, { targets: [processor] }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes, { targets: [processor] }); expect( result.value.objects.find(({ kind }) => kind === "amdgpu"), ).toMatchObject({ @@ -1148,8 +1127,7 @@ it.each(["gfx11-generic", "gfx9-4-generic"] as const)( it("recognizes a modern AMDGPU triple inside compressed CCOB v3", async () => { const targetId = "hipv4-amdgpu9.00-amd-amdhsa--gfx900"; const bytes = ccobFixture(3, "zstd", hipFixture(amdFixture(), targetId)); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect( result.value.objects.find(({ bundle_id }) => bundle_id === targetId), ).toMatchObject({ @@ -1162,13 +1140,12 @@ it("recognizes a modern AMDGPU triple inside compressed CCOB v3", async () => { expect(result.value.kernels).toHaveLength(1); }); it("bounds standalone AMD note discovery before retaining metadata", async () => { - const result = await inspect( + const result = await inspectSuccessfully( elfFixture(224, [ { name: ".note", type: 7, bytes: Buffer.alloc(8 * 1024 * 1024 + 1) }, ]), { analysis: "inventory" }, ); - if (!result.ok) throw result.error; expect(result.value.objects[0]).toMatchObject({ target: "gfx900", inspection: "capacity", @@ -1183,8 +1160,7 @@ it("reads PE raw-size fallback and ELF-host section locations", async () => { peGpuFixture(), elfFixture(62, [{ name: ".nv_fatbin", bytes: cudaFixture() }]), ]) { - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.kernels).toHaveLength(2); expect(result.value.objects[0]!.location.section_index).not.toBeNull(); expect(result.value.objects[1]!.location.container_id).toBe( @@ -1195,25 +1171,22 @@ it("reads PE raw-size fallback and ELF-host section locations", async () => { it("coalesces aliased CUDA metadata before expanding the temporary index", async () => { const bytes = cubinFixture({ globalRecords: 65536, globalAliases: 1024 }); expect(bytes.length).toBeLessThan(1024 * 1024); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.objects[0]!.inspection).toBe("complete"); expect(result.value.kernels).toHaveLength(1); expect(result.value.kernels[0]!.registers.physical).toBe(10); }); it("retains unknown PTX virtual counts and partial payload coverage", async () => { - const result = await inspect( + const result = await inspectSuccessfully( Buffer.from(ptxFixture.replace("%r<9>", "r0, r1, %r<4>, %s<8>")), ); - if (!result.ok) throw result.error; expect(result.value.kernels[0]!.registers.virtual[0]).toEqual({ type: ".b32", count: 14, }); - const unsupported = await inspect( + const unsupported = await inspectSuccessfully( Buffer.from(ptxFixture.replace("%r<9>", "%r[4]")), ); - if (!unsupported.ok) throw unsupported.error; expect(unsupported.value.objects[0]!.inspection).toBe("partial"); expect(unsupported.value.coverage.payloads).toBe("partial"); expect(unsupported.value.kernels[0]!.registers.virtual[0]).toEqual({ @@ -1228,8 +1201,7 @@ it.each(["spaced", "compact", "mixed"])( const header = ".version 8.8\n.target sm_80\n// GPU 寄存器 🎯\n"; const entry = `.entry k() { ${directive}.b32 %r<4>; ${spacing === "mixed" ? ".reg " : directive}.b32 r0, r1, %r4; ${directive}.b64 %rd<2>; ret; }`; const source = header + entry; - const result = await inspect(Buffer.from(source)); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(Buffer.from(source)); expect(result.value.objects[0]!.inspection).toBe("complete"); expect(result.value.coverage.payloads).toBe("complete"); expect(result.value.ptx_artifacts[0]!.text).toBe(source); @@ -1245,10 +1217,9 @@ it.each(["spaced", "compact", "mixed"])( }, ); it("keeps unsupported compact PTX register types partial", async () => { - const result = await inspect( + const result = await inspectSuccessfully( Buffer.from(ptxFixture.replace(".reg .b32", ".reg.v2.b32")), ); - if (!result.ok) throw result.error; expect(result.value.objects[0]!.inspection).toBe("partial"); expect(result.value.coverage.payloads).toBe("partial"); expect(result.value.kernels[0]!.registers.virtual).toEqual([ @@ -1263,12 +1234,11 @@ it.each([64, 65])( { length: count }, (_, index) => `%r${index}`, ).join(", "); - const result = await inspect( + const result = await inspectSuccessfully( Buffer.from( `.version 8.8\n.target sm_80\n.address_size 64\n.entry k() { .reg .b32 ${names}; ret; }\n`, ), ); - if (!result.ok) throw result.error; expect(result.value.objects[0]!.inspection).toBe("complete"); expect(result.value.coverage.payloads).toBe("complete"); expect(result.value.kernels[0]!.registers.virtual).toEqual([ @@ -1280,12 +1250,11 @@ it("retains PTX kernels before and after a long scalar register list", async () const names = Array.from({ length: 65 }, (_, index) => `%r${index}`).join( ", ", ); - const result = await inspect( + const result = await inspectSuccessfully( Buffer.from( `.version 8.8\n.target sm_80\n.address_size 64\n.entry before() { ret; }\n.entry affected() { .reg .b32 ${names}; ret; }\n.entry after() { ret; }\n`, ), ); - if (!result.ok) throw result.error; expect(result.value.objects[0]!.inspection).toBe("complete"); expect(result.value.coverage.payloads).toBe("complete"); expect(result.value.kernels.map((kernel) => kernel.name)).toEqual([ @@ -1298,12 +1267,11 @@ it("retains PTX kernels before and after a long scalar register list", async () ]); }); it("retains later PTX kernels when a virtual register total overflows", async () => { - const result = await inspect( + const result = await inspectSuccessfully( Buffer.from( ".version 8.8\n.target sm_80\n.address_size 64\n.entry before() { ret; }\n.entry affected() { .reg .b32 %r<9007199254740991>, %s; ret; }\n.entry after() { ret; }\n", ), ); - if (!result.ok) throw result.error; expect(result.value.objects[0]!.inspection).toBe("partial"); expect(result.value.coverage.payloads).toBe("partial"); expect(result.value.kernels.map((kernel) => kernel.name)).toEqual([ @@ -1320,10 +1288,9 @@ it.each([ ".entry k() { ret; }", ".entry k .maxntid 1 { ret; }", ])("inspects PTX entry with optional parameters: %s", async (entry) => { - const result = await inspect( + const result = await inspectSuccessfully( Buffer.from(`.version 7.0\n.target sm_80\n.address_size 64\n${entry}`), ); - if (!result.ok) throw result.error; expect(result.value.objects[0]!.inspection).toBe("complete"); expect(result.value.coverage.payloads).toBe("complete"); expect(result.value.kernels).toMatchObject([ @@ -1337,8 +1304,7 @@ it.each([ "marks unknown PTX %s declarations partial while retaining known facts", async (kind, from, to) => { const bytes = Buffer.from(ptxFixture.replace(from, to)); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.objects[0]!.inspection).toBe("partial"); expect(result.value.coverage.payloads).toBe("partial"); expect(result.value.ptx_artifacts[0]!.text).toBe(bytes.toString()); @@ -1373,8 +1339,7 @@ it.each([ const bytes = Buffer.from( ptxFixture.replace(".u64 output", `.u64 ${qualifiers} output`), ); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.objects[0]!.inspection).toBe("complete"); expect(result.value.coverage.payloads).toBe("complete"); expect(result.value.ptx_artifacts[0]!.text).toBe(bytes.toString()); @@ -1394,8 +1359,7 @@ it.each([".align 8 .b8", ".b8 .align 8"])( const bytes = Buffer.from( ptxFixture.replace(".u64 output", `${type} payload[8]`), ); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.objects[0]!.inspection).toBe("complete"); expect(result.value.coverage.payloads).toBe("complete"); expect(result.value.ptx_artifacts[0]!.text).toBe(bytes.toString()); @@ -1412,7 +1376,7 @@ it.each([".align 8 .b8", ".b8 .align 8"])( it.each(["9007199254740991", "0x1fffffffffffff"])( "retains PTX parameter facts when aligning an extent of %s exceeds the exact range", async (extent) => { - const result = await inspect( + const result = await inspectSuccessfully( Buffer.from( `.version 8.0 .target sm_80 @@ -1420,7 +1384,6 @@ it.each(["9007199254740991", "0x1fffffffffffff"])( .entry later(.param .u32 value) { ret; }`, ), ); - if (!result.ok) throw result.error; expect(result.value.coverage.payloads).toBe("partial"); expect(result.value.kernels).toMatchObject([ { @@ -1451,8 +1414,7 @@ it.each([ const bytes = Buffer.from( ptxFixture.replace(".u64 output", `${type} payload[8]`), ); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.objects[0]!.inspection).toBe("partial"); expect(result.value.coverage.payloads).toBe("partial"); expect(result.value.kernels[0]).toMatchObject({ @@ -1503,8 +1465,7 @@ it("reports invalid standalone PTX encoding in inventory and kernel inspection", const malformed = Buffer.concat([header, Buffer.from([0xff]), entry]); const valid = Buffer.concat([header, Buffer.from("café"), entry]); for (const analysis of ["inventory", "kernels"] as const) { - const result = await inspect(malformed, { analysis }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(malformed, { analysis }); expect(result.value).toMatchObject({ format: "ptx", artifact: { @@ -1522,8 +1483,7 @@ it("reports invalid standalone PTX encoding in inventory and kernel inspection", "PTX is not valid UTF-8 text", ); - const control = await inspect(valid, { analysis }); - if (!control.ok) throw control.error; + const control = await inspectSuccessfully(valid, { analysis }); expect(control.value.coverage.discovery).toBe("complete"); expect(control.value.objects[0]!.target).toBe("sm_80"); if (analysis === "kernels") { @@ -1553,8 +1513,7 @@ it.each([ ".version 8.0\n.target sm_80\n.entry k() { ret; }\n.target sm_90\n", ); for (const analysis of ["inventory", "kernels"] as const) { - const result = await inspect(malformed, { analysis }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(malformed, { analysis }); expect(result.value.coverage.discovery).toBe("partial"); expect(result.value.objects).toMatchObject([{ kind: "ptx", target: null }]); expect(result.value.objects[0]!.inspection).not.toBe("complete"); @@ -1562,8 +1521,7 @@ it.each([ "Malformed PTX text prevents complete target discovery.", ); - const control = await inspect(valid, { analysis }); - if (!control.ok) throw control.error; + const control = await inspectSuccessfully(valid, { analysis }); expect(control.value.coverage.discovery).toBe("complete"); expect(control.value.objects).toMatchObject([ { @@ -1584,8 +1542,7 @@ it("keeps a UTF-8 character split by the standalone PTX scan budget unexamined", Buffer.alloc(budget - header.length - 1, 0x20), Buffer.from("é\n"), ]); - const result = await inspect(bytes, { analysis: "inventory" }); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes, { analysis: "inventory" }); expect(result.value.coverage.discovery).toBe("partial"); expect(result.value.objects).toMatchObject([ { kind: "ptx", target: null, inspection: "partial" }, @@ -1618,8 +1575,7 @@ it.each(["truncated", "invalid", "extension"] as const)( consistency: "consistent", }, ]) { - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.kernels).toHaveLength(1); expect(result.value.kernels[0]).toMatchObject({ name: "add_one", @@ -1638,17 +1594,15 @@ it.each(["truncated", "invalid", "extension"] as const)( result.value.objects.find((row) => row.kind === "amdgpu"), ).toMatchObject(identity); expect(result.value.coverage.payloads).toBe("partial"); - const selected = await inspect(bytes, { targets: [target] }); - if (!selected.ok) throw selected.error; + const selected = await inspectSuccessfully(bytes, { targets: [target] }); expect( selected.value.objects.find((row) => row.kind === "amdgpu"), ).toMatchObject(identity); expect(selected.value.kernels).toEqual(result.value.kernels); expect(selected.value.coverage.payloads).toBe("partial"); - const skipped = await inspect(bytes, { + const skipped = await inspectSuccessfully(bytes, { targets: [target === "gfx900" ? payloadTarget : "gfx900"], }); - if (!skipped.ok) throw skipped.error; expect( skipped.value.objects.find((row) => row.kind === "amdgpu"), ).toMatchObject( @@ -1673,13 +1627,12 @@ it("bounds cumulative CUDA records across separate in-range metadata sections", records = Buffer.alloc(record.length * 131073); for (let offset = 0; offset < records.length; offset += record.length) record.copy(records, offset); - const result = await inspect( + const result = await inspectSuccessfully( elfFixture(190, [ { name: ".nv.info", type: 0x70000000, bytes: records }, { name: ".nv.info", type: 0x70000000, bytes: records }, ]), ); - if (!result.ok) throw result.error; expect(result.value.objects[0]!.inspection).toBe("capacity"); expect(result.value.objects[0]!.limitations.join(" ")).toContain( "aggregate record/symbol visits", @@ -1691,8 +1644,7 @@ it.each(["section-names", "symbols"] as const)( const bytes = cubinFixture(); if (missing === "section-names") bytes.writeUInt16LE(0, 62); else bytes.writeUInt32LE(1, Number(bytes.readBigUInt64LE(40)) + 3 * 64 + 4); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.objects[0]!.inspection).toBe("partial"); expect(result.value.coverage.payloads).toBe("partial"); expect(result.value.kernels).toHaveLength(missing === "symbols" ? 0 : 1); @@ -1706,8 +1658,7 @@ it.each(["section-names", "symbols"] as const)( it.each(["add_one", "kérnel_日本"])( "decodes UTF-8 CUBIN symbol name %s without a name limitation", async (name) => { - const result = await inspect(cubinFixture({ name })); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(cubinFixture({ name })); const [kernel] = result.value.kernels; expect(kernel).toMatchObject({ name, symbol: name }); expect(kernel!.limitations.join(" ")).not.toContain("not valid UTF-8"); @@ -1718,8 +1669,7 @@ it("preserves non-UTF-8 CUBIN symbol bytes in the kernel name", async () => { const symbolName = bytes.indexOf(Buffer.from("\0add_one\0")); expect(symbolName).toBeGreaterThanOrEqual(0); bytes[symbolName + 1] = 0xff; - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); const [kernel] = result.value.kernels; expect(kernel?.name).toBe("ÿdd_one"); expect(kernel!.limitations).toContain( @@ -1731,10 +1681,9 @@ it.each([9, 10])( "preserves parameters and register coverage for text count %d", async (textRegisters) => { const name = "kernel_" + "argument".repeat(64); - const result = await inspect( + const result = await inspectSuccessfully( cubinFixture({ name, textRegisters, globalRegisters: 10 }), ); - if (!result.ok) throw result.error; const conflict = textRegisters !== 10; expect(result.value.kernels[0]).toMatchObject({ name, @@ -1755,10 +1704,9 @@ it.each([9, 10])( }, ); it("iterates flat concatenated fatbins beyond the genuine container nesting limit", async () => { - const result = await inspect( + const result = await inspectSuccessfully( Buffer.concat(Array.from({ length: 20 }, () => cudaFixture())), ); - if (!result.ok) throw result.error; expect(result.value.objects).toHaveLength(40); expect(result.value.kernels).toHaveLength(40); expect(result.value.coverage.discovery).toBe("complete"); @@ -1766,14 +1714,12 @@ it("iterates flat concatenated fatbins beyond the genuine container nesting limi it("reports checksum corruption and unknown compression as partial, retaining known entries", async () => { const corrupt = ccobFixture(); corrupt[16] = corrupt[16]! ^ 1; - const result = await inspect(corrupt); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(corrupt); expect(result.value.coverage.discovery).toBe("partial"); expect(result.value.objects[0]!.inspection).toBe("malformed"); const unknown = ccobFixture(); unknown.writeUInt16LE(99, 6); - const unsupported = await inspect(unknown); - if (!unsupported.ok) throw unsupported.error; + const unsupported = await inspectSuccessfully(unknown); expect(unsupported.value.objects[0]!.inspection).toBe("unsupported"); }); it("rejects out-of-range bundle entries without guessing a payload", async () => { @@ -1788,8 +1734,7 @@ it("rejects out-of-range bundle entries without guessing a payload", async () => it("preserves standalone PTX BOM and trailing NUL bytes in the retained text artifact", async () => { const bytes = Buffer.from("\uFEFF" + ptxFixture + "\0"); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect( Buffer.compare(Buffer.from(result.value.ptx_artifacts[0]!.text), bytes), ).toBe(0); @@ -1810,8 +1755,7 @@ it("iterates mixed plain/CCOB bundles without counting flat records as nesting", const records = Array.from({ length: 20 }, (_, index) => index % 2 === 0 ? hipFixture() : ccobFixture(), ); - const result = await inspect(Buffer.concat(records)); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(Buffer.concat(records)); expect(result.value.kernels).toHaveLength(20); expect(result.value.coverage.discovery).toBe("complete"); }); @@ -1834,10 +1778,9 @@ it("requires the PTX version directive before any module content", async () => { it("retains an embedded CCOB with a corrupted signature as unsupported", async () => { const bytes = ccobFixture(3, "zlib"); bytes[0] = bytes[0]! | 0x80; - const result = await inspect( + const result = await inspectSuccessfully( elfFixture(62, [{ name: ".hip_fatbin", bytes }]), ); - if (!result.ok) throw result.error; expect(result.value.coverage.discovery).toBe("partial"); expect(result.value.kernels).toEqual([]); expect(result.value.objects).toContainEqual( @@ -1859,8 +1802,7 @@ it.each([ const bytes = peGpuFixture(); const pe = bytes.readUInt32LE(60); bytes.writeUInt16LE(machine, pe + 4); - const result = await inspect(bytes); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(bytes); expect(result.value.format).toBe("pe"); expect(result.value.artifact.sha256).toBe( createHash("sha256").update(bytes).digest("hex"), @@ -1901,8 +1843,9 @@ it.each(["zlib", "zstd"] as const)( const first = ccobFixture(1, codec), second = ccobFixture(2, "zlib"), padding = Buffer.alloc((8 - (first.length % 8)) % 8); - const result = await inspect(Buffer.concat([first, padding, second])); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully( + Buffer.concat([first, padding, second]), + ); const bundles = result.value.objects.filter( ({ kind }) => kind === "hip-bundle", ); @@ -1926,8 +1869,7 @@ it.each(["zlib", "zstd"] as const)( it("keeps a later CCOB bundle after a truncated legacy v1 stream", async () => { const truncated = ccobFixture(1, "zlib").subarray(0, -1), later = ccobFixture(2, "zlib"); - const result = await inspect(Buffer.concat([truncated, later])); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully(Buffer.concat([truncated, later])); const bundles = result.value.objects.filter( ({ kind }) => kind === "hip-bundle", ); @@ -1954,10 +1896,9 @@ it.each(["checksum", "decoded-size"] as const)( if (declaration === "checksum") header[12] = header[12]! ^ 1; else header.writeUInt32LE(bundle.length + 1, 8); const first = Buffer.concat([header, compressed]); - const result = await inspect( + const result = await inspectSuccessfully( Buffer.concat([first, ccobFixture(2, "zlib")]), ); - if (!result.ok) throw result.error; const wrappers = result.value.objects.filter( ({ kind }) => kind === "hip-bundle", ); @@ -1977,8 +1918,9 @@ it.each(["checksum", "decoded-size"] as const)( it("continues at the declared CCOB boundary after an unsupported codec", async () => { const unknown = ccobFixture(); unknown.writeUInt16LE(99, 6); - const result = await inspect(Buffer.concat([unknown, ccobFixture()])); - if (!result.ok) throw result.error; + const result = await inspectSuccessfully( + Buffer.concat([unknown, ccobFixture()]), + ); expect(result.value.kernels).toHaveLength(1); expect(result.value.coverage.discovery).toBe("partial"); }); @@ -1995,10 +1937,9 @@ it.each([ async ({ decoded, projected }) => { const first = ccobFixture(3, "zlib"); first.writeBigUInt64LE(decoded, 16); - const result = await inspect( + const result = await inspectSuccessfully( Buffer.concat([first, ccobFixture(3, "zlib")]), ); - if (!result.ok) throw result.error; const wrappers = result.value.objects.filter( ({ kind }) => kind === "hip-bundle", ); @@ -2047,8 +1988,9 @@ it("refuses escaped PTX report expansion while preserving bounded interrupted fa it("distinguishes impossible Clang bundle counts from a framed over-capacity directory", async () => { const empty = Buffer.alloc(32); Buffer.from("__CLANG_OFFLOAD_BUNDLE__").copy(empty); - const emptyResult = await inspect(empty, { analysis: "inventory" }); - if (!emptyResult.ok) throw emptyResult.error; + const emptyResult = await inspectSuccessfully(empty, { + analysis: "inventory", + }); expect(emptyResult.value.objects).toEqual([]); const truncated = hipFixture().subarray(0, 32); for (const count of [65537n, 0xffffffffffffffffn]) { @@ -2290,11 +2232,10 @@ it("enforces per-call GPU budgets and recovers when raised", async () => { expect(recoveredObject.ok).toBe(true); // max_work_bytes: per-object capacity limitation names max_work_bytes and recovers when raised. - const limitedWork = await inspect(cudaFixture("none"), { + const limitedWork = await inspectSuccessfully(cudaFixture("none"), { analysis: "kernels", max_work_bytes: 32, }); - if (!limitedWork.ok) throw limitedWork.error; expect(limitedWork.value.coverage.payloads).toBe("partial"); expect( limitedWork.value.objects.some( @@ -2305,11 +2246,10 @@ it("enforces per-call GPU budgets and recovers when raised", async () => { ), ), ).toBe(true); - const recoveredWork = await inspect(cudaFixture("none"), { + const recoveredWork = await inspectSuccessfully(cudaFixture("none"), { analysis: "kernels", max_work_bytes: 1024 * 1024, }); - if (!recoveredWork.ok) throw recoveredWork.error; expect(recoveredWork.value.coverage.payloads).toBe("complete"); // max_structure_bytes: ELF section directory refusal & recovery. @@ -2343,11 +2283,10 @@ it("enforces per-call GPU budgets and recovers when raised", async () => { expect(recoveredStructure.ok).toBe(true); // max_metadata_bytes & max_parser_visits on AMDGPU metadata note. - const limitedMetadata = await inspect(amdBytes, { + const limitedMetadata = await inspectSuccessfully(amdBytes, { analysis: "kernels", max_metadata_bytes: 16, }); - if (!limitedMetadata.ok) throw limitedMetadata.error; expect(limitedMetadata.value.objects[0]).toMatchObject({ inspection: "capacity", limitations: expect.arrayContaining([ @@ -2355,11 +2294,10 @@ it("enforces per-call GPU budgets and recovers when raised", async () => { ]), }); - const limitedVisits = await inspect(amdBytes, { + const limitedVisits = await inspectSuccessfully(amdBytes, { analysis: "kernels", max_parser_visits: 2, }); - if (!limitedVisits.ok) throw limitedVisits.error; expect(limitedVisits.value.objects[0]).toMatchObject({ inspection: "capacity", limitations: expect.arrayContaining([ @@ -2367,12 +2305,11 @@ it("enforces per-call GPU budgets and recovers when raised", async () => { ]), }); - const recoveredAmd = await inspect(amdBytes, { + const recoveredAmd = await inspectSuccessfully(amdBytes, { analysis: "kernels", max_metadata_bytes: 65_536, max_parser_visits: 4096, }); - if (!recoveredAmd.ok) throw recoveredAmd.error; expect(recoveredAmd.value.objects[0]?.inspection).toBe("complete"); expect(recoveredAmd.value.kernels.length).toBeGreaterThan(0); }); @@ -2409,11 +2346,10 @@ it("respects max_object_bytes during container scanning and full-file digesting" const smallBundle = hipFixture(Buffer.from("x"), "host-x86_64"); const paddedBundle = Buffer.concat([smallBundle, Buffer.alloc(2048)]); - const scanned = await inspect(paddedBundle, { + const scanned = await inspectSuccessfully(paddedBundle, { analysis: "inventory", max_object_bytes: 512, }); - if (!scanned.ok) throw scanned.error; expect(scanned.value.format).toBe("hip-bundle"); expect(scanned.value.coverage.discovery).toBe("complete"); @@ -2447,10 +2383,9 @@ it("keeps PTX single-parameter 128-token ceiling fixed independently of max_pars const widePtx = Buffer.from( `.version 8.8\n.target sm_80\n.address_size 64\n.visible .entry wide_param(.param .u32 p${manyDimensions}) {\nret;\n}\n`, ); - const defaultRefused = await inspect(widePtx, { + const defaultRefused = await inspectSuccessfully(widePtx, { analysis: "kernels", }); - if (!defaultRefused.ok) throw defaultRefused.error; expect(defaultRefused.value.objects[0]).toMatchObject({ inspection: "capacity", limitations: expect.arrayContaining([ @@ -2467,10 +2402,9 @@ it("keeps PTX single-parameter 128-token ceiling fixed independently of max_pars const wideBodyParamPtx = Buffer.from( `.version 1.3\n.target sm_10\n.entry wide_body() {\n.param .u32 p${manyDimensions};\nret;\n}\n`, ); - const bodyRefused = await inspect(wideBodyParamPtx, { + const bodyRefused = await inspectSuccessfully(wideBodyParamPtx, { analysis: "kernels", }); - if (!bodyRefused.ok) throw bodyRefused.error; expect(bodyRefused.value.objects[0]).toMatchObject({ inspection: "capacity", limitations: expect.arrayContaining([ @@ -2487,11 +2421,10 @@ it("keeps PTX single-parameter 128-token ceiling fixed independently of max_pars const singleParamPtx = Buffer.from( ".version 8.8\n.target sm_80\n.address_size 64\n.visible .entry add_one(.param .align 8 .u32 x[4]) {\nret;\n}\n", ); - const singleParam = await inspect(singleParamPtx, { + const singleParam = await inspectSuccessfully(singleParamPtx, { analysis: "kernels", max_parser_entries: 4, }); - if (!singleParam.ok) throw singleParam.error; expect(singleParam.value.objects[0]?.inspection).toBe("complete"); expect(singleParam.value.kernels.map((k) => k.name)).toEqual(["add_one"]); }); @@ -2504,11 +2437,10 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat corruptV1.fill(0xff, 20); const siblingV2 = ccobFixture(2, "zlib", smallBundle); const combined = Buffer.concat([corruptV1, siblingV2, Buffer.alloc(600)]); - const recovered = await inspect(combined, { + const recovered = await inspectSuccessfully(combined, { analysis: "inventory", max_object_bytes: 512, }); - if (!recovered.ok) throw recovered.error; const bundles = recovered.value.objects.filter( (o) => o.kind === "hip-bundle", ); @@ -2524,11 +2456,10 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat ); const validV1 = Buffer.concat([header, storedCompressed]); expect(storedCompressed.length).toBeGreaterThan(smallBundle.length); - const truncatedByBudget = await inspect(validV1, { + const truncatedByBudget = await inspectSuccessfully(validV1, { analysis: "inventory", max_object_bytes: smallBundle.length, }); - if (!truncatedByBudget.ok) throw truncatedByBudget.error; expect(truncatedByBudget.value.objects[0]).toMatchObject({ kind: "hip-bundle", inspection: "capacity", @@ -2538,11 +2469,10 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat ), ]), }); - const raisedV1 = await inspect(validV1, { + const raisedV1 = await inspectSuccessfully(validV1, { analysis: "inventory", max_object_bytes: validV1.length + 64, }); - if (!raisedV1.ok) throw raisedV1.error; expect(raisedV1.value.objects[0]?.inspection).toBe("complete"); // Multi-frame Zstandard CCOB v1 whose declared decoded size fits every cut @@ -2571,11 +2501,10 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat const budget = prefixFrames.length + extra; expect(smallBundle.length).toBeLessThanOrEqual(budget); expect(budget).toBeLessThan(multiFrames.length); - const cut = await inspect(multiFrameV1, { + const cut = await inspectSuccessfully(multiFrameV1, { analysis: "inventory", max_object_bytes: budget, }); - if (!cut.ok) throw cut.error; expect(cut.value.objects).toHaveLength(1); expect(cut.value.objects[0]).toMatchObject({ kind: "hip-bundle", @@ -2587,11 +2516,10 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat ]), }); } - const fullMultiFrame = await inspect(multiFrameV1, { + const fullMultiFrame = await inspectSuccessfully(multiFrameV1, { analysis: "inventory", max_object_bytes: multiFrames.length + 64, }); - if (!fullMultiFrame.ok) throw fullMultiFrame.error; expect(fullMultiFrame.value.objects[0]?.inspection).toBe("complete"); // When a sibling's cached legacy window ends right between prefixFrames and @@ -2609,11 +2537,10 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat expect(cachedWindowCut).toBeGreaterThanOrEqual(smallBundle.length); expect(cachedWindowCut).toBeGreaterThanOrEqual(multiFrames.length); const twoSiblings = Buffer.concat([prefixV1, multiFrameV1]); - const refilledSiblings = await inspect(twoSiblings, { + const refilledSiblings = await inspectSuccessfully(twoSiblings, { analysis: "inventory", max_object_bytes: cachedWindowCut, }); - if (!refilledSiblings.ok) throw refilledSiblings.error; expect( refilledSiblings.value.objects .filter((o) => o.kind === "hip-bundle") @@ -2656,11 +2583,10 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat const cutBudget = multiFrames.length + extra; expect(smallBundle.length).toBeLessThanOrEqual(cutBudget); expect(cutBudget).toBeLessThan(withTailEncoded.length); - const cutTail = await inspect(withTailV1, { + const cutTail = await inspectSuccessfully(withTailV1, { analysis: "inventory", max_object_bytes: cutBudget, }); - if (!cutTail.ok) throw cutTail.error; expect(cutTail.value.objects).toHaveLength(1); expect(cutTail.value.objects[0]).toMatchObject({ kind: "hip-bundle", @@ -2677,11 +2603,10 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat const refillBudget = prefixStored.length + 20 + multiFrames.length + extra; expect(refillBudget).toBeGreaterThanOrEqual(withTailEncoded.length); - const refilledTail = await inspect(siblingWithTail, { + const refilledTail = await inspectSuccessfully(siblingWithTail, { analysis: "inventory", max_object_bytes: refillBudget, }); - if (!refilledTail.ok) throw refilledTail.error; const tailBundles = refilledTail.value.objects.filter( (o) => o.kind === "hip-bundle", ); @@ -2700,25 +2625,23 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat const exactFrame = zstdCompressSync(smallBundle); const exactZstdV1 = Buffer.concat([zstdHeader, exactFrame]); const trailingClangBundle = hipFixture(Buffer.from("next"), "host-x86_64"); - const exactWithNul = await inspect( + const exactWithNul = await inspectSuccessfully( Buffer.concat([exactZstdV1, Buffer.alloc(4)]), { analysis: "inventory", max_object_bytes: Math.max(smallBundle.length, exactFrame.length), }, ); - if (!exactWithNul.ok) throw exactWithNul.error; expect(exactWithNul.value.coverage.discovery).toBe("complete"); expect(exactWithNul.value.objects[0]?.inspection).toBe("complete"); - const exactWithClang = await inspect( + const exactWithClang = await inspectSuccessfully( Buffer.concat([exactZstdV1, trailingClangBundle]), { analysis: "inventory", max_object_bytes: Math.max(smallBundle.length, exactFrame.length + 1), }, ); - if (!exactWithClang.ok) throw exactWithClang.error; expect(exactWithClang.value.coverage.discovery).toBe("complete"); expect( exactWithClang.value.objects.every((o) => o.inspection === "complete"), @@ -2736,12 +2659,11 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat const windowBudget = prefixStored.length + 20 + exactFrame.length + extra; const tightWorkBudget = windowBudget + prefixBundle.length + smallBundle.length; - const tightResult = await inspect(tightThree, { + const tightResult = await inspectSuccessfully(tightThree, { analysis: "inventory", max_object_bytes: windowBudget, max_work_bytes: tightWorkBudget, }); - if (!tightResult.ok) throw tightResult.error; expect(tightResult.value.coverage.discovery).toBe("complete"); expect( tightResult.value.objects.every((o) => o.inspection === "complete"), @@ -2774,11 +2696,10 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat } amdElf.copy(aliasedBundle, aliasedHeaderLen); - const amdWorkRefused = await inspect(aliasedBundle, { + const amdWorkRefused = await inspectSuccessfully(aliasedBundle, { analysis: "inventory", max_work_bytes: 16_384, }); - if (!amdWorkRefused.ok) throw amdWorkRefused.error; expect( amdWorkRefused.value.objects.some( (o) => @@ -2786,11 +2707,10 @@ it("keeps corrupt CCOB v1 recovery distinct from max_object_bytes window truncat o.limitations.some((l) => l.includes("(parameter: max_work_bytes)")), ), ).toBe(true); - const amdWorkRaised = await inspect(aliasedBundle, { + const amdWorkRaised = await inspectSuccessfully(aliasedBundle, { analysis: "inventory", max_work_bytes: 512 * 1024, }); - if (!amdWorkRaised.ok) throw amdWorkRaised.error; expect( amdWorkRaised.value.objects.some((o) => o.inspection === "capacity"), ).toBe(false); @@ -2828,12 +2748,11 @@ it("does not double-charge work on CCOB v1 refill, bounds aliased sections, keep expect(refillObjBudget).toBeGreaterThanOrEqual(b2.length); expect(refillObjBudget).toBeGreaterThanOrEqual(c2.length); const exactWorkOnce = refillObjBudget + b1.length + b2.length + c2.length; - const refillOnce = await inspect(refillPair, { + const refillOnce = await inspectSuccessfully(refillPair, { analysis: "inventory", max_object_bytes: refillObjBudget, max_work_bytes: exactWorkOnce, }); - if (!refillOnce.ok) throw refillOnce.error; expect( refillOnce.value.objects .filter((o) => o.kind === "hip-bundle") @@ -2873,11 +2792,10 @@ it("does not double-charge work on CCOB v1 refill, bounds aliased sections, keep manyV1, Buffer.alloc(16), ]); - const afterRefillNul = await inspect(refillThenNul, { + const afterRefillNul = await inspectSuccessfully(refillThenNul, { analysis: "inventory", max_object_bytes: manyEncoded.length, }); - if (!afterRefillNul.ok) throw afterRefillNul.error; const refillNulBundles = afterRefillNul.value.objects.filter( (o) => o.kind === "hip-bundle", ); @@ -2926,11 +2844,10 @@ it("does not double-charge work on CCOB v1 refill, bounds aliased sections, keep aliasedSectionElf.writeBigUInt64LE(BigInt(payloadOff), sh + 24); aliasedSectionElf.writeBigUInt64LE(BigInt(aliasedPtx.length), sh + 32); } - const aliasedSectionRefused = await inspect(aliasedSectionElf, { + const aliasedSectionRefused = await inspectSuccessfully(aliasedSectionElf, { analysis: "inventory", max_work_bytes: 16_384, }); - if (!aliasedSectionRefused.ok) throw aliasedSectionRefused.error; const nativeSections = aliasedSectionRefused.value.objects.filter( (o) => o.kind === "native-section", ); @@ -2954,11 +2871,10 @@ it("does not double-charge work on CCOB v1 refill, bounds aliased sections, keep const singleSectionPtxElf = elfFixture(62, [ { name: ".hip_fatbin", type: 1, bytes: sectionPtx6060 }, ]); - const singleSectionWorkOk = await inspect(singleSectionPtxElf, { + const singleSectionWorkOk = await inspectSuccessfully(singleSectionPtxElf, { analysis: "inventory", max_work_bytes: 6100, }); - if (!singleSectionWorkOk.ok) throw singleSectionWorkOk.error; expect( singleSectionWorkOk.value.objects.every( (o) => o.inspection === "complete" || o.inspection === "inventory", @@ -2969,11 +2885,13 @@ it("does not double-charge work on CCOB v1 refill, bounds aliased sections, keep ?.inspection, ).toBe("complete"); - const singleSectionObjRefused = await inspect(singleSectionPtxElf, { - analysis: "inventory", - max_object_bytes: 4096, - }); - if (!singleSectionObjRefused.ok) throw singleSectionObjRefused.error; + const singleSectionObjRefused = await inspectSuccessfully( + singleSectionPtxElf, + { + analysis: "inventory", + max_object_bytes: 4096, + }, + ); expect( singleSectionObjRefused.value.objects.find( (o) => o.kind === "native-section", @@ -2993,11 +2911,10 @@ it("does not double-charge work on CCOB v1 refill, bounds aliased sections, keep { name: ".hip_fatbin", type: 1, bytes: ccobStoredV2 }, ]); const ccobExactWork = 32 + 32 + ccobStoredV2.length + ccobInnerPayload.length; - const ccobSectionOk = await inspect(ccobInSectionElf, { + const ccobSectionOk = await inspectSuccessfully(ccobInSectionElf, { analysis: "inventory", max_work_bytes: ccobExactWork, }); - if (!ccobSectionOk.ok) throw ccobSectionOk.error; expect( ccobSectionOk.value.objects.find((o) => o.kind === "hip-bundle") ?.inspection, @@ -3013,11 +2930,10 @@ it("does not double-charge work on CCOB v1 refill, bounds aliased sections, keep { name: ".hip_fatbin", type: 1, bytes: innerElf }, ]); const nestedExactWork = innerElf.length + 256; - const nestedSectionOk = await inspect(outerElf, { + const nestedSectionOk = await inspectSuccessfully(outerElf, { analysis: "inventory", max_work_bytes: nestedExactWork, }); - if (!nestedSectionOk.ok) throw nestedSectionOk.error; expect( nestedSectionOk.value.objects .filter((o) => o.kind === "native-section") @@ -3037,11 +2953,10 @@ it("does not double-charge work on CCOB v1 refill, bounds aliased sections, keep { name: ".hip_fatbin", type: 1, bytes: nestedAmdBundle }, ]); const nestedAmdWork = nestedAmdElf.length + 512; - const nestedAmdOk = await inspect(nestedAmdSectionElf, { + const nestedAmdOk = await inspectSuccessfully(nestedAmdSectionElf, { analysis: "inventory", max_work_bytes: nestedAmdWork, }); - if (!nestedAmdOk.ok) throw nestedAmdOk.error; expect( nestedAmdOk.value.objects.some((o) => o.inspection === "capacity"), ).toBe(false); @@ -3146,28 +3061,26 @@ it("does not double-charge work on CCOB v1 refill, bounds aliased sections, keep ]); expect(corruptExact.length).toBe(200); const nextValidV2 = ccobFixture(2, "zlib", small1); - const exactRecovery = await inspect( + const exactRecovery = await inspectSuccessfully( Buffer.concat([corruptExact, nextValidV2]), { analysis: "inventory", max_object_bytes: corruptExact.length, }, ); - if (!exactRecovery.ok) throw exactRecovery.error; expect( exactRecovery.value.objects .filter((o) => o.kind === "hip-bundle") .map((o) => o.inspection), ).toEqual(["malformed", "complete"]); - const overRecovery = await inspect( + const overRecovery = await inspectSuccessfully( Buffer.concat([corruptExact, Buffer.of(0xff), nextValidV2]), { analysis: "inventory", max_object_bytes: corruptExact.length, }, ); - if (!overRecovery.ok) throw overRecovery.error; expect( overRecovery.value.objects .filter((o) => o.kind === "hip-bundle") @@ -3218,12 +3131,11 @@ it("applies max_structure_bytes independently of max_object_bytes and covers PE, bytes: Buffer.alloc(8), })), ); - const elfOk = await inspect(emptyElf, { + const elfOk = await inspectSuccessfully(emptyElf, { analysis: "inventory", max_object_bytes: 256, max_structure_bytes: 65_536, }); - if (!elfOk.ok) throw elfOk.error; expect(elfOk.value.format).toBe("elf"); expect(elfOk.value.coverage.discovery).toBe("complete"); @@ -3280,21 +3192,19 @@ it("applies max_structure_bytes independently of max_object_bytes and covers PE, // CUBIN CudaMetadataBudget respects max_parser_visits and recovers when raised. const cubinBytes = cubinFixture(); - const cubinLimited = await inspect(cubinBytes, { + const cubinLimited = await inspectSuccessfully(cubinBytes, { analysis: "kernels", max_parser_visits: 1, }); - if (!cubinLimited.ok) throw cubinLimited.error; expect(cubinLimited.value.objects[0]).toMatchObject({ inspection: "capacity", limitations: expect.arrayContaining([ expect.stringContaining("(parameter: max_parser_visits)"), ]), }); - const cubinRecovered = await inspect(cubinBytes, { + const cubinRecovered = await inspectSuccessfully(cubinBytes, { analysis: "kernels", max_parser_visits: 4096, }); - if (!cubinRecovered.ok) throw cubinRecovered.error; expect(cubinRecovered.value.objects[0]?.inspection).toBe("complete"); });