Merge pull request #1159 from morluto/fix/dylib-resolution-root-input-errors
fix(apple): report unusable dylib-resolution roots as invalid input
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
import { dylibResolutionResultSchema } from "../../../src/domain/apple/dylibResolution.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
import { cliTest, type TestCli } from "../../support/cli/cliFixture.js";
|
||||
|
||||
const ENVIRONMENT = { REA_LOG_LEVEL: "silent", REA_ANALYSIS_PROVIDER: "auto" };
|
||||
|
||||
@@ -29,6 +29,41 @@ const writeFiles = async (
|
||||
}
|
||||
};
|
||||
|
||||
/** A caller-selected root that cannot be traced is an input issue on that root. */
|
||||
const expectRootInputError = async (
|
||||
cli: TestCli,
|
||||
{
|
||||
app,
|
||||
root,
|
||||
reason,
|
||||
message,
|
||||
}: {
|
||||
readonly app: string;
|
||||
readonly root: string;
|
||||
readonly reason: string;
|
||||
readonly message: string;
|
||||
},
|
||||
): Promise<void> => {
|
||||
const rejected = await cli.run({
|
||||
arguments: ["trace-dylib-resolution", app, "--root", root, "--json"],
|
||||
environment: ENVIRONMENT,
|
||||
});
|
||||
expect(rejected.exitCode).toBe(1);
|
||||
expect(rejected.json).toMatchObject({
|
||||
error: "Analysis failed",
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
path: ["roots", 0],
|
||||
reason,
|
||||
message: expect.stringContaining(message),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const fixtureApp = async (): Promise<string> => {
|
||||
const app = join(
|
||||
await createTestTempDirectory("rea-dylib-cli-"),
|
||||
@@ -141,17 +176,16 @@ describe("trace-dylib-resolution CLI", () => {
|
||||
const outside = await createTestTempDirectory("rea-dylib-outside-");
|
||||
await writeFiles(outside, { Tool: machoImage({}) });
|
||||
await symlink(outside, join(app, "Contents/Linked"));
|
||||
for (const root of [
|
||||
"../outside",
|
||||
"Contents/Info.plist",
|
||||
"Contents/Linked/Tool",
|
||||
]) {
|
||||
const rejected = await cli.run({
|
||||
arguments: ["trace-dylib-resolution", app, "--root", root, "--json"],
|
||||
environment: ENVIRONMENT,
|
||||
});
|
||||
expect(rejected.exitCode).toBe(1);
|
||||
expect(rejected.json).toMatchObject({ error: "Analysis failed" });
|
||||
for (const [root, reason, message] of [
|
||||
["../outside", "invalid_format", "Use a normalized path"],
|
||||
["Contents/Info.plist", "invalid_value", "is not a Mach-O image"],
|
||||
[
|
||||
"Contents/Linked/Tool",
|
||||
"invalid_value",
|
||||
"resolves outside the analyzed root",
|
||||
],
|
||||
] as const) {
|
||||
await expectRootInputError(cli, { app, root, reason, message });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { chmod, mkdir, writeFile } from "node:fs/promises";
|
||||
import { chmod, mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
@@ -375,3 +375,53 @@ it.each([
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("reports caller-selected roots that cannot be traced as invalid input", async () => {
|
||||
const app = join(
|
||||
await createTestTempDirectory("rea-dylib-roots-"),
|
||||
"Fixture.app",
|
||||
);
|
||||
await mkdir(join(app, "Contents/MacOS"), { recursive: true });
|
||||
await writeFile(
|
||||
join(app, "Contents/Info.plist"),
|
||||
"<plist><dict><key>CFBundleExecutable</key><string>App</string></dict></plist>",
|
||||
);
|
||||
await writeFile(
|
||||
join(app, "Contents/MacOS/App"),
|
||||
machoImage({ commands: [buildVersionCommand(1)] }),
|
||||
);
|
||||
await symlink("/bin/ls", join(app, "Contents/MacOS/outside"));
|
||||
await withClient(async (client) => {
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: app },
|
||||
});
|
||||
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
|
||||
for (const [root, message] of [
|
||||
["Contents/MacOS/Missing", "is not a regular file"],
|
||||
["Contents/MacOS", "is not a regular file"],
|
||||
["Contents/Info.plist", "is not a Mach-O image"],
|
||||
["Contents/MacOS/outside", "resolves outside the analyzed root"],
|
||||
] as const) {
|
||||
const called = await client.callTool({
|
||||
name: "trace_dylib_resolution",
|
||||
arguments: { roots: ["Contents/MacOS/App", root] },
|
||||
});
|
||||
expect(called.isError, root).toBe(true);
|
||||
expect(called.structuredContent, root).toMatchObject({
|
||||
error: {
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
path: ["roots", 1],
|
||||
reason: "invalid_value",
|
||||
message: expect.stringContaining(`Root ${root} ${message}`),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user