Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(native): preserve resolved plist selection intent

morlutoe6c487799bb6
diff --git a/docs/native-investigation.md b/docs/native-investigation.md
index 97fe97c0d..938c62dc2 100644
--- a/docs/native-investigation.md
+++ b/docs/native-investigation.md
@@ -268,6 +268,12 @@ markup, including UTF-8 and BOM-marked UTF-16 sources. Unidentified text and
OpenStep plists, including a data-only value such as `<deadbeef>`, report
`unknown` even when plutil decodes their values through an XML conversion.
+A plist explicitly selected through the path input or as the active plist target
+reports an unreadable or malformed selection as `invalid_request`. A missing or
+unreadable default plist of another target reports `capability_unavailable`.
+Permission failures remain `access_denied`; output and cleanup failures retain
+their own error categories.
+
A plist decode refusal includes plutil's diagnostic from either output stream.
`details.captured_output` retains bounded stdout/stderr excerpts, observed byte
totals and exit status. `truncated: true` means those excerpts are incomplete.
diff --git a/src/native/NativeMacOSProvider.ts b/src/native/NativeMacOSProvider.ts
index deb595fef..e2d961755 100644
--- a/src/native/NativeMacOSProvider.ts
+++ b/src/native/NativeMacOSProvider.ts
@@ -1,7 +1,8 @@
import {
plistSourceFormat,
requireRegularPlist,
- nativePlistFileFailure,
+ nativePlistFailure,
+ resolveNativePlistSelection,
unreadablePlist,
} from "./NativePlistSource.js";
import { bindArtifactFileCleanup } from "../artifacts/ArtifactFileOperation.js";
@@ -21,8 +22,7 @@ import {
import { NativeUiCleanupError } from "./NativeUiCleanupError.js";
import { LldbCallTracer, type NativeCallTracer } from "./LldbCallTracer.js";
import { observeNativeCalls } from "./NativeCallObservation.js";
-import { basename, dirname, isAbsolute, resolve } from "node:path";
-import { realpath, stat } from "node:fs/promises";
+import { realpath } from "node:fs/promises";
import { z } from "zod";
@@ -790,11 +790,13 @@ class NativeMacOSClient implements AnalysisClient {
try {
return await this.#plistResources.run(async () => {
try {
- const plist = await resolvePlistPath(this.target, requested);
+ const plist = await resolveNativePlistSelection(
+ this.target,
+ requested,
+ );
if (!plist.ok) return plist;
const fileInput = {
- path: plist.value,
- requested,
+ selection: plist.value,
resources: this.#plistResources,
signal,
};
@@ -803,14 +805,14 @@ class NativeMacOSClient implements AnalysisClient {
const classified = await this.#run(
"inspect_plist",
"file",
- ["-b", plist.value],
+ ["-b", plist.value.path],
{ signal },
);
if (!classified.ok) return classified;
const json = await this.#run(
"inspect_plist",
"plutil",
- ["-convert", "json", "-o", "-", "--", plist.value],
+ ["-convert", "json", "-o", "-", "--", plist.value.path],
{ signal, acceptNonZero: true },
);
if (!json.ok) return json;
@@ -825,7 +827,7 @@ class NativeMacOSClient implements AnalysisClient {
: await this.#run(
"inspect_plist",
"plutil",
- ["-convert", "xml1", "-o", "-", "--", plist.value],
+ ["-convert", "xml1", "-o", "-", "--", plist.value.path],
{ signal, acceptNonZero: !jsonDecoded },
);
if (xml !== undefined && !xml.ok) return xml;
@@ -834,8 +836,7 @@ class NativeMacOSClient implements AnalysisClient {
return err(
unreadablePlist(
plist.value,
- requested,
- `plutil could not decode it as a property list (${plutilDiagnostic(capture, plist.value)})`,
+ `plutil could not decode it as a property list (${plutilDiagnostic(capture, plist.value.path)})`,
{
capturedOutput: {
stdout: capture.stdout,
@@ -861,7 +862,7 @@ class NativeMacOSClient implements AnalysisClient {
classified.value,
json.value,
...(xml === undefined ? [] : [xml.value]),
- ].map((item) => invocation(item, plist.value, "$PLIST"));
+ ].map((item) => invocation(item, plist.value.path, "$PLIST"));
const converted = xml?.value ?? json.value;
const format = await plistSourceFormat(classified.value.stdout, {
...fileInput,
@@ -880,14 +881,14 @@ class NativeMacOSClient implements AnalysisClient {
format: format.value,
value: parsed.value.value,
bundle: parsed.value.bundle,
- source_path: plist.value,
+ source_path: plist.value.path,
provenance,
limitations: parsed.value.limitations,
});
return ok({
result: jsonValueSchema.parse(result),
limitations: parsed.value.limitations,
- locations: [{ kind: "artifact-path", path: plist.value }],
+ locations: [{ kind: "artifact-path", path: plist.value.path }],
});
} catch (cause: unknown) {
// Producer failures stay opaque; only scope admission failures reach the file mapper.
@@ -895,9 +896,7 @@ class NativeMacOSClient implements AnalysisClient {
}
});
} catch (cause: unknown) {
- return err(
- nativePlistFileFailure(cause, requested ?? this.target.path, requested),
- );
+ return err(nativePlistFailure(cause, undefined));
}
}
@@ -1272,38 +1271,3 @@ const plutilDiagnostic = (
? "plutil printed no diagnostic"
: diagnostics.join("\n");
};
-
-/** The bundle whose Contents/MacOS directory directly holds `path`. */
-const macOSBundleRoot = (path: string): string | undefined => {
- const programs = dirname(path);
- const contents = dirname(programs);
- return basename(programs) === "MacOS" && basename(contents) === "Contents"
- ? dirname(contents)
- : undefined;
-};
-
-const resolvePlistPath = async (
- target: BinaryTarget,
- requested: string | undefined,
-): Promise<Result<string, AnalysisError>> => {
- try {
- const source = target.sourcePath ?? target.path;
- if (requested !== undefined && isAbsolute(requested))
- return ok(resolve(requested));
- const sourceMetadata = await stat(source);
- const root = sourceMetadata.isDirectory()
- ? source
- : (macOSBundleRoot(target.path) ?? dirname(target.path));
- if (requested !== undefined) return ok(resolve(root, requested));
- // A selected plist file is itself the plist to inspect.
- if (target.kind === "artifact" && target.format === "plist")
- return ok(target.path);
- // A bundle target records the Info.plist its program file was declared
- // in: Contents/Info.plist, or the root plist of an iOS-style bundle.
- return ok(target.bundleInfoPlist ?? resolve(root, "Contents/Info.plist"));
- } catch (cause: unknown) {
- return err(
- new ProviderAdapterError(IDENTITY.id, "inspect_plist", { cause }),
- );
- }
-};
diff --git a/src/native/NativePlistSource.ts b/src/native/NativePlistSource.ts
index 1ed98a529..4c4d38d01 100644
--- a/src/native/NativePlistSource.ts
+++ b/src/native/NativePlistSource.ts
@@ -1,3 +1,6 @@
+import { stat } from "node:fs/promises";
+import { basename, dirname, isAbsolute, resolve } from "node:path";
+import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
import type { FileHandle } from "node:fs/promises";
import type { z } from "zod";
import type { inspectPlistSchema } from "../domain/native/nativeInspection.js";
@@ -27,20 +30,67 @@ import {
import type { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
import { NATIVE_MACOS_PROVIDER_IDENTITY as IDENTITY } from "./NativeMacOSProviderMetadata.js";
+/** Resolved lookup identity and selection intent, independent of file readiness. */
+export interface NativePlistSelection {
+ readonly path: string;
+ readonly origin: "selected" | "default";
+}
+
+/** Resolve intent once; consumers never infer it from an omitted tool argument. */
+export const resolveNativePlistSelection = async (
+ target: BinaryTarget,
+ requested: string | undefined,
+): Promise<Result<NativePlistSelection, AnalysisError>> => {
+ try {
+ if (requested !== undefined && isAbsolute(requested))
+ return ok({ path: resolve(requested), origin: "selected" });
+ if (
+ requested === undefined &&
+ target.kind === "artifact" &&
+ target.format === "plist"
+ )
+ return ok({ path: target.path, origin: "selected" });
+ const source = target.sourcePath ?? target.path;
+ const sourceMetadata = await stat(source);
+ const root = sourceMetadata.isDirectory()
+ ? source
+ : (macOSBundleRoot(target.path) ?? dirname(target.path));
+ if (requested !== undefined)
+ return ok({ path: resolve(root, requested), origin: "selected" });
+ return ok({
+ path: target.bundleInfoPlist ?? resolve(root, "Contents/Info.plist"),
+ origin: "default",
+ });
+ } catch (cause: unknown) {
+ return err(
+ new ProviderAdapterError(IDENTITY.id, "inspect_plist", { cause }),
+ );
+ }
+};
+
+/** The bundle whose Contents/MacOS directory directly holds the program. */
+const macOSBundleRoot = (path: string): string | undefined => {
+ const programs = dirname(path);
+ const contents = dirname(programs);
+ return basename(programs) === "MacOS" && basename(contents) === "Contents"
+ ? dirname(contents)
+ : undefined;
+};
+
/**
* Report a plist that cannot be decoded as the caller's selection, or as the
* target's missing default, rather than as a failed tool run.
*/
export const unreadablePlist = (
- path: string,
- requested: string | undefined,
+ selection: NativePlistSelection,
reason: string,
options?: AnalysisErrorOptions,
): AnalysisError => {
+ const { path } = selection;
const sentence = reason.endsWith(".") ? reason : `${reason}.`;
// Name the default that is missing and the selection that still works.
const missingDefault = `The target has no readable default plist at ${path}: ${sentence} Select another plist in the target with the path input (CLI: --relative-path).`;
- return requested === undefined
+ return selection.origin === "default"
? new AnalysisCapabilityUnavailableError(
IDENTITY.id,
"inspect_plist",
@@ -57,18 +107,16 @@ export const unreadablePlist = (
};
interface PlistFileInput {
- readonly path: string;
- readonly requested: string | undefined;
+ readonly selection: NativePlistSelection;
readonly resources: ArtifactResourceScope;
readonly signal: AbortSignal | undefined;
readonly capturedOutput?: AnalysisCapturedOutput;
}
/** Translate only physical file outcomes, never a later signal or arbitrary abort value. */
-export const nativePlistFileFailure = (
+export const nativePlistFailure = (
cause: unknown,
- path: string,
- requested: string | undefined,
+ selection: NativePlistSelection | undefined,
capturedOutput?: AnalysisCapturedOutput,
): AnalysisError => {
if (cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined) {
@@ -78,10 +126,9 @@ export const nativePlistFileFailure = (
: undefined;
const previous =
physical?.outcome.kind === "failed"
- ? nativePlistFileFailure(
+ ? nativePlistFailure(
artifactFilePrimaryFailure(cause),
- path,
- requested,
+ selection,
capturedOutput,
)
: physical?.completionCancellation === undefined
@@ -134,15 +181,25 @@ export const nativePlistFileFailure = (
cause.message,
{ cause, capturedOutput },
);
+ if (selection === undefined)
+ return new ProviderAdapterError(IDENTITY.id, "inspect_plist", {
+ cause,
+ capturedOutput,
+ diagnostics: {
+ phase: "plist-scope",
+ reason: cause instanceof Error ? cause.message : String(cause),
+ },
+ });
+ const { path } = selection;
const code =
cause instanceof Error && "code" in cause ? cause.code : undefined;
if (code === "ENOENT" || code === "ENOTDIR")
- return unreadablePlist(path, requested, "no file exists there", {
+ return unreadablePlist(selection, "no file exists there", {
cause,
capturedOutput,
});
if (code === "EISDIR" || code === "ENOTFILE")
- return unreadablePlist(path, requested, "it is not a regular file", {
+ return unreadablePlist(selection, "it is not a regular file", {
cause,
capturedOutput,
});
@@ -170,7 +227,7 @@ const readPlistFile = async <Value>(
try {
return ok(
await withArtifactRegularFile(
- input.path,
+ input.selection.path,
input.resources,
input.signal,
read,
@@ -179,12 +236,7 @@ const readPlistFile = async <Value>(
);
} catch (cause: unknown) {
return err(
- nativePlistFileFailure(
- cause,
- input.path,
- input.requested,
- input.capturedOutput,
- ),
+ nativePlistFailure(cause, input.selection, input.capturedOutput),
);
}
};
diff --git a/tests/boundary/cli/nativePlistSelectionFailureCli.test.ts b/tests/boundary/cli/nativePlistSelectionFailureCli.test.ts
index ad32e71d1..81046e68a 100644
--- a/tests/boundary/cli/nativePlistSelectionFailureCli.test.ts
+++ b/tests/boundary/cli/nativePlistSelectionFailureCli.test.ts
@@ -208,3 +208,43 @@ describe.skipIf(process.platform !== "darwin")(
);
},
);
+
+describe.skipIf(process.platform !== "darwin")(
+ "native plist CLI direct target selection",
+ () => {
+ cliTest.for([
+ "<plist><dict><key>value</key><integer> 42 </integer></dict></plist>",
+ "<plist><dict><key>value</key><true>x</true></dict></plist>",
+ ])(
+ "classifies the selected malformed plist as input: %s",
+ async (source, { cli }) => {
+ const root = await createTestTempDirectory("rea-plist-target-input-");
+ const path = join(root, "chosen.plist");
+ await writeFile(path, source);
+ for (const args of [[], ["--relative-path", path]]) {
+ const result = await cli.run({
+ arguments: ["inspect-plist", path, ...args, "--json"],
+ environment,
+ });
+ expect(result.exitCode).toBe(1);
+ expect(result.json).toMatchObject({
+ code: "invalid_request",
+ details: {
+ issues: [
+ {
+ path: ["path"],
+ message: expect.stringContaining("Property List error:"),
+ },
+ ],
+ captured_output: { exit_code: 1 },
+ },
+ });
+ expect(capturedDiagnostic(result.json)).toContain(
+ "Property List error:",
+ );
+ }
+ expect(await readFile(path, "utf8")).toBe(source);
+ },
+ );
+ },
+);
diff --git a/tests/boundary/mcp/nativePlistDiagnosticsMcp.test.ts b/tests/boundary/mcp/nativePlistDiagnosticsMcp.test.ts
index a8c0bab4b..226df35d6 100644
--- a/tests/boundary/mcp/nativePlistDiagnosticsMcp.test.ts
+++ b/tests/boundary/mcp/nativePlistDiagnosticsMcp.test.ts
@@ -49,6 +49,21 @@ it.skipIf(process.platform !== "darwin")(
"Property List error:",
);
}
+ const selectedTarget = await call("open_binary", { path });
+ expect(selectedTarget.isError).not.toBe(true);
+ const direct = parseMcpToolError(await call("inspect_plist", {})).error;
+ expect(direct).toMatchObject({
+ code: "invalid_request",
+ details: {
+ issues: [
+ {
+ path: ["path"],
+ message: expect.stringContaining("Property List error:"),
+ },
+ ],
+ captured_output: { exit_code: 1, truncated: false },
+ },
+ });
expect(await readFile(path, "utf8")).toBe(source);
},
);
diff --git a/tests/boundary/providers/native/nativePlistFileCleanup.test.ts b/tests/boundary/providers/native/nativePlistFileCleanup.test.ts
index d51c49f97..95ae22ebe 100644
--- a/tests/boundary/providers/native/nativePlistFileCleanup.test.ts
+++ b/tests/boundary/providers/native/nativePlistFileCleanup.test.ts
@@ -121,75 +121,85 @@ it("keeps mixed client cleanup live until both file and tracer owners resolve",
expect(first.error.cleanupResources).toEqual([]);
});
-it("retains prefix read and close failures through repeated client cleanup", async ({
- onTestFinished,
-}) => {
- const root = await createTestTempDirectory("rea-native-plist-close-");
- const path = join(root, "selected.plist");
- await writeFile(path, "<plist><string>value</string></plist>");
- const probe = await open(path, "r");
- const prototype = Object.getPrototypeOf(probe) as FileHandle;
- await probe.close();
- const primary = Object.assign(new Error("controlled prefix read failure"), {
- code: "EIO",
- });
- const cleanup = new Error("controlled prefix close failure");
- let attempts = 0;
- let release: (() => Promise<void>) | undefined;
- const read = vi
- .spyOn(prototype, "read")
- .mockImplementationOnce(async function (this: FileHandle) {
- release = this.close.bind(this);
- this.close = async () => {
- attempts += 1;
- if (attempts <= 2) throw cleanup;
- await release!();
- };
- throw primary;
+it.for(["path-input", "target"] as const)(
+ "retains %s prefix read and close failures through repeated client cleanup",
+ async (selection, { onTestFinished }) => {
+ const root = await createTestTempDirectory("rea-native-plist-close-");
+ const path = join(root, "selected.plist");
+ await writeFile(path, "<plist><string>value</string></plist>");
+ const probe = await open(path, "r");
+ const prototype = Object.getPrototypeOf(probe) as FileHandle;
+ await probe.close();
+ const primary = Object.assign(new Error("controlled prefix read failure"), {
+ code: "EIO",
});
- onTestFinished(async () => {
- read.mockRestore();
- await release?.();
- });
- const client = new NativeMacOSProvider(
- {},
- new NativeFixtureRunner({ file: "ASCII text", plutil: '"value"' }),
- "darwin",
- ).createClient(nativeMachoTarget(join(root, "target")));
- onTestFinished(async () => {
- await client.close();
- });
- const result = await client.execute("inspect_plist", { path });
- expect(result.ok).toBe(false);
- if (result.ok) throw new Error("Expected retained cleanup failure");
- expect(result.error).toMatchObject({
- cleanupIncomplete: true,
- operation: "inspect_plist",
- });
- expect(result.error.cleanupResources).toContain(path);
- expect(result.error.capturedOutput?.stdout).toBe('"value"');
- const projected = projectAnalysisError(result.error);
- expect(JSON.stringify(projected).match(/captured_output/gu)).toHaveLength(1);
- expect(result.error.cause).toBeInstanceOf(ArtifactFileCleanupFailure);
- const failure = result.error.cause as ArtifactFileCleanupFailure;
- expect(failure.fileCleanupFailure.outcome).toEqual({
- kind: "failed",
- cause: primary,
- });
- expect(failure.fileCleanupFailure.cleanupCause).toBe(cleanup);
- const first = await client.close();
- expect(first.ok).toBe(false);
- expect(attempts).toBe(2);
- const retried = await client.close();
- expect(retried.ok).toBe(true);
- expect(attempts).toBe(3);
- expect(result.error.cleanupIncomplete).toBe(false);
- expect(resolvedAnalysisError(result.error).cause).toBe(primary);
- expect(resolvedAnalysisError(result.error).capturedOutput?.stdout).toBe(
- '"value"',
- );
- if (!first.ok) expect(first.error.cleanupIncomplete).toBe(false);
-});
+ const cleanup = new Error("controlled prefix close failure");
+ let attempts = 0;
+ let release: (() => Promise<void>) | undefined;
+ const read = vi
+ .spyOn(prototype, "read")
+ .mockImplementationOnce(async function (this: FileHandle) {
+ release = this.close.bind(this);
+ this.close = async () => {
+ attempts += 1;
+ if (attempts <= 2) throw cleanup;
+ await release!();
+ };
+ throw primary;
+ });
+ onTestFinished(async () => {
+ read.mockRestore();
+ await release?.();
+ });
+ const client = new NativeMacOSProvider(
+ {},
+ new NativeFixtureRunner({ file: "ASCII text", plutil: '"value"' }),
+ "darwin",
+ ).createClient(
+ selection === "target"
+ ? { kind: "artifact", format: "plist", path, sha256: "0".repeat(64) }
+ : nativeMachoTarget(join(root, "target")),
+ );
+ onTestFinished(async () => {
+ await client.close();
+ });
+ const result = await client.execute(
+ "inspect_plist",
+ selection === "target" ? {} : { path },
+ );
+ expect(result.ok).toBe(false);
+ if (result.ok) throw new Error("Expected retained cleanup failure");
+ expect(result.error).toMatchObject({
+ cleanupIncomplete: true,
+ operation: "inspect_plist",
+ });
+ expect(result.error.cleanupResources).toContain(path);
+ expect(result.error.capturedOutput?.stdout).toBe('"value"');
+ const projected = projectAnalysisError(result.error);
+ expect(JSON.stringify(projected).match(/captured_output/gu)).toHaveLength(
+ 1,
+ );
+ expect(result.error.cause).toBeInstanceOf(ArtifactFileCleanupFailure);
+ const failure = result.error.cause as ArtifactFileCleanupFailure;
+ expect(failure.fileCleanupFailure.outcome).toEqual({
+ kind: "failed",
+ cause: primary,
+ });
+ expect(failure.fileCleanupFailure.cleanupCause).toBe(cleanup);
+ const first = await client.close();
+ expect(first.ok).toBe(false);
+ expect(attempts).toBe(2);
+ const retried = await client.close();
+ expect(retried.ok).toBe(true);
+ expect(attempts).toBe(3);
+ expect(result.error.cleanupIncomplete).toBe(false);
+ expect(resolvedAnalysisError(result.error).cause).toBe(primary);
+ expect(resolvedAnalysisError(result.error).capturedOutput?.stdout).toBe(
+ '"value"',
+ );
+ if (!first.ok) expect(first.error.cleanupIncomplete).toBe(false);
+ },
+);
for (const readFails of [false, true])
it(`retains a ${readFails ? "failed" : "completed"} read when cancellation and close failure coincide`, async () => {
diff --git a/tests/boundary/providers/native/nativePlistSelection.test.ts b/tests/boundary/providers/native/nativePlistSelection.test.ts
new file mode 100644
index 000000000..892a0f8d5
--- /dev/null
+++ b/tests/boundary/providers/native/nativePlistSelection.test.ts
@@ -0,0 +1,148 @@
+import { chmod, mkdir, writeFile } from "node:fs/promises";
+import { join } from "node:path";
+import { expect, it, onTestFinished } from "vitest";
+import { NativeMacOSProvider } from "../../../../src/native/NativeMacOSProvider.js";
+import {
+ resolveNativePlistSelection,
+ nativePlistFailure,
+} from "../../../../src/native/NativePlistSource.js";
+import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
+import {
+ NativeFixtureRunner,
+ nativeMachoTarget,
+} from "../../../fixtures/nativeCommands.js";
+import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
+
+it("resolves selected paths and defaults without conflating intent and file readiness", async () => {
+ const root = await createTestTempDirectory("rea-plist-origin-");
+ const program = join(root, "program");
+ await writeFile(program, "fixture program");
+ const target = nativeMachoTarget(program);
+ const chosen = join(root, "chosen.plist");
+ expect(await resolveNativePlistSelection(target, chosen)).toEqual({
+ ok: true,
+ value: { path: chosen, origin: "selected" },
+ });
+ expect(await resolveNativePlistSelection(target, "chosen.plist")).toEqual({
+ ok: true,
+ value: { path: chosen, origin: "selected" },
+ });
+ expect(await resolveNativePlistSelection(target, undefined)).toEqual({
+ ok: true,
+ value: { path: join(root, "Contents/Info.plist"), origin: "default" },
+ });
+ const recorded = join(root, "Info.plist");
+ expect(
+ await resolveNativePlistSelection(
+ { ...target, bundleInfoPlist: recorded },
+ undefined,
+ ),
+ ).toEqual({ ok: true, value: { path: recorded, origin: "default" } });
+ const plistTarget = {
+ kind: "artifact",
+ format: "plist",
+ path: chosen,
+ sha256: "0".repeat(64),
+ } as const;
+ expect(await resolveNativePlistSelection(plistTarget, undefined)).toEqual({
+ ok: true,
+ value: { path: chosen, origin: "selected" },
+ });
+});
+
+it.each(["missing", "directory"] as const)(
+ "retains selected target intent for a %s plist",
+ async (kind) => {
+ const root = await createTestTempDirectory("rea-plist-origin-file-");
+ const path = join(root, "chosen.plist");
+ if (kind === "directory") await mkdir(path);
+ const client = new NativeMacOSProvider(
+ {},
+ new NativeFixtureRunner(),
+ "darwin",
+ ).createClient({
+ kind: "artifact",
+ format: "plist",
+ path,
+ sha256: "0".repeat(64),
+ });
+ onTestFinished(async () => {
+ await client.close();
+ });
+ const result = await client.execute("inspect_plist", {});
+ if (result.ok) throw new Error("Expected selected file refusal");
+ expect(projectAnalysisError(result.error)).toMatchObject({
+ code: "invalid_request",
+ details: {
+ issues: [
+ {
+ path: ["path"],
+ message: expect.stringContaining(
+ kind === "missing"
+ ? "no file exists there"
+ : "not a regular file",
+ ),
+ },
+ ],
+ },
+ });
+ },
+);
+
+it.skipIf(process.getuid?.() === 0 || process.platform === "win32")(
+ "keeps permission failure distinct from selection and format",
+ async () => {
+ const root = await createTestTempDirectory("rea-plist-origin-denied-");
+ const path = join(root, "chosen.plist");
+ await writeFile(path, "<plist><dict/></plist>");
+ const client = new NativeMacOSProvider(
+ {},
+ new NativeFixtureRunner(),
+ "darwin",
+ ).createClient({
+ kind: "artifact",
+ format: "plist",
+ path,
+ sha256: "0".repeat(64),
+ });
+ onTestFinished(async () => {
+ await chmod(path, 0o600);
+ await client.close();
+ });
+ await chmod(path, 0);
+ const result = await client.execute("inspect_plist", {});
+ if (result.ok) throw new Error("Expected access denial");
+ expect(projectAnalysisError(result.error)).toMatchObject({
+ code: "access_denied",
+ details: { path },
+ });
+ },
+);
+
+it("does not invent selection facts for unresolved scope failures", () => {
+ const cause = Object.assign(new Error("scope failure"), { code: "ENOENT" });
+ const error = nativePlistFailure(cause, undefined);
+ expect(error.cause).toBe(cause);
+ expect(error.diagnostics).toEqual({
+ phase: "plist-scope",
+ reason: "scope failure",
+ });
+ expect(projectAnalysisError(error).code).not.toBe("invalid_request");
+ expect(projectAnalysisError(error).code).not.toBe("capability_unavailable");
+});
+
+it("refuses closed client admission before resolving a target or launching tools", async () => {
+ const root = await createTestTempDirectory("rea-plist-origin-closed-");
+ const client = new NativeMacOSProvider(
+ {},
+ new NativeFixtureRunner(),
+ "darwin",
+ ).createClient(nativeMachoTarget(join(root, "missing-program")));
+ expect((await client.close()).ok).toBe(true);
+ const result = await client.execute("inspect_plist", {});
+ if (result.ok) throw new Error("Expected closed scope");
+ expect(projectAnalysisError(result.error)).toMatchObject({
+ code: "capability_unavailable",
+ details: { reason: "Native provider client is closed" },
+ });
+});