Merge pull request #868 from morluto/fix/swift-demangle-arguments

fix(native): pass Swift symbols to swift-demangle as operands
This commit is contained in:
Kaoru0822
2026-10-06 23:00:45 -07:00
committed by GitHub
11 changed files with 175 additions and 16 deletions
@@ -0,0 +1,61 @@
import { copyFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
const environment = {
REA_LOG_LEVEL: "silent",
REA_ANALYSIS_PROVIDER: "auto",
} as const;
/** Copy a host program to serve as the evidence-identity artifact. */
const evidenceTarget = async () => {
const path = join(await createTestTempDirectory("rea-demangle-"), "tool");
await copyFile("/usr/bin/true", path);
return path;
};
describe.skipIf(process.platform !== "darwin")(
"native Swift demangling CLI with line-terminator characters",
() => {
cliTest("keeps a carriage return in the symbol", async ({ cli }) => {
const result = await cli.run({
arguments: [
"demangle-swift",
await evidenceTarget(),
"$s4main3FooV",
"carriage\r",
"--json",
],
environment,
});
expect(result.exitCode).toBe(0);
expect(result.json).toMatchObject({
normalized_result: {
symbols: [
{ input: "$s4main3FooV", output: "main.Foo", status: "demangled" },
{ input: "carriage\r", output: "carriage\r", status: "unchanged" },
],
},
});
});
cliTest("rejects a symbol spanning lines as input", async ({ cli }) => {
const result = await cli.run({
arguments: [
"demangle-swift",
await evidenceTarget(),
"$s4main3FooV",
"$s4main\n3FooV",
"--json",
],
environment,
});
expect(result.exitCode).not.toBe(0);
expect(result.json).toMatchObject({ code: "VALIDATION_ERROR" });
});
},
);
@@ -0,0 +1,76 @@
import { copyFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect } from "vitest";
import { z } from "zod";
import { createBinarySession } from "../../../src/application/runtime.js";
import { parseConfig } from "../../../src/config.js";
import { createServer } from "../../../src/server/createServer.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { mcpTest } from "../../support/mcp/mcpFixture.js";
const demangledSchema = z.object({
result: z.object({
symbols: z.array(
z.object({ input: z.string(), output: z.string(), status: z.string() }),
),
}),
});
describe.skipIf(process.platform !== "darwin")(
"native Swift demangling through MCP",
() => {
mcpTest(
"passes option-like symbols to swift-demangle as symbols",
async ({ mcp, onTestFinished }) => {
const target = join(
await createTestTempDirectory("rea-demangle-mcp-"),
"tool",
);
await copyFile("/usr/bin/true", target);
const configured = parseConfig({ REA_ANALYSIS_PROVIDER: "auto" });
if (!configured.ok) throw configured.error;
const session = createBinarySession(configured.value);
onTestFinished(async () => {
await session.close();
});
const client = await mcp.connect(createServer(session, session));
const opened = await client.callTool({
name: "open_binary",
arguments: { path: target },
});
expect(opened.isError, JSON.stringify(opened.content)).not.toBe(true);
const called = await client.callTool({
name: "demangle_swift",
arguments: {
symbols: ["-help", "--simplified", "$s4main3FooV", "carriage\r"],
},
});
expect(called.isError, JSON.stringify(called.content)).not.toBe(true);
expect(
demangledSchema.parse(called.structuredContent).result.symbols,
).toEqual([
{ input: "-help", output: "-help", status: "unchanged" },
{
input: "--simplified",
output: "--simplified",
status: "unchanged",
},
{ input: "$s4main3FooV", output: "main.Foo", status: "demangled" },
{ input: "carriage\r", output: "carriage\r", status: "unchanged" },
]);
const spanning = await client.callTool({
name: "demangle_swift",
arguments: { symbols: ["$s4main\n3FooV"] },
});
expect(spanning.isError).toBe(true);
expect(JSON.stringify(spanning.content)).toContain(
"Each Swift symbol must be one line.",
);
},
);
},
);