fix(native): name the ownership helper prerequisite in command failures (#2506)
* fix(native): name the ownership helper prerequisite in command failures Every supervised native command launch needs the Darwin process-ownership helper. When that helper cannot be compiled (relative REA_DARWIN_SWIFTC_PATH, missing SDKROOT, a missing compiler, or an SDK/compiler mismatch), the runner reduced the typed DarwinProcessOwnershipInspectionError to a bare `io` failure. inspect_macho then reported `execution_failure` with no hint, and inspect_artifact on any universal Mach-O said only "lipo could not enumerate universal Mach-O slices". The runner now keeps the inspection message as the failure's `detail` at the launch boundary and carries it through xcrun resolution. The native provider adds it to its diagnostics and the slice reader appends it to its message, matching what the SQLite and capture providers already report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(native): cover the provider's ownership helper diagnostics Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4276aaf18b
commit
20f51d7286
@@ -3,6 +3,8 @@ import { readFile } from "node:fs/promises";
|
||||
import { describe, expect, it, onTestFinished } from "vitest";
|
||||
|
||||
import { MachOSliceArtifactReader } from "../../../../src/artifacts/MachOSliceArtifactReader.js";
|
||||
import { XcrunCommandRunner } from "../../../../src/native/CommandRunner.js";
|
||||
import { DarwinProcessOwnershipInspectionError } from "../../../../src/process/DarwinProcessRunTokenReader.js";
|
||||
|
||||
/**
|
||||
* Read a 32-bit FAT table directly. The host's /bin/ls changes between macOS
|
||||
@@ -20,6 +22,26 @@ const fatSlices = async (
|
||||
};
|
||||
|
||||
describe("Mach-O slice reader with system lipo", () => {
|
||||
it("names the process ownership helper prerequisite when lipo cannot be supervised", async () => {
|
||||
const prerequisite =
|
||||
"Direct Darwin helper compilation requires absolute REA_DARWIN_SWIFTC_PATH and SDKROOT paths.";
|
||||
const reader = new MachOSliceArtifactReader(
|
||||
process.execPath,
|
||||
{},
|
||||
new XcrunCommandRunner({}, undefined, () =>
|
||||
Promise.reject(new DarwinProcessOwnershipInspectionError(prerequisite)),
|
||||
),
|
||||
);
|
||||
onTestFinished(() => reader.close());
|
||||
const enumerate = async () => {
|
||||
for await (const _entry of reader.entries()) continue;
|
||||
};
|
||||
await expect(enumerate()).rejects.toMatchObject({
|
||||
reason: "unavailable",
|
||||
message: `lipo could not enumerate universal Mach-O slices: ${prerequisite}`,
|
||||
});
|
||||
});
|
||||
|
||||
it.skipIf(process.platform !== "darwin")(
|
||||
"checks real /bin/ls slice ranges against its FAT table",
|
||||
async () => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type NativeCommandLauncher,
|
||||
} from "../../../../src/native/CommandRunner.js";
|
||||
import { ok } from "../../../../src/domain/result.js";
|
||||
import { DarwinProcessOwnershipInspectionError } from "../../../../src/process/DarwinProcessRunTokenReader.js";
|
||||
|
||||
afterEach(() => vi.unstubAllEnvs());
|
||||
|
||||
@@ -210,3 +211,23 @@ it.skipIf(process.platform === "win32")(
|
||||
if (!killed.ok) expect(killed.error.reason).toBe("nonzero-exit");
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps the ownership helper prerequisite when xcrun cannot be supervised", async () => {
|
||||
const inspection = new DarwinProcessOwnershipInspectionError(
|
||||
"macOS process ownership inspection requires the Apple Swift compiler via xcrun",
|
||||
);
|
||||
const runner = new XcrunCommandRunner({}, undefined, () =>
|
||||
Promise.reject(inspection),
|
||||
);
|
||||
|
||||
const result = await runner.run("file", [], {});
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) return;
|
||||
expect(result.error).toMatchObject({
|
||||
tool: "file",
|
||||
reason: "io",
|
||||
detail: inspection.message,
|
||||
cause: { tool: "xcrun", detail: inspection.message, cause: inspection },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { DarwinProcessOwnershipInspectionError } from "../../../../src/process/DarwinProcessRunTokenReader.js";
|
||||
import { EventEmitter } from "node:events";
|
||||
import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
@@ -280,6 +281,30 @@ describe("native command failure capture and limits", () => {
|
||||
stderr_bytes: expect.any(Number),
|
||||
},
|
||||
});
|
||||
expect(projectAnalysisError(result.error).details).not.toHaveProperty(
|
||||
"diagnostics.detail",
|
||||
);
|
||||
});
|
||||
|
||||
it("projects the ownership helper prerequisite when a command cannot be supervised", async () => {
|
||||
const inspection = new DarwinProcessOwnershipInspectionError(
|
||||
"Direct Darwin helper compilation requires absolute REA_DARWIN_SWIFTC_PATH and SDKROOT paths.",
|
||||
);
|
||||
const runner = new XcrunCommandRunner(
|
||||
{},
|
||||
() =>
|
||||
Promise.resolve(ok({ path: process.execPath, sha256: "a".repeat(64) })),
|
||||
() => Promise.reject(inspection),
|
||||
);
|
||||
const result = await new NativeMacOSProvider({}, runner, "darwin")
|
||||
.createClient(machoTarget("/private/fixture"))
|
||||
.execute("demangle_swift", { symbols: ["fixture-symbol"] });
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) return;
|
||||
expect(projectAnalysisError(result.error).details).toMatchObject({
|
||||
diagnostics: { reason: "io", detail: inspection.message },
|
||||
});
|
||||
});
|
||||
|
||||
it("retains output written before cancellation and reaps the stalled command", async () => {
|
||||
|
||||
Reference in New Issue
Block a user