From 37467640cb0fadfc908b7c48bc481b8834b41456 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:14:16 -0500 Subject: [PATCH] test(ida): consolidate registration and profile selection checks (#12998) * test(ida): consolidate registration and profile selection checks * test(ida): keep native registration checks at their reader --- src/ida/IdaConfiguration.test.ts | 160 +++++++++++++++-------------- src/ida/IdaHexRaysProtocol.test.ts | 45 +------- src/ida/IdaNativeProtocol.test.ts | 37 +------ 3 files changed, 86 insertions(+), 156 deletions(-) diff --git a/src/ida/IdaConfiguration.test.ts b/src/ida/IdaConfiguration.test.ts index c03bc7851d..fa8f82b5b5 100644 --- a/src/ida/IdaConfiguration.test.ts +++ b/src/ida/IdaConfiguration.test.ts @@ -262,7 +262,7 @@ describe("IDA registration descriptor ownership", () => { }); it.each(["env", "headers"] as const)( - "preserves all explicit IDA %s keys", + "preserves explicit IDA %s keys and rejects invalid values at the same keys", async (field) => { const root = await createTestTempDirectory("rea-ida-config-"); const path = join(root, "mcp.json"); @@ -284,18 +284,7 @@ it.each(["env", "headers"] as const)( : undefined; expect(parsed).toEqual(mapping); expect(Object.hasOwn(parsed ?? {}, "__proto__")).toBe(true); - }, -); -it.each(["env", "headers"] as const)( - "rejects malformed explicit IDA %s values at __proto__", - async (field) => { - const root = await createTestTempDirectory("rea-ida-config-"); - const path = join(root, "mcp.json"); - const transport = - field === "env" - ? { command: "python", protocol: "native" } - : { url: "http://127.0.0.1:8745/mcp", protocol: "native" }; for (const value of [42, null, {}]) { await writeFile( path, @@ -304,85 +293,104 @@ it.each(["env", "headers"] as const)( [field]: Object.fromEntries([["__proto__", value]]), }), ); - expect((await read(path)).ok).toBe(false); + expect((await read(path)).ok, JSON.stringify(value)).toBe(false); } }, ); -// A stored registration that still selects the removed 1.4 proxy is refused -// with migration guidance; it is never read as the native or headless protocol. -it.each([ - { command: "python", args: ["server.py"], protocol: "legacy" }, - { url: "http://127.0.0.1:13337/mcp", mode: "attached", protocol: "legacy" }, - { - mcpServers: { - "ida-pro-mcp": { command: "python", protocol: "legacy" }, +describe("IDA registration compatibility profiles", () => { + it.each([ + { url: "http://127.0.0.1:13337/mcp", mode: "attached", protocol: "legacy" }, + { + mcpServers: { + "ida-pro-mcp": { command: "python", protocol: "legacy" }, + }, }, - }, -])("refuses the removed legacy protocol in %j", async (input) => { - const root = await createTestTempDirectory("rea-ida-config-"); - const path = join(root, "mcp.json"); - await writeFile(path, JSON.stringify(input)); - const parsed = await read(path); - if (parsed.ok) throw new Error("Expected the legacy protocol to fail"); - // The refusal names the protocol setting and delivers the owner's guidance. - const constraint = `protocol: ${LEGACY_PROTOCOL_REMOVED}`; - expect(parsed.error.settings).toEqual([ - { setting: "REA_IDA_MCP_CONFIG", constraint }, - ]); - expect(parsed.error.message).toContain(constraint); -}); - -it("points legacy protocol recovery to the documented migration", async () => { - expect(LEGACY_PROTOCOL_REMOVED).toContain('"protocol": "native"'); - const guide = await fs.readFile("docs/providers/ida-provider.md", "utf8"); - expect(guide).toMatch(/^### Migrate a legacy attached registration$/mu); - expect(LEGACY_PROTOCOL_REMOVED).toContain( - '"Migrate a legacy attached registration"', - ); -}); - -// An attached registration has no default protocol; it fails closed naming -// the protocol choice instead of guessing. -it.each([ - { command: "python", args: ["server.py"] }, - { command: "python", mode: "attached" }, - { url: "http://127.0.0.1:13337/mcp" }, -])( - "requires an explicit protocol for attached registration %j", - async (input) => { + ])("refuses the removed legacy protocol in %j", async (input) => { const root = await createTestTempDirectory("rea-ida-config-"); const path = join(root, "mcp.json"); await writeFile(path, JSON.stringify(input)); const parsed = await read(path); - if (parsed.ok) throw new Error("Expected an omitted protocol to fail"); + if (parsed.ok) throw new Error("Expected the legacy protocol to fail"); + const constraint = `protocol: ${LEGACY_PROTOCOL_REMOVED}`; + expect(parsed.error.settings).toEqual([ + { setting: "REA_IDA_MCP_CONFIG", constraint }, + ]); + expect(parsed.error.message).toContain(constraint); + expect(constraint).toContain('"protocol": "native"'); + }); + + it.each([ + [{ command: "python", args: ["server.py"] }, 'set protocol to "native"'], + [ + { url: "http://127.0.0.1:13337/mcp", mode: "attached" }, + 'set protocol to "native"', + ], + [ + { command: "python", mode: "headless", protocol: "native" }, + 'a headless registration omits protocol or sets "hexrays"', + ], + [ + { + url: "http://127.0.0.1:13337/mcp", + mode: "headless", + protocol: "native", + }, + 'a headless registration omits protocol or sets "hexrays"', + ], + [ + { command: "uvx", args: ["ida-mcp", "stdio"], protocol: "hexrays" }, + "requires a headless stdio registration", + ], + [ + { + url: "http://127.0.0.1:8737/mcp", + mode: "headless", + protocol: "hexrays", + }, + "requires a headless stdio registration", + ], + ] as const)("rejects incompatible registration %j", async (input, reason) => { + const root = await createTestTempDirectory("rea-ida-config-"); + const path = join(root, "mcp.json"); + await writeFile(path, JSON.stringify(input)); + const parsed = await read(path); + if (parsed.ok) + throw new Error("Expected incompatible registration to fail"); expect(parsed.error.settings).toEqual([ { setting: "REA_IDA_MCP_CONFIG", - constraint: expect.stringContaining('set protocol to "native"'), + constraint: expect.stringContaining(reason), }, ]); - }, -); - -it("resolves the single headless protocol without a protocol field", async () => { - const root = await createTestTempDirectory("rea-ida-config-"); - const path = join(root, "mcp.json"); - await writeFile( - path, - JSON.stringify({ command: "python", mode: "headless" }), - ); - expect(await read(path)).toMatchObject({ - ok: true, - value: { mode: "headless", protocol: "modern" }, }); - await writeFile( - path, - JSON.stringify({ + + it.each([ + { command: "python", - mode: "headless", - protocol: "native", - }), + args: ["server.py"], + protocol: "modern", + inputProtocol: {}, + }, + { + command: "uvx", + args: ["ida-mcp", "stdio"], + protocol: "hexrays", + inputProtocol: { protocol: "hexrays" }, + }, + ])( + "resolves a headless $protocol registration", + async ({ command, args, protocol, inputProtocol }) => { + const root = await createTestTempDirectory("rea-ida-config-"); + const path = join(root, "mcp.json"); + await writeFile( + path, + JSON.stringify({ command, args, mode: "headless", ...inputProtocol }), + ); + expect(await read(path)).toMatchObject({ + ok: true, + value: { command, args, mode: "headless", protocol }, + }); + }, ); - expect((await read(path)).ok).toBe(false); }); diff --git a/src/ida/IdaHexRaysProtocol.test.ts b/src/ida/IdaHexRaysProtocol.test.ts index cdeb6ef770..60c96c26cd 100644 --- a/src/ida/IdaHexRaysProtocol.test.ts +++ b/src/ida/IdaHexRaysProtocol.test.ts @@ -1,5 +1,5 @@ import { spawnSync } from "node:child_process"; -import { access, readdir, rm, writeFile } from "node:fs/promises"; +import { access, readdir, rm } from "node:fs/promises"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; @@ -9,11 +9,9 @@ import { functionDossierSchema } from "../domain/native/functionDossier.js"; import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; import { IdaToolRejection, type IdaMcpConnection } from "./IdaMcpConnection.js"; import { readCallGraphCallees } from "./IdaCallGraph.js"; -import { readIdaConfiguration } from "./IdaConfiguration.js"; import { IdaSessionClient } from "./IdaSessionClient.js"; import { runHexRaysQuery } from "./IdaHexRaysProtocol.js"; import type { JsonValue } from "../domain/jsonValue.js"; -import type { RetainedResourceScope } from "../ports/AnalysisProvider.js"; import { WindowsPrivateRuntime } from "../windows/WindowsPrivateRuntime.js"; const roots: string[] = []; @@ -62,51 +60,10 @@ const fixture = async () => { ); return { root, target, producer, client }; }; -const resourceScope: RetainedResourceScope = { - retain: () => undefined, - run: (operation) => operation(), -}; /** Private workspaces REA allocated beside the fixture target. */ const workspaces = async (root: string) => (await readdir(root)).filter((name) => name.startsWith("rea-ida-")); -describe("Hex-Rays IDA MCP registration", () => { - it("admits only a headless stdio registration", async () => { - const { root } = await createIdaTarget(); - roots.push(root); - const path = join(root, "mcp.json"); - for (const [input, ok] of [ - [ - { - command: "uvx", - args: ["ida-mcp", "stdio"], - mode: "headless", - protocol: "hexrays", - }, - true, - ], - [ - { command: "uvx", args: ["ida-mcp", "stdio"], protocol: "hexrays" }, - false, - ], - [ - { - url: "http://127.0.0.1:8737/mcp", - mode: "headless", - protocol: "hexrays", - }, - false, - ], - ] as const) { - await writeFile(path, JSON.stringify(input)); - expect( - (await readIdaConfiguration(path, { resourceScope })).ok, - JSON.stringify(input), - ).toBe(ok); - } - }); -}); - const hasPython = spawnSync("python3", ["--version"]).status === 0; it.each([1, 500, 1000, 300_000])( diff --git a/src/ida/IdaNativeProtocol.test.ts b/src/ida/IdaNativeProtocol.test.ts index bbeb70542b..9f5983ef59 100644 --- a/src/ida/IdaNativeProtocol.test.ts +++ b/src/ida/IdaNativeProtocol.test.ts @@ -1,7 +1,4 @@ -import { - IDA_COMPATIBILITY_PROFILES, - readIdaConfiguration, -} from "./IdaConfiguration.js"; +import { IDA_COMPATIBILITY_PROFILES } from "./IdaConfiguration.js"; import { rm, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; @@ -282,38 +279,6 @@ describe("IDA selected registration factories", () => { for (const client of clients) await client.close(); }); - it("requires explicit opt-in and rejects native headless registrations", async () => { - const { root } = await fixture(); - const path = join(root, "native.json"); - await writeFile( - path, - JSON.stringify({ url: "http://127.0.0.1:13337/mcp", protocol: "native" }), - ); - expect(await readIdaConfiguration(path, { resourceScope })).toMatchObject({ - ok: true, - value: { mode: "attached", protocol: "native" }, - }); - await writeFile( - path, - JSON.stringify({ - url: "http://127.0.0.1:13337/mcp", - protocol: "native", - mode: "headless", - }), - ); - expect((await readIdaConfiguration(path, { resourceScope })).ok).toBe( - false, - ); - await writeFile( - path, - JSON.stringify({ command: "python", protocol: "legacy" }), - ); - expect( - (await readIdaConfiguration(path, { resourceScope })).ok, - "the removed legacy protocol is refused, not read as native", - ).toBe(false); - }); - it("commits native profile semantics and advertises GUI effects without starting a provider", async () => { const { root, target, producer } = await fixture(); const path = join(root, "profile.json");