fix(native): keep lipo path echoes out of FAT records (#2605)
* fix(native): keep lipo path echoes out of FAT records Parse FAT records only after separating the exact echoed operand path. Pass the same lipo operand at all three consumers and cover multiline paths through parser, slice-reader and compiled CLI regressions. * fix(native): use parsed lipo framing for container offsets * test(native): use explicit FAT fixtures for CLI regressions
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import { copyFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
import { describe, expect } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
inspectMachoSchema,
|
||||
listArchitecturesSchema,
|
||||
} from "../../../src/domain/native/nativeInspection.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
@@ -34,27 +38,68 @@ const resultSchema = z.object({
|
||||
describe.skipIf(process.platform !== "darwin")(
|
||||
"native Mach-O CLI with echoed path text",
|
||||
() => {
|
||||
cliTest(
|
||||
"does not read load commands or symbols from the file name",
|
||||
async ({ cli }) => {
|
||||
const directory = await createTestTempDirectory("rea-macho-echo-");
|
||||
const inspect = async (name: string) => {
|
||||
const path = join(directory, name);
|
||||
await copyFile("/usr/bin/true", path);
|
||||
const result = await cli.run({
|
||||
arguments: ["inspect-macho", path, "--json"],
|
||||
environment,
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
const { provenance: _provenance, ...facts } = resultSchema.parse(
|
||||
result.json,
|
||||
).normalized_result;
|
||||
return facts;
|
||||
};
|
||||
const forged = await inspect(FORGED_NAME);
|
||||
expect(forged).toEqual(await inspect("tool"));
|
||||
expect(JSON.stringify(forged)).not.toMatch(/forged|4242/u);
|
||||
},
|
||||
);
|
||||
const lipoName = "tool\narchitecture forged\n offset 123\n size 32";
|
||||
for (const [facts, command, filename] of [
|
||||
["load commands or symbols", "inspect-macho", FORGED_NAME],
|
||||
["FAT architecture records", "inspect-macho", lipoName],
|
||||
["FAT architecture inventory", "list-architectures", lipoName],
|
||||
["thin-file framing", "inspect-macho", "tool\nNon-fat file: forged"],
|
||||
] as const) {
|
||||
cliTest(
|
||||
`does not read ${facts} from the file name`,
|
||||
async ({ cli, processes }) => {
|
||||
const directory = await createTestTempDirectory(
|
||||
"rea-native-cli-echo-",
|
||||
);
|
||||
const fixture = join(directory, "fat-fixture");
|
||||
const compiled = await processes.run(
|
||||
"/usr/bin/xcrun",
|
||||
[
|
||||
"clang",
|
||||
"-arch",
|
||||
"arm64",
|
||||
"-arch",
|
||||
"x86_64",
|
||||
resolve("tests/conformance/c/fixture.c"),
|
||||
"-o",
|
||||
fixture,
|
||||
],
|
||||
{ timeoutMs: 30_000 },
|
||||
);
|
||||
expect(compiled.exitCode, compiled.stderr).toBe(0);
|
||||
const inspect = async (name: string) => {
|
||||
const path = join(directory, name);
|
||||
await copyFile(fixture, path);
|
||||
const result = await cli.run({
|
||||
arguments: [command, path, "--json"],
|
||||
environment,
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
const { provenance: _provenance, ...facts } = resultSchema.parse(
|
||||
result.json,
|
||||
).normalized_result;
|
||||
return facts;
|
||||
};
|
||||
const ordinary = await inspect("tool");
|
||||
// Prove this comparison exercised FAT framing, independent of host binaries.
|
||||
const architectures =
|
||||
listArchitecturesSchema.shape.architectures.parse(
|
||||
ordinary.architectures,
|
||||
);
|
||||
expect(architectures.total).toBeGreaterThan(1);
|
||||
if (command === "inspect-macho") {
|
||||
const selected =
|
||||
inspectMachoSchema.shape.selected_architecture.parse(
|
||||
ordinary.selected_architecture,
|
||||
);
|
||||
expect(selected.container_file_offset).toBeGreaterThan(0);
|
||||
}
|
||||
const forged = await inspect(filename);
|
||||
expect(forged).toEqual(ordinary);
|
||||
expect(JSON.stringify(forged)).not.toMatch(/forged|4242/u);
|
||||
},
|
||||
60_000,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user