Files
reverse-engineering-anything/src/mcpStartupPolicy.test.ts
T
Syed Rishadandgensokyo-dev a062529bb2 feat(ghidra): bound one procedure's decompile without closing the session (#5662)
* feat(ghidra): bound one procedure's decompile without closing the session

Fixes #5340

* fix(ghidra): report decompile limit as a request timeout

Keeps BinarySession from marking every Ghidra operation unavailable after one procedure's decompile reaches the limit, and names the MCP tool-call deadline in the remediation.

* fix(ghidra): budget the decompile limit and report cancellation-closed sessions

Adds REA_GHIDRA_DECOMPILE_TIMEOUT_SECONDS to the derived Codex/Kimi tool deadline and forwards it through setup. Marks a remote failure that settles after caller cancellation so the timeout projection no longer promises session reuse.

* fix(ghidra): align deadline bounds and cancellation outcomes

* refactor(ghidra): shorten deadline recovery guidance

* fix(mcp): clarify the scope of inferred decompile deadlines

* test(ghidra): verify deadline workflows and document measured costs

Separate failure and registration cases by their distinct contracts.
Record actual Linux Ghidra, CLI and MCP evidence with measured context,
elapsed time, CPU and memory, and explicit remaining coverage limits.

* docs(ghidra): pin integration and distinguish baseline format failures

* fix(ghidra): own failure lifecycle wording in the provider

* test(ghidra): budget timeout fixture generation before allocation

* fix(ghidra): align capability and traversal deadline guidance

* style(config): align deadline guidance formatting

* docs(ghidra): record capability and traversal verification

---------

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-10-24 07:42:50 +08:00

79 lines
2.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { parseClientConfiguration } from "./application/ClientConfigurationDocument.js";
import { clientRegistrationEnvironmentDetails } from "./application/ClientRegistrationEnvironment.js";
import { explicitSetupRegistrationEnvironment } from "./application/SetupRegistrationEnvironment.js";
import {
mcpProviderDeadlineAllowanceMs,
recommendedMcpToolTimeoutSeconds,
} from "./mcpStartupPolicy.js";
const inputs = {
ghidraStartupTimeoutMs: 330_000,
hopperStartupTimeoutMs: 120_000,
} as const;
describe("MCP tool deadline allowance for a Ghidra decompile limit", () => {
it.each([
["ghidra", 930_000],
["auto", 930_000],
["hopper", 120_000],
] as const)(
"allows %s cold startup plus the selected decompile limit",
(analysisProvider, expected) => {
expect(
mcpProviderDeadlineAllowanceMs({
...inputs,
analysisProvider,
ghidraDecompileTimeoutMs: 600_000,
}),
).toBe(expected);
},
);
it("keeps the startup-only allowance when no decompile limit is set", () => {
const allowance = { ...inputs, analysisProvider: "ghidra" } as const;
expect(mcpProviderDeadlineAllowanceMs(allowance)).toBe(330_000);
expect(recommendedMcpToolTimeoutSeconds(allowance)).toBe(450);
});
it("derives the registration allowance from REA_GHIDRA_DECOMPILE_TIMEOUT_SECONDS", () => {
const details = clientRegistrationEnvironmentDetails(
parseClientConfiguration(
JSON.stringify({
mcpServers: {
rea: {
command: "rea",
args: ["mcp"],
env: {
REA_ANALYSIS_PROVIDER: "ghidra",
REA_GHIDRA_DECOMPILE_TIMEOUT_SECONDS: "600",
},
},
},
}),
"json",
),
);
if (!details.ok) throw details.error;
expect(details.value.timeoutInputs).toMatchObject({
analysisProvider: "ghidra",
ghidraDecompileTimeoutMs: 600_000,
});
// 330 s default startup + 600 s limit + 120 s operation headroom.
const timeoutInputs = details.value.timeoutInputs;
if (timeoutInputs === undefined)
throw new Error("Expected resolved decompile timeout inputs");
expect(recommendedMcpToolTimeoutSeconds(timeoutInputs)).toBe(1050);
});
it("forwards an explicit decompile limit into setup registrations", () => {
expect(
explicitSetupRegistrationEnvironment({
REA_GHIDRA_DECOMPILE_TIMEOUT_SECONDS: "600",
UNRELATED: "dropped",
}),
).toEqual({ REA_GHIDRA_DECOMPILE_TIMEOUT_SECONDS: "600" });
});
});