Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -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