Files
reverse-engineering-anything/tests/boundary/cli/nativeMachoLinkerOptionsCli.test.ts
T
gensokyo-devandgensokyo-dev c169e8d56e test(native): assert universal slice refusals by their input issue
The MCP universal-slice refusal test also compared whole English
messages; it now checks the architecture input issue and only the
offered selector. The linker-options CLI test drops its per-call child
timeout, which the testing guide reserves for testing the deadline.

Refs #9792
Refs #8935

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-11-14 12:13:56 +01:00

118 lines
3.9 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,
]);
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, result.stdout + result.stderr).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),
).toMatchObject([
{
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",
},
]);
},
);
cliTest(
"does not report undecoded payload for an exact linker option command",
async ({ cli, processes }) => {
const directory = await createTestTempDirectory("rea-linker-option-");
const source = join(directory, "option.c");
const object = join(directory, "option.o");
await writeFile(
source,
[
'__asm__(".linker_option \\"-lz\\"");',
"int sample(void) { return 7; }",
"",
].join("\n"),
);
const compiled = await processes.run("/usr/bin/xcrun", [
"clang",
"-c",
source,
"-o",
object,
]);
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, result.stdout + result.stderr).toBe(0);
const { load_commands: loadCommands } = evidenceSchema.parse(
result.json,
).normalized_result;
const option = loadCommands.items.find(
(command) => command.kind === "LC_LINKER_OPTION",
);
expect(option?.fields).toMatchObject({
cmd: "LC_LINKER_OPTION",
cmdsize: 16,
count: 1,
"string #1": "-lz",
});
expect(option?.fields).not.toHaveProperty("command_sha256");
expect(loadCommands.limitations).not.toEqual(
expect.arrayContaining([
expect.stringContaining("payload fields are not decoded"),
]),
);
},
);
},
);