From adaa04d9cef58eb23d665d211356b213bfc87e3b Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Wed, 18 Nov 2026 06:12:39 +0800 Subject: [PATCH] test(elf): verify debuglink checksums at the file boundary (#11863) --- src/native/elf/ElfDebugLink.test.ts | 238 +----------------- src/native/elf/ElfDebugLink.ts | 16 -- src/native/elf/ElfDebugLinkNameBudget.test.ts | 14 +- tests/acceptance/elfDebugLinkCli.test.ts | 27 +- .../boundary/filesystem/elfDebugLink.test.ts | 92 +++++-- tests/boundary/mcp/elfDebugLinkMcp.test.ts | 8 +- 6 files changed, 96 insertions(+), 299 deletions(-) diff --git a/src/native/elf/ElfDebugLink.test.ts b/src/native/elf/ElfDebugLink.test.ts index c64b4b1e5d..369c4fa352 100644 --- a/src/native/elf/ElfDebugLink.test.ts +++ b/src/native/elf/ElfDebugLink.test.ts @@ -3,13 +3,10 @@ import { expect, it } from "vitest"; import { ParseFailureError } from "../../domain/parseFailure.js"; import { - ELF_DEBUG_LINK_CANDIDATE_BUDGET_LIMITATION, - ELF_DEBUG_LINK_CANDIDATE_PREFIX_LIMITATION, ELF_DEBUG_LINK_CANDIDATE_UNREADABLE_LIMITATION, ELF_DEBUG_LINK_CANNOT_VERIFY_LIMITATION, ELF_DEBUG_LINK_MULTIPLE_BUILD_IDS_LIMITATION, ELF_DEBUG_LINK_NAME_SEGMENT_LIMITATION, - ELF_DEBUG_LINK_UNAVAILABLE_CHECK_LIMITATION, elfDebugLinkSchema, inspectElfDebugLinkInputSchema, } from "../../domain/native/elfDebugLink.js"; @@ -17,9 +14,6 @@ import { gnuBuildIdNote } from "./ElfNotes.fixture.js"; import { parseElfNotes } from "./ElfNoteParser.js"; import { readElfImage } from "../../domain/native/elfImage.js"; import { - continueGnuDebuglinkCrc32, - gnuDebuglinkCrc32, - gnuDebuglinkCrc32Hex, parseElfDebugLink, unreadableElfDebugCandidate, verifyElfDebugCandidate, @@ -53,18 +47,6 @@ const parse = ( ), ); -it("matches the known CRC32 of 123456789 and chunked continuation", () => { - const classic = Buffer.from("123456789", "latin1"); - expect(gnuDebuglinkCrc32(classic)).toBe(0xcbf43926); - expect(gnuDebuglinkCrc32Hex(classic)).toBe("cbf43926"); - const wide = Buffer.alloc(100, 0x5a); - let continued = 0; - for (let offset = 0; offset < wide.length; offset += 16) - continued = crc32(wide.subarray(offset, offset + 16), continued); - expect(gnuDebuglinkCrc32(wide)).toBe(continued >>> 0); - expect(gnuDebuglinkCrc32(wide)).toBe(crc32(wide) >>> 0); -}); - it("reads a little-endian debuglink CRC, build-id, and lookup paths", () => { const report = parse(elfDebugLinkFixture()); expect(report).toMatchObject({ @@ -101,18 +83,6 @@ it("reads a little-endian debuglink CRC, build-id, and lookup paths", () => { expect(report.verification).toBeNull(); }); -it("reads a big-endian ELF32 debuglink CRC", () => { - const report = parse( - elfDebugLinkFixture({ bits: 32, little: false, machine: 20 }), - ); - expect(report).toMatchObject({ - format: "elf32", - byte_order: "big", - machine: 20, - debuglink: { status: "present", crc32_hex: "12345678" }, - }); -}); - it("keeps the CRC across padding, trailing bytes, and an overlong name", () => { const padded = debuglinkSection("ab", 0x89abcdef, true); expect(padded.length).toBe(8); @@ -378,7 +348,7 @@ const verify = (image: Buffer, candidate: Buffer, candidatePath: string) => { path: candidatePath, sha256: digest, bytes: candidate.length, - crc32: gnuDebuglinkCrc32(candidate), + crc32: crc32(candidate), prefix: candidate, }, inputFor(), @@ -386,30 +356,6 @@ const verify = (image: Buffer, candidate: Buffer, candidatePath: string) => { ); }; -it("matches a candidate by CRC32 and build-id and records its sections", () => { - const candidate = elfDebugCandidateFixture(); - const image = elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), - }); - const report = verify(image, candidate, "/artifacts/prog.debug"); - expect(report.verification).toMatchObject({ - status: "matches", - reason: null, - crc32: { status: "match", observed_hex: gnuDebuglinkCrc32Hex(candidate) }, - build_id: { status: "match", candidate_hex: FIXTURE_BUILD_ID_HEX }, - }); - expect(report.candidate).toMatchObject({ - path: "/artifacts/prog.debug", - format: "elf64", - debug_info: "present", - symtab: "present", - }); -}); - it("counts legacy .zdebug_info as present candidate debug info", () => { const candidate = elfDebugCandidateFixture({ zdebugInfo: true }); const sections = readElfImage(candidate).sections; @@ -424,11 +370,7 @@ it("counts legacy .zdebug_info as present candidate debug info", () => { ), ).toBe(false); const image = elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), + debuglink: debuglinkSection(FIXTURE_DEBUG_NAME, crc32(candidate), true), }); const report = verify(image, candidate, "/artifacts/prog.debug"); expect(report.candidate).toMatchObject({ debug_info: "present" }); @@ -459,11 +401,7 @@ it("leaves candidate sections whose range is outside the file unknown", () => { ".symtab", ); const image = elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), + debuglink: debuglinkSection(FIXTURE_DEBUG_NAME, crc32(candidate), true), }); const report = verify(image, candidate, "/artifacts/prog.debug"); expect(report.verification?.build_id).toMatchObject({ status: "match" }); @@ -487,57 +425,6 @@ it("reports CRC32 and build-id mismatches together", () => { }); }); -it("matches CRC32 of a non-ELF candidate and leaves build-id unverified", () => { - const candidate = Buffer.from("not an elf", "latin1"); - const image = elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), - }); - const report = verify(image, candidate, "/artifacts/plain.debug"); - expect(report.candidate).toMatchObject({ - format: null, - byte_order: null, - debug_info: "not_elf", - symtab: "not_elf", - }); - expect(report.verification).toMatchObject({ - status: "matches", - crc32: { status: "match" }, - build_id: { status: "unavailable", reason: "candidate_not_elf" }, - }); - expect(report.limitations).toContain( - ELF_DEBUG_LINK_UNAVAILABLE_CHECK_LIMITATION, - ); -}); - -it("reports a candidate with ELF magic and a bad header as malformed ELF", () => { - // ELF magic, ELFCLASS64, little-endian, then an unsupported EI_VERSION. - const candidate = Buffer.alloc(64); - candidate.set([0x7f, 0x45, 0x4c, 0x46, 2, 1, 9]); - const image = elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), - }); - const report = verify(image, candidate, "/artifacts/bad-header.debug"); - expect(report.candidate).toMatchObject({ - format: null, - byte_order: null, - debug_info: "unknown", - symtab: "unknown", - }); - expect(report.verification).toMatchObject({ - status: "matches", - crc32: { status: "match" }, - build_id: { status: "unavailable", reason: "candidate_elf_malformed" }, - }); -}); - it("cannot verify when neither CRC32 nor build-id is comparable", () => { const image = elfDebugLinkFixture({ debuglink: null, notes: null }); const candidate = elfDebugCandidateFixture({ buildIdHex: null }); @@ -550,127 +437,10 @@ it("cannot verify when neither CRC32 nor build-id is comparable", () => { crc32: { status: "unavailable", reason: "debuglink_crc_absent" }, build_id: { status: "unavailable", reason: "binary_build_id_absent" }, }); - expect(report.verification?.crc32.observed_hex).toBe( - gnuDebuglinkCrc32Hex(candidate), - ); + expect(report.verification?.crc32.observed_hex).toBe("314f0306"); expect(report.limitations).toContain(ELF_DEBUG_LINK_CANNOT_VERIFY_LIMITATION); }); -it("verifies a streamed candidate by CRC32 when only its header was retained", () => { - const candidate = elfDebugCandidateFixture(); - const image = elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), - }); - const report = parseElfDebugLink( - image, - { path: artifactPath, sha256: digest, bytes: image.length }, - inputFor(), - ); - let streamed = 0; - for (let offset = 0; offset < candidate.length; offset += 7) - streamed = continueGnuDebuglinkCrc32( - streamed, - candidate.subarray(offset, offset + 7), - ); - const verified = elfDebugLinkSchema.parse( - verifyElfDebugCandidate( - report, - { - path: "/artifacts/prog.debug", - sha256: digest, - bytes: candidate.length, - crc32: streamed, - prefix: candidate.subarray(0, 64), - }, - inputFor(), - ), - ); - expect(verified.candidate).toMatchObject({ - format: "elf64", - byte_order: "little", - debug_info: "unknown", - symtab: "unknown", - }); - expect(verified.verification).toMatchObject({ - status: "matches", - crc32: { status: "match" }, - build_id: { status: "unavailable", reason: "candidate_build_id_unknown" }, - }); - expect(verified.limitations).toEqual( - expect.arrayContaining([ - ELF_DEBUG_LINK_CANDIDATE_PREFIX_LIMITATION, - ELF_DEBUG_LINK_UNAVAILABLE_CHECK_LIMITATION, - ]), - ); -}); - -it("keeps the image linkage when the candidate exceeds the note entry budget", () => { - const candidate = elfDebugLinkFixture({ - debuglink: null, - notes: Buffer.concat([ - gnuBuildIdNote(FIXTURE_BUILD_ID_HEX, true), - gnuBuildIdNote("bb".repeat(20), true), - ]), - debugInfo: Buffer.from("debug-info", "latin1"), - }); - const image = elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), - }); - const input = inputFor({ max_entries: 1 }); - const report = parseElfDebugLink( - image, - { path: artifactPath, sha256: digest, bytes: image.length }, - input, - ); - const verified = elfDebugLinkSchema.parse( - verifyElfDebugCandidate( - report, - { - path: "/artifacts/prog.debug", - sha256: digest, - bytes: candidate.length, - crc32: gnuDebuglinkCrc32(candidate), - prefix: candidate, - }, - input, - ), - ); - expect(verified.debuglink.status).toBe("present"); - expect(verified.build_id).toMatchObject({ - status: "observed", - hex: FIXTURE_BUILD_ID_HEX, - }); - expect(verified.candidate).toMatchObject({ - format: "elf64", - debug_info: "present", - symtab: "absent", - }); - expect(verified.verification).toMatchObject({ - status: "matches", - crc32: { status: "match" }, - build_id: { - status: "unavailable", - binary_hex: FIXTURE_BUILD_ID_HEX, - candidate_hex: null, - reason: "candidate_build_id_unknown", - }, - }); - expect(verified.limitations).toEqual( - expect.arrayContaining([ - ELF_DEBUG_LINK_CANDIDATE_BUDGET_LIMITATION, - ELF_DEBUG_LINK_UNAVAILABLE_CHECK_LIMITATION, - ]), - ); -}); - it("keeps the image linkage when the candidate cannot be read", () => { const image = elfDebugLinkFixture({ debuglink: debuglinkSection(FIXTURE_DEBUG_NAME, 0x12345678, true), diff --git a/src/native/elf/ElfDebugLink.ts b/src/native/elf/ElfDebugLink.ts index ead2b1dcd0..5048ee5f52 100644 --- a/src/native/elf/ElfDebugLink.ts +++ b/src/native/elf/ElfDebugLink.ts @@ -41,7 +41,6 @@ const DEBUG_SECTION_NAMES = [ ".gnu_debugdata", ] as const; const XZ_MAGIC = Buffer.from([0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00]); -const CRC_CHUNK = 65536; const GNU_BUILD_ID_NOTE_TYPE = 3; const fits = (offset: bigint, size: bigint, fileLength: number): boolean => @@ -81,27 +80,12 @@ const untrustedName = ( const crc32Hex = (value: number): string => (value >>> 0).toString(16).padStart(8, "0"); -/** GNU debuglink CRC32 of one bounded buffer. Continuation matches one-shot. */ -export const gnuDebuglinkCrc32 = (bytes: Buffer): number => { - let value = 0; - for (let offset = 0; offset < bytes.length; offset += CRC_CHUNK) - value = crc32( - bytes.subarray(offset, Math.min(offset + CRC_CHUNK, bytes.length)), - value, - ); - return value >>> 0; -}; - /** Continue a GNU debuglink CRC32 over the next streamed chunk. */ export const continueGnuDebuglinkCrc32 = ( value: number, chunk: Buffer, ): number => crc32(chunk, value) >>> 0; -/** Eight lowercase hex digits for a GNU debuglink CRC32. */ -export const gnuDebuglinkCrc32Hex = (bytes: Buffer): string => - crc32Hex(gnuDebuglinkCrc32(bytes)); - const isRethrownBudget = (cause: unknown): boolean => isParseLimit(cause, "elf") || isParseLimit(cause, "elf-notes") || diff --git a/src/native/elf/ElfDebugLinkNameBudget.test.ts b/src/native/elf/ElfDebugLinkNameBudget.test.ts index 6f978faf63..ccb0769f69 100644 --- a/src/native/elf/ElfDebugLinkNameBudget.test.ts +++ b/src/native/elf/ElfDebugLinkNameBudget.test.ts @@ -1,4 +1,4 @@ -import { deflateSync } from "node:zlib"; +import { crc32, deflateSync } from "node:zlib"; import { afterEach, expect, it, vi } from "vitest"; const zlib = vi.hoisted(() => ({ inflated: 0 })); @@ -18,11 +18,7 @@ import { ELF_DEBUG_LINK_CANDIDATE_BUDGET_LIMITATION, inspectElfDebugLinkInputSchema, } from "../../domain/native/elfDebugLink.js"; -import { - gnuDebuglinkCrc32, - parseElfDebugLink, - verifyElfDebugCandidate, -} from "./ElfDebugLink.js"; +import { parseElfDebugLink, verifyElfDebugCandidate } from "./ElfDebugLink.js"; import { elfDebugCandidateFixture, elfDebugLinkFixture, @@ -117,7 +113,7 @@ it("leaves compressed candidate names above the selected budget undecoded", () = path: "/artifacts/prog.debug", sha256: "cd".repeat(32), bytes: candidate.length, - crc32: gnuDebuglinkCrc32(candidate), + crc32: crc32(candidate), prefix: candidate, }, input, @@ -169,7 +165,7 @@ it("keeps the build-id of a candidate whose names use an unsupported compression path: "/artifacts/prog.debug", sha256: "cd".repeat(32), bytes: candidate.length, - crc32: gnuDebuglinkCrc32(candidate), + crc32: crc32(candidate), prefix: candidate, }, input, @@ -215,7 +211,7 @@ it("leaves compressed candidate names undecoded when only section zero declares path: "/artifacts/prog.debug", sha256: "cd".repeat(32), bytes: candidate.length, - crc32: gnuDebuglinkCrc32(candidate), + crc32: crc32(candidate), prefix: candidate, }, input, diff --git a/tests/acceptance/elfDebugLinkCli.test.ts b/tests/acceptance/elfDebugLinkCli.test.ts index 32318e711d..cf00f7a96d 100644 --- a/tests/acceptance/elfDebugLinkCli.test.ts +++ b/tests/acceptance/elfDebugLinkCli.test.ts @@ -3,10 +3,6 @@ import { dirname, join } from "node:path"; import { expect } from "vitest"; import { contractNamed } from "../../src/cli/contractCliDescription.js"; import { BINARY_DIAGNOSTICS_TOOL_CONTRACTS } from "../../src/contracts/native/binaryDiagnosticsToolContracts.js"; -import { - gnuDebuglinkCrc32, - gnuDebuglinkCrc32Hex, -} from "../../src/native/elf/ElfDebugLink.js"; import { debuglinkSection, elfDebugCandidateFixture, @@ -28,11 +24,7 @@ cliTest( const root = await createTestTempDirectory("rea-elf-debug-link-cli-"); const candidate = elfDebugCandidateFixture(); const image = elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), + debuglink: debuglinkSection(FIXTURE_DEBUG_NAME, 0xae159abd, true), }); const imagePath = join(root, "prog"); const candidatePath = join(root, "prog.debug"); @@ -53,14 +45,23 @@ cliTest( path: imagePath, candidate_path: candidatePath, }); - expect(evidence.normalized_result.verification?.status).toBe("matches"); + expect(evidence.normalized_result.verification).toMatchObject({ + status: "matches", + reason: null, + crc32: { + status: "match", + expected_hex: "ae159abd", + observed_hex: "ae159abd", + }, + build_id: { status: "match", candidate_hex: FIXTURE_BUILD_ID_HEX }, + }); expect(evidence.normalized_result.candidate).toMatchObject({ + path: candidatePath, + format: "elf64", debug_info: "present", symtab: "present", }); - expect(evidence.normalized_result.debuglink.crc32_hex).toBe( - gnuDebuglinkCrc32Hex(candidate), - ); + expect(evidence.normalized_result.debuglink.crc32_hex).toBe("ae159abd"); expect(evidence.normalized_result.build_id.hex).toBe(FIXTURE_BUILD_ID_HEX); expect(evidence.normalized_result.debuglink.filename?.trust).toBe( "observed-untrusted", diff --git a/tests/boundary/filesystem/elfDebugLink.test.ts b/tests/boundary/filesystem/elfDebugLink.test.ts index d44eb64269..c28cb83ffe 100644 --- a/tests/boundary/filesystem/elfDebugLink.test.ts +++ b/tests/boundary/filesystem/elfDebugLink.test.ts @@ -1,3 +1,4 @@ +import { crc32 } from "node:zlib"; import { mkdir, symlink, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; @@ -6,9 +7,9 @@ import { createElfDebugLinkService } from "../../../src/composition/binaryDiagno import { ELF_DEBUG_LINK_CANDIDATE_BUDGET_LIMITATION, ELF_DEBUG_LINK_CANDIDATE_PREFIX_LIMITATION, + ELF_DEBUG_LINK_UNAVAILABLE_CHECK_LIMITATION, elfDebugLinkSchema, } from "../../../src/domain/native/elfDebugLink.js"; -import { gnuDebuglinkCrc32 } from "../../../src/native/elf/ElfDebugLink.js"; import { gnuBuildIdNote } from "../../../src/native/elf/ElfNotes.fixture.js"; import { debuglinkSection, @@ -152,6 +153,44 @@ describe("ELF debug-link stable filesystem boundary", () => { }); describe("ELF debug-link streamed candidate boundary", () => { + it("matches the known CRC32 of a non-ELF candidate", async () => { + const root = await createTestTempDirectory("rea-elf-debug-link-crc32-"); + const path = join(root, "prog"); + const candidatePath = join(root, FIXTURE_DEBUG_NAME); + await writeFile( + path, + elfDebugLinkFixture({ + debuglink: debuglinkSection(FIXTURE_DEBUG_NAME, 0xcbf43926, true), + }), + ); + await writeFile(candidatePath, "123456789"); + const service = createElfDebugLinkService(); + try { + const result = await service.inspect({ + path, + candidate_path: candidatePath, + }); + if (!result.ok) throw result.error; + const report = elfDebugLinkSchema.parse(result.value.normalized_result); + expect(report.candidate).toMatchObject({ + format: null, + byte_order: null, + debug_info: "not_elf", + symtab: "not_elf", + }); + expect(report.verification).toMatchObject({ + status: "matches", + crc32: { status: "match", observed_hex: "cbf43926" }, + build_id: { status: "unavailable", reason: "candidate_not_elf" }, + }); + expect(report.limitations).toContain( + ELF_DEBUG_LINK_UNAVAILABLE_CHECK_LIMITATION, + ); + } finally { + await service.close(); + } + }); + it("streams a candidate larger than the image read budget", async () => { const root = await createTestTempDirectory("rea-elf-debug-link-stream-"); // Trailing padding keeps the ELF header while exceeding several chunks. @@ -160,11 +199,7 @@ describe("ELF debug-link streamed candidate boundary", () => { Buffer.alloc(200_000, 0x5a), ]); const image = elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), + debuglink: debuglinkSection(FIXTURE_DEBUG_NAME, 0x5f6d3801, true), }); const path = join(root, "prog"); const candidatePath = join(root, FIXTURE_DEBUG_NAME); @@ -183,25 +218,35 @@ describe("ELF debug-link streamed candidate boundary", () => { expect(report.candidate).toMatchObject({ bytes: candidate.length, format: "elf64", + byte_order: "little", debug_info: "unknown", symtab: "unknown", }); expect(report.verification).toMatchObject({ status: "matches", - crc32: { status: "match" }, + crc32: { + status: "match", + expected_hex: "5f6d3801", + observed_hex: "5f6d3801", + }, build_id: { status: "unavailable", reason: "candidate_build_id_unknown", }, }); - expect(report.limitations).toContain( - ELF_DEBUG_LINK_CANDIDATE_PREFIX_LIMITATION, + expect(report.limitations).toEqual( + expect.arrayContaining([ + ELF_DEBUG_LINK_CANDIDATE_PREFIX_LIMITATION, + ELF_DEBUG_LINK_UNAVAILABLE_CHECK_LIMITATION, + ]), ); } finally { await service.close(); } }); +}); +describe("ELF debug-link candidate degradation", () => { it.each([ ["with", "candidate_elf_malformed"], ["without", "binary_build_id_absent"], @@ -216,11 +261,7 @@ describe("ELF debug-link streamed candidate boundary", () => { candidate.set([0x7f, 0x45, 0x4c, 0x46, 2, 1, 9]); const image = elfDebugLinkFixture({ ...(presence === "with" ? {} : { notes: null }), - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), + debuglink: debuglinkSection(FIXTURE_DEBUG_NAME, crc32(candidate), true), }); const path = join(root, "prog"); const candidatePath = join(root, FIXTURE_DEBUG_NAME); @@ -236,6 +277,7 @@ describe("ELF debug-link streamed candidate boundary", () => { const report = elfDebugLinkSchema.parse(result.value.normalized_result); expect(report.candidate).toMatchObject({ format: null, + byte_order: null, debug_info: "unknown", symtab: "unknown", }); @@ -254,17 +296,14 @@ describe("ELF debug-link streamed candidate boundary", () => { const root = await createTestTempDirectory("rea-elf-debug-link-entries-"); const candidate = elfDebugLinkFixture({ debuglink: null, + debugInfo: Buffer.from("debug-info", "latin1"), notes: Buffer.concat([ gnuBuildIdNote(FIXTURE_BUILD_ID_HEX, true), gnuBuildIdNote("bb".repeat(20), true), ]), }); const image = elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), + debuglink: debuglinkSection(FIXTURE_DEBUG_NAME, crc32(candidate), true), }); const path = join(root, "prog"); const candidatePath = join(root, FIXTURE_DEBUG_NAME); @@ -283,16 +322,27 @@ describe("ELF debug-link streamed candidate boundary", () => { status: "observed", hex: FIXTURE_BUILD_ID_HEX, }); + expect(report.debuglink.status).toBe("present"); + expect(report.candidate).toMatchObject({ + format: "elf64", + debug_info: "present", + symtab: "absent", + }); expect(report.verification).toMatchObject({ status: "matches", crc32: { status: "match" }, build_id: { status: "unavailable", + binary_hex: FIXTURE_BUILD_ID_HEX, + candidate_hex: null, reason: "candidate_build_id_unknown", }, }); - expect(report.limitations).toContain( - ELF_DEBUG_LINK_CANDIDATE_BUDGET_LIMITATION, + expect(report.limitations).toEqual( + expect.arrayContaining([ + ELF_DEBUG_LINK_CANDIDATE_BUDGET_LIMITATION, + ELF_DEBUG_LINK_UNAVAILABLE_CHECK_LIMITATION, + ]), ); } finally { await service.close(); diff --git a/tests/boundary/mcp/elfDebugLinkMcp.test.ts b/tests/boundary/mcp/elfDebugLinkMcp.test.ts index f763488886..7a7a9845a3 100644 --- a/tests/boundary/mcp/elfDebugLinkMcp.test.ts +++ b/tests/boundary/mcp/elfDebugLinkMcp.test.ts @@ -1,10 +1,10 @@ +import { crc32 } from "node:zlib"; import { writeFile } from "node:fs/promises"; import { join } from "node:path"; import { expect } from "vitest"; import { contractNamed } from "../../../src/cli/contractCliDescription.js"; import { BINARY_DIAGNOSTICS_TOOL_CONTRACTS } from "../../../src/contracts/native/binaryDiagnosticsToolContracts.js"; import { createServer } from "../../../src/server/createServer.js"; -import { gnuDebuglinkCrc32 } from "../../../src/native/elf/ElfDebugLink.js"; import { debuglinkSection, elfDebugCandidateFixture, @@ -102,11 +102,7 @@ mcpTest("verifies one caller-selected debug file", async ({ mcp }) => { await writeFile( imagePath, elfDebugLinkFixture({ - debuglink: debuglinkSection( - FIXTURE_DEBUG_NAME, - gnuDebuglinkCrc32(candidate), - true, - ), + debuglink: debuglinkSection(FIXTURE_DEBUG_NAME, crc32(candidate), true), }), ); await writeFile(candidatePath, candidate);