Files
reverse-engineering-anything/tests/boundary/cli/foreignUniversalMachoCli.test.ts
T
84990f9777 test: remove fixed child-process deadlines from tests
239 literal timeoutMs values on cli.run and processes.run only restated
a guess at host speed. On hosted runners with four workers, cliOutput's
3-second value failed while the command still produced correct output.
Deadlines that are the behavior under test, derived from an operation
budget, or that bound a regression's wait remain.

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 13:21:13 +08:00

88 lines
2.9 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join, resolve } from "node:path";
import { expect } from "vitest";
import { z } from "zod";
import { fat } from "../../../src/domain/binaryTarget.fixture.js";
import { listArchitecturesSchema } from "../../../src/domain/native/nativeInspection.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
const environment = { REA_LOG_LEVEL: "silent" } as const;
// The one slice of each container below is never the host's architecture.
const foreign =
process.arch === "arm64"
? { name: "x86_64", cpuType: 0x01000007 }
: { name: "arm64", cpuType: 0x0100000c };
cliTest.skipIf(process.platform !== "darwin")(
"inventories a universal Mach-O whose only slice is foreign to the host",
async ({ cli, processes }) => {
const directory = await createTestTempDirectory("rea-foreign-fat-cli-");
const thin = join(directory, "thin");
const universal = join(directory, "universal");
const compiled = await processes.run("/usr/bin/xcrun", [
"clang",
"-arch",
foreign.name,
resolve("tests/conformance/c/fixture.c"),
"-o",
thin,
]);
expect(compiled.exitCode, compiled.stderr).toBe(0);
const created = await processes.run("/usr/bin/xcrun", [
"lipo",
"-create",
thin,
"-output",
universal,
]);
expect(created.exitCode, created.stderr).toBe(0);
const result = await cli.run({
arguments: ["list-architectures", universal, "--json"],
environment,
});
expect(result.exitCode, result.stderr).toBe(0);
const evidence = z
.object({
subject: z.object({ format: z.string() }),
normalized_result: listArchitecturesSchema,
})
.parse(result.json);
expect(evidence.subject.format).toBe("mach-o-universal");
expect(evidence.normalized_result.architectures).toMatchObject({
total: 1,
exhaustive: true,
items: [{ name: foreign.name }],
});
expect(
evidence.normalized_result.architectures.items[0]?.file_offset,
).toBeGreaterThan(0);
},
);
cliTest.skipIf(process.platform === "darwin")(
"admits a universal Mach-O whose only slice is foreign to the host",
async ({ cli }) => {
const directory = await createTestTempDirectory("rea-foreign-fat-cli-");
const universal = join(directory, "universal");
await writeFile(universal, fat([foreign.cpuType]));
const result = await cli.run({
arguments: ["list-architectures", universal, "--json"],
environment,
});
// The target is admitted; only the macOS-only lipo inventory is refused.
expect(result.exitCode).not.toBe(0);
expect(result.json).toMatchObject({
code: "capability_unavailable",
details: { provider_id: "native-macos", operation: "list_architectures" },
});
},
);