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
@@ -81,7 +81,9 @@ export class MachOSliceArtifactReader implements ArtifactReader {
|
||||
if (!captured.ok)
|
||||
throw new ArtifactReaderFailure(
|
||||
captured.error.reason === "cancelled" ? "cancelled" : "unavailable",
|
||||
"lipo could not enumerate universal Mach-O slices",
|
||||
captured.error.detail === null
|
||||
? "lipo could not enumerate universal Mach-O slices"
|
||||
: `lipo could not enumerate universal Mach-O slices: ${captured.error.detail}`,
|
||||
{
|
||||
cause: captured.error,
|
||||
...(captured.error.cleanupFailure === null &&
|
||||
|
||||
@@ -4,6 +4,7 @@ import { createReadStream } from "node:fs";
|
||||
import { realpath } from "node:fs/promises";
|
||||
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { DarwinProcessOwnershipInspectionError } from "../process/DarwinProcessRunTokenReader.js";
|
||||
import {
|
||||
OwnedCommandFailure,
|
||||
runOwnedCommand,
|
||||
@@ -39,6 +40,7 @@ export interface NativeCommandCapture {
|
||||
export class NativeCommandFailure extends Error {
|
||||
readonly cleanupOwner: ProviderProcessSupervisor | undefined;
|
||||
readonly cleanupFailures: readonly NativeCommandCleanupFailure[];
|
||||
readonly detail: string | null;
|
||||
|
||||
constructor(
|
||||
readonly tool: string,
|
||||
@@ -58,6 +60,7 @@ export class NativeCommandFailure extends Error {
|
||||
super(`Native command ${tool} failed: ${reason}`, options);
|
||||
this.cleanupOwner = options?.cleanupOwner;
|
||||
this.cleanupFailures = options?.cleanupFailures ?? [];
|
||||
this.detail = options?.detail ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +70,8 @@ export interface NativeCommandFailureOptions extends ErrorOptions {
|
||||
readonly cleanupOwner?: ProviderProcessSupervisor;
|
||||
/** All owners still incomplete after a preflight retry blocked this command. */
|
||||
readonly cleanupFailures?: readonly NativeCommandCleanupFailure[];
|
||||
/** Host-side reason the command could not be supervised, such as a missing ownership helper compiler. */
|
||||
readonly detail?: string;
|
||||
}
|
||||
|
||||
/** One failed cleanup attempt; the runner retains `owner` until it is verified stopped. */
|
||||
@@ -310,6 +315,9 @@ export const resolveXcrunTool = async (
|
||||
...(found.error.cleanupFailures.length === 0
|
||||
? {}
|
||||
: { cleanupFailures: found.error.cleanupFailures }),
|
||||
...(found.error.detail === null
|
||||
? {}
|
||||
: { detail: found.error.detail }),
|
||||
},
|
||||
found.error.capture,
|
||||
found.error.cleanupFailure,
|
||||
@@ -449,7 +457,16 @@ const captureProcess = async (
|
||||
),
|
||||
);
|
||||
}
|
||||
return err(new NativeCommandFailure(tool, "io", null, { cause }));
|
||||
return err(
|
||||
new NativeCommandFailure(tool, "io", null, {
|
||||
cause,
|
||||
// Process supervision needs the Darwin ownership helper; its typed
|
||||
// message names the compiler or SDK prerequisite to fix.
|
||||
...(cause instanceof DarwinProcessOwnershipInspectionError
|
||||
? { detail: cause.message }
|
||||
: {}),
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -966,6 +966,7 @@ const translateCommandFailure = (
|
||||
signal: failure.capture?.signal ?? null,
|
||||
stdout_bytes: failure.capture?.stdoutBytes ?? 0,
|
||||
stderr_bytes: failure.capture?.stderrBytes ?? 0,
|
||||
...(failure.detail === null ? {} : { detail: failure.detail }),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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