Files
rea/src/artifacts/MachOSliceArchitecture.test.ts
T
To3akaRin 1684c73d4f fix(artifacts): reconcile ARM32 Mach-O slice names by subtype (#4352)
* fix(artifacts): reconcile ARM32 Mach-O slice names with subtypes

* test(snapshot): preserve Evidence-scoped native workflow unknowns

* test(process): assert owned snapshot cancellation outcomes

* test(process): preserve snapshot race causes and owned cleanup

* test(cli): scope runtime cleanup provider injection

CLI boundary tests share a module graph. The cleanup fixture's module mock
cannot replace a provider factory already captured by the real command
registration, leaving its close count at zero after another test imports it.

Inject a typed provider factory into the registration instance, defaulting
to the existing production factory. Both commands still create their own
provider at execution time. Remove the redundant runtime context wrapper
and the global mock state. Keep the real child CLI parity case and verify
that neither command completion nor JSON output precedes awaited cleanup;
retain the close-count, cleanup error and completed Evidence assertions.

The unchanged test passes alone but fails with the command module preloaded.
Both modes pass after the correction. Seven related files pass 28 tests;
check and docs:check also pass on Node24.18.0/npm11.16.0 macOS arm64.

* test(artifacts): use valid ASAR bytes for signature control

* test(mcp): isolate snapshot filesystem fault injection

* test(process): distinguish unacquired resources in failure progress

---------

Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 02:29:48 +08:00

109 lines
3.0 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it, onTestFinished } from "vitest";
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
import { ok } from "../domain/result.js";
import { fatImage, machoImage } from "./apple/MachoImage.fixture.js";
import { MachOSliceArtifactReader } from "./MachOSliceArtifactReader.js";
const armSlices = async (
name: string,
subtype: number,
reported: {
readonly type?: number;
readonly subtype?: number;
readonly offset?: number;
readonly size?: number;
readonly alignment?: number;
} = {},
) => {
const root = await createTestTempDirectory("rea-arm-slice-identity-");
const path = join(root, "fat");
const cpu = { type: 12, subtype };
const bytes = machoImage({ cpu, wide: false });
await writeFile(path, fatImage([{ cpu, bytes }]));
const reader = new MachOSliceArtifactReader(
path,
{},
{
run: async () =>
ok({
tool: "lipo",
executable: "/usr/bin/lipo",
executableSha256: "1".repeat(64),
toolVersion: null,
versionReason: "fixture",
arguments: ["-detailed_info", path],
stdout: `architecture ${name}\n cputype ${reported.type ?? cpu.type}\n cpusubtype ${reported.subtype ?? subtype}\n offset ${reported.offset ?? 4096}\n size ${reported.size ?? bytes.length}\n align 2^${reported.alignment ?? 12}\n`,
stderr: "",
stdoutBytes: 1,
stderrBytes: 0,
exitCode: 0,
signal: null,
}),
},
);
onTestFinished(() => reader.close());
const entries = [];
for await (const entry of reader.entries()) entries.push(entry);
return entries;
};
it.each([
["armv4t", 5],
["armv5", 7],
["xscale", 8],
["armv6", 6],
["armv7", 9],
["armv7f", 10],
["armv7s", 11],
["armv7k", 12],
["armv6m", 14],
["armv7m", 15],
["armv7em", 16],
["armv8m.main", 17],
["armv8m.base", 18],
["armv8.1m.main", 19],
["armv7", 0x80000009],
] as const)(
"matches %s to its physical ARM subtype %i",
async (name, subtype) => {
const entries = await armSlices(name, subtype);
expect(entries).toHaveLength(1);
expect(entries[0]).toMatchObject({
path: `slices/${name}`,
byteOffset: 4096,
declaredSize: 44,
});
expect(entries[0]?.limitations).toEqual([]);
},
);
it.each([
["armv7s", 9],
["armv7", 11],
["armv7", 42],
["armv99", 9],
] as const)(
"rejects the inconsistent name %s for subtype %i",
async (name, subtype) => {
await expect(armSlices(name, subtype)).rejects.toMatchObject({
reason: "integrity",
});
},
);
it.each([
{ type: 0x0100000c },
{ subtype: 11 },
{ subtype: 0x80000009 },
{ offset: 4097 },
{ size: 45 },
{ alignment: 11 },
])("still rejects physical metadata disagreement %j", async (reported) => {
await expect(armSlices("armv7", 9, reported)).rejects.toMatchObject({
reason: "integrity",
});
});