Files
rea/tests/boundary/mcp/ghidraFailureDiagnostics.test.ts
T

80 lines
2.7 KiB
TypeScript

import { expect, it } from "vitest";
import { logCliCommand } from "../../../src/cliLogging.js";
import { analysisErrorProjectionSchema } from "../../../src/contracts/errorSchemas.js";
import { GhidraRequestQueue } from "../../../src/ghidra/GhidraRequestQueue.js";
import { bindGhidraSessionFailure } from "../../../src/ghidra/GhidraSessionError.js";
import { silentLogger } from "../../../src/logger.js";
import { connectGhidraMcp } from "./ghidraMcpHarness.js";
it("preserves queue failure diagnostics through the provider, CLI adapter and SDK MCP transport", async () => {
const token = "fixture-authentication-token";
const cause = Object.assign(
new TypeError(
`Decode failed ${token}: /tmp/password-fixture http://localhost/secret?token=public-value`,
),
{ code: "EDECODE" },
);
const failure = bindGhidraSessionFailure(
() => ({
target_path: "/tmp/public-fixture",
target_sha256: "a".repeat(64),
}),
(value) => value.replaceAll(token, "[REDACTED]"),
);
const queue = new GhidraRequestQueue(
async () => {
throw cause;
},
failure,
() => Promise.resolve(),
);
const harness = await connectGhidraMcp(
"ghidra-failure-diagnostics",
(operation, input, options) => queue.run(operation, input, options ?? {}),
);
const previousExitCode = process.exitCode;
try {
const cli = await logCliCommand(silentLogger, "inspect", async () => {
const result = await harness.session.execute("list_procedures", {
document: null,
});
if (!result.ok) throw result.error;
return result.value.result;
});
expect(process.exitCode).toBe(1);
const parsed = analysisErrorProjectionSchema.parse(cli);
expect(parsed).toMatchObject({
code: "execution_failure",
details: {
diagnostics: {
target_path: "/tmp/public-fixture",
failure_cause: {
name: "TypeError",
code: "EDECODE",
message:
"Decode failed [REDACTED]: /tmp/password-fixture http://localhost/secret?token=public-value",
},
},
},
});
const mcp = await harness.mcp.callTool({
name: "list_procedures",
arguments: {},
});
expect(mcp.isError).toBe(true);
expect(mcp.structuredContent).toMatchObject({ error: parsed });
expect(mcp.content).toContainEqual(
expect.objectContaining({
type: "text",
text: expect.stringContaining("EDECODE"),
}),
);
expect(JSON.stringify(mcp)).not.toContain(token);
expect(JSON.stringify(mcp)).not.toContain(cause.stack);
} finally {
process.exitCode = previousExitCode;
await harness.close();
}
}, 30_000);