Files
rea/tests/boundary/cli/nativeMachoLinkerOptionsCli.test.ts
Kaoru0822andClaude Opus 5.5 47b4628bac fix(native): retain every repeated otool load-command field (#4048)
`inspect-macho` stored each `otool -l` row in a flat record, so a key
printed more than once kept only its last value. A two-string
LC_LINKER_OPTION lost `-framework` and kept `#2 Foundation`, and a
multi-tool LC_BUILD_VERSION kept only its last tool, while the
collection still claimed exhaustive coverage.

Linker-option strings are now keyed by otool's own `string #n` label
with the exact option text and must match the declared count. Any other
repeated key is labeled `key #n` in print order. Dylib encoding checks
read the parsed rows, so repeated `options` rows are still rejected.

Fixes #4008

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 02:29:06 -07:00

69 lines
2.2 KiB
TypeScript

import { join } from "node:path";
import { writeFile } from "node:fs/promises";
import { describe, expect } from "vitest";
import { z } from "zod";
import { inspectMachoSchema } from "../../../src/domain/native/nativeInspection.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
const evidenceSchema = z.object({ normalized_result: inspectMachoSchema });
describe.skipIf(process.platform !== "darwin")(
"native Mach-O CLI linker options",
() => {
cliTest(
"retains every compiler-recorded linker option string in order",
async ({ cli, processes }) => {
const directory = await createTestTempDirectory("rea-linker-option-");
const source = join(directory, "options.c");
const object = join(directory, "options.o");
await writeFile(
source,
[
'__asm__(".linker_option \\"-framework\\", \\"Foundation\\"");',
'__asm__(".linker_option \\"-lz\\"");',
"int sample(void) { return 7; }",
"",
].join("\n"),
);
const compiled = await processes.run(
"/usr/bin/xcrun",
["clang", "-c", source, "-o", object],
{ timeoutMs: 30_000 },
);
expect(compiled.exitCode, compiled.stderr).toBe(0);
const result = await cli.run({
arguments: ["inspect-macho", object, "--json"],
environment: { REA_LOG_LEVEL: "silent" },
});
expect(result.exitCode).toBe(0);
const { load_commands: loadCommands } = evidenceSchema.parse(
result.json,
).normalized_result;
expect(loadCommands.exhaustive).toBe(true);
expect(
loadCommands.items
.filter((command) => command.kind === "LC_LINKER_OPTION")
.map(({ fields }) => fields),
).toEqual([
{
cmd: "LC_LINKER_OPTION",
cmdsize: 40,
count: 2,
"string #1": "-framework",
"string #2": "Foundation",
},
{
cmd: "LC_LINKER_OPTION",
cmdsize: 16,
count: 1,
"string #1": "-lz",
},
]);
},
);
},
);