fix(apple): preserve slice identity and macOS boundary diagnostics (#1772)

* fix(artifacts): name CPU_SUBTYPE_ARM64E_X1 Mach-O slices arm64e

macOS 27 system binaries such as /bin/ls carry a third FAT slice with
cpusubtype 0x8000000c. The SDK defines subtype 12 as
CPU_SUBTYPE_ARM64E_X1, and CPU_SUBTYPE_HAS_ARM64E puts it in the arm64e
family. architectureName knew only subtype 2, so it named the slice
arm64, lipoNameMatches rejected lipo's arm64e.x1 name, and
inspect-artifact /bin/ls failed with integrity_mismatch.

The arm64e.x1 test fixture now uses the real subtype. It fails without
this change.

Refs #1168, #1765

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(artifacts): classify en-GB hdiutil verify refusals as format failures

hdiutil follows AppleLanguages. With en-GB it writes "image not
recognised", and verifyFailureReason matched only the US spelling, so a
file that is not a disk image got the reason unavailable. Both spellings
now give format. Other languages still give unavailable.

Refs #1765

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(process): read the full process table in the lifecycle cleanup check

The check ran ps -axo command= with the Node default maxBuffer of 1 MiB.
On a host with 1905 processes, the output is 1.52 MB, and the test failed
with "stdout maxBuffer length exceeded".

Refs #1765

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(process): bound cleanup observations to sampled descendants

* fix(apple): retain CPU subtype identity during dylib resolution

* test(process): retain OS PIDs for descendant observations

---------

Co-authored-by: David Lee <davidlee@Dav3Book-Pro-M4-Max.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
David Lee
2026-10-13 06:06:37 +09:00
committed by GitHub
co-authored by David Lee Claude Opus 5.5 morluto
parent 85e124253a
commit 5c2956587a
9 changed files with 193 additions and 32 deletions
+2
View File
@@ -625,7 +625,9 @@ const verifyFailureReason = (
processOutput(cause, "stderr"),
);
switch (diagnostic) {
// hdiutil follows AppleLanguages, so en-GB and en-AU spell it "recognised".
case "image not recognized":
case "image not recognised":
return "format";
case "invalid checksum":
case "image data corrupted":
@@ -21,6 +21,7 @@ export const CPU = {
i386: { type: 7, subtype: 3 },
arm64: { type: 0x0100000c, subtype: 0 },
arm64e: { type: 0x0100000c, subtype: 0x80000002 },
arm64eX1: { type: 0x0100000c, subtype: 0x8000000c },
x86_64: { type: 0x01000007, subtype: 3 },
} as const;
@@ -136,6 +136,98 @@ it("uses legacy simulator and device platform facts when resolving dylibs", asyn
);
});
it("selects matching arm64e subtype slices when tracing a mixed FAT image", async () => {
const root = await createTestTempDirectory("rea-macho-arm64e-subtypes-");
const executablePath = "Contents/MacOS/App";
const dylibPath = "Contents/MacOS/libVariant.dylib";
const installName = "@executable_path/libVariant.dylib";
const arm64eDependency = "@executable_path/libArm64e.dylib";
const arm64eX1Dependency = "@executable_path/libArm64eX1.dylib";
const executableSlice = (cpu: typeof CPU.arm64e | typeof CPU.arm64eX1) =>
machoImage({
cpu,
commands: [
buildVersionCommand(1),
dylibCommand(LC.LOAD_DYLIB, installName),
],
});
const executable = fatImage([
{
cpu: CPU.arm64eX1,
bytes: executableSlice(CPU.arm64eX1),
},
{
cpu: CPU.arm64e,
bytes: executableSlice(CPU.arm64e),
},
]);
const variantSlice = (
cpu: typeof CPU.arm64e | typeof CPU.arm64eX1,
dependencyName: string,
) =>
machoImage({
cpu,
fileType: FILE_TYPE.dylib,
commands: [
buildVersionCommand(1),
dylibCommand(LC.ID_DYLIB, installName),
dylibCommand(LC.LOAD_DYLIB, dependencyName),
],
});
const completeDylib = fatImage([
{
cpu: CPU.arm64e,
bytes: variantSlice(CPU.arm64e, arm64eDependency),
},
{
cpu: CPU.arm64eX1,
bytes: variantSlice(CPU.arm64eX1, arm64eX1Dependency),
},
]);
await mkdir(join(root, "Contents/MacOS"), { recursive: true });
await writeFile(join(root, executablePath), executable);
await writeFile(join(root, dylibPath), completeDylib);
const trace = () =>
traceDylibResolution({
rootPath: root,
targetPath: join(root, executablePath),
targetSha256: createHash("sha256").update(executable).digest("hex"),
enumerateRoots: false,
parameters: { roots: [executablePath] },
});
const complete = await trace();
expect(
complete.edges
.filter(({ loader }) => loader === dylibPath)
.map(({ install_name: dependencyName }) => dependencyName),
).toEqual([arm64eX1Dependency, arm64eDependency]);
const onlyArm64e = fatImage([
{
cpu: CPU.arm64e,
bytes: variantSlice(CPU.arm64e, arm64eDependency),
},
]);
await writeFile(join(root, dylibPath), onlyArm64e);
const missingVariant = await trace();
expect(
missingVariant.edges
.filter(
({ loader, install_name: dependencyName }) =>
loader === executablePath && dependencyName === installName,
)
.map(({ candidates, resolution }) => [
candidates[0]?.outcome,
resolution.status,
]),
).toEqual([
["architecture-missing", "unresolved"],
["resolved", "resolved"],
]);
});
describe("Mach-O load command reader: decodes thin-image load commands", () => {
it("decodes dylib loading commands of a thin image", async () => {
const image = machoImage({
@@ -3,6 +3,7 @@ import type {
MachoImageFacts,
MachoSlice,
} from "../../domain/apple/dylibResolution.js";
import { machoCpuSubtypeBase } from "../../domain/apple/machoCpuIdentity.js";
import {
classifyFatContainerIdentity,
readFatContainerHeader,
@@ -482,13 +483,12 @@ const CPU_ARCH_ABI64 = 0x01000000;
const CPU_ARCH_ABI64_32 = 0x02000000;
const CPU_TYPE_X86 = 7;
const CPU_TYPE_ARM = 12;
const CPU_SUBTYPE_MASK = 0xff000000;
const CPU_SUBTYPE_ARM64E = 2;
const CPU_SUBTYPE_ARM64E_X1 = 12;
const CPU_SUBTYPE_X86_64_H = 8;
const architectureName = (cpuType: number, cpuSubtype: number): string => {
const subtype = cpuSubtype & ~CPU_SUBTYPE_MASK;
const subtype = machoCpuSubtypeBase(cpuSubtype);
if (cpuType === (CPU_TYPE_ARM | CPU_ARCH_ABI64))
// Both pointer-authentication subtypes belong to the arm64e family.
return subtype === CPU_SUBTYPE_ARM64E || subtype === CPU_SUBTYPE_ARM64E_X1