diff --git a/tests/boundary/mcp/goBinaryMcp.test.ts b/tests/boundary/mcp/goBinaryMcp.test.ts index 8141f67cd4..7aac6ffa1c 100644 --- a/tests/boundary/mcp/goBinaryMcp.test.ts +++ b/tests/boundary/mcp/goBinaryMcp.test.ts @@ -29,6 +29,7 @@ import { createGoBinaryByteStringFixture, createGoBinaryDiagnosticFixtures, createGoBinaryFixture, + createGoBinaryOneDirectoryFixture, createGoBinaryPathFailureFixture, } from "../../fixtures/go/image.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; @@ -288,6 +289,20 @@ goMcpTest( }, }); } + // A declared directory count below 16 is admitted, as the loader admits it. + const path = join(root, "one-directory.exe"); + await writeFile(path, createGoBinaryOneDirectoryFixture().bytes); + const admitted = await client.callTool({ + name: "inspect_go_binary", + arguments: { path }, + }); + expect(admitted.isError, JSON.stringify(admitted.content)).not.toBe(true); + expect( + goBinarySchema.parse( + (admitted.structuredContent as { normalized_result: unknown }) + .normalized_result, + ).build_info, + ).toMatchObject({ go_version: "go1.26.0" }); }, ); diff --git a/tests/fixtures/go/image.ts b/tests/fixtures/go/image.ts index 6446d8f961..5a9c37afc3 100644 --- a/tests/fixtures/go/image.ts +++ b/tests/fixtures/go/image.ts @@ -440,12 +440,11 @@ export const createGoBinaryDiagnosticFixtures = () => { { name: "damaged-pe", bytes: damagedPe }, ...highBitSignatures, ]; - const absentDirectories = createGoBinaryFixture({ format: "pe" }).bytes; - absentDirectories.writeUInt32LE(1, 152 + 108); + // The loader reads the optional header at its fixed offsets whatever + // SizeOfOptionalHeader declares, so an unknown magic there is unsupported. const shortOptionalHeaders = [0, 1].map((size) => { const bytes = createGoBinaryFixture({ format: "pe" }).bytes; bytes.writeUInt16LE(size, 148); - // Bytes following the declared header must not supply its magic field. bytes.fill(0xff, 152 + size, 154); return { name: `optional-header-${String(size)}-bytes`, bytes }; }); @@ -460,20 +459,27 @@ export const createGoBinaryDiagnosticFixtures = () => { code: "unsupported_target" as const, details: { operation: "inspect_go_binary" }, })), - ...[ - { name: "absent-directories", bytes: absentDirectories }, - ...shortOptionalHeaders, - ].map((fixture) => ({ + ...shortOptionalHeaders.map((fixture) => ({ ...fixture, code: "unsupported_target" as const, details: { operation: "inspect_go_binary", - format_failure: "malformed", + reason: "Only PE32 and PE32+ image optional headers are supported", }, })), ]; }; +/** + * A PE that declares one data directory. The loader admits it, and the Go + * build information is found by section scan, so inspection succeeds. + */ +export const createGoBinaryOneDirectoryFixture = () => { + const fixture = createGoBinaryFixture({ format: "pe" }); + fixture.bytes.writeUInt32LE(1, 152 + 108); + return fixture; +}; + const encodeVarint = (input: number): Buffer => { let value = BigInt(input); const bytes: number[] = [];