Files
rea/tests/boundary/mcp/ghidraFailureDiagnostics.test.ts
T
YsopwnableandGitHub 7e96f25f8b fix(mcp): deliver typed errors without invalid structured output (#1277)
* fix(mcp): deliver tool errors within advertised schema contracts

Retain complete typed JSON error content while omitting non-conforming
structured errors at the public transport boundary. Recover oversized
diagnostics into Evidence before removing their private structured carrier.
Update schema-validated client readers and cover actual stdio delivery.

Closes #1261

Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)

* test(mcp): read typed errors in canonical Evidence regressions

* test(mcp): validate public error diagnostics in acceptance workflows
2026-10-09 13:54:32 +00:00

82 lines
2.8 KiB
TypeScript

import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
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", {});
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_kind: "protocol",
failure_message:
"Ghidra serial request execution rejected unexpectedly",
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(parseMcpToolError(mcp)).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);