Files
reverse-engineering-anything/tests/boundary/mcp/toolErrorSchemaDelivery.test.ts
T
morluto c7fa6af8a3 test: fail loudly on setup refusals and assert exact MCP refusal and linkage facts (#15368)
* test(mcp): assert exact refusal, identity and Evidence linkage facts

Replace isError-only, expect.any and oracle-mirror checks in MCP and CLI workflow tests with the exact code, reason, subject identity and Evidence links the producers report. The capability-unavailable unknowns test now opens its target, so it exercises the path it names instead of NoBinaryOpenError.

* test: fail loudly on setup refusals, unrecorded paths and zombie liveness

Three shared helpers remove weakness classes from the suite:

- callOk (tests/support/mcp/toolResult.ts) fails at the setup step when a
  tool used as fixture setup refuses. It replaces the build-computer copy
  and the unchecked open_binary calls. serverUnknownsMcp's
  capability-unavailable test passed only because open_binary failed: its
  fixture refused health, and NoBinaryOpenError has the same "unavailable"
  category. The fixture now answers health, and the test asserts
  capability_unavailable for procedure_pseudo_code.
- expectRemoved (tests/support/expectRemoved.ts) throws when no path was
  recorded; access(list[0] ?? "") passed because "" is also ENOENT.
- expectProcessRunning checks ps state instead of signal 0, which still
  reaches a zombie that REA wrongly signalled.

Also asserts the open target before and after an ordinary close, the
written overwrite snapshot, and the comparison's links, status and
supporting unknown.

* test(mcp): compare delivered recovery with its owning projection
2026-12-01 02:26:44 +00:00

53 lines
2.2 KiB
TypeScript

import { canonicalOutputSchema } from "../../fixtures/canonicalOutputSchema.js";
import { join } from "node:path";
import { Ajv2020 } from "ajv/dist/2020.js";
import { expect, it } from "vitest";
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it("delivers typed tool failures without violating the advertised success schema over stdio", async () => {
const root = await createTestTempDirectory("rea-tool-error-schema-");
const missing = join(root, "not-present.bin");
const { client, call } = await connectLocalToolsMcp();
const tools = (await client.listTools()).tools;
const requests = [
{ name: "list_documents", arguments: {} },
{ name: "open_binary", arguments: { path: missing } },
{
name: "analyze_javascript_application",
arguments: { input_path: missing },
},
{ name: "inspect_artifact", arguments: {} },
];
for (const request of requests) {
const tool = tools.find(({ name }) => name === request.name);
if (tool === undefined)
throw new Error(`${request.name} omitted its output schema`);
const reply = await client.callTool(request, { toolDefinition: tool });
const diagnostic = parseMcpToolError(reply);
expect(diagnostic.error.message, request.name).not.toBe("");
if ("path" in request.arguments || "input_path" in request.arguments)
expect(JSON.stringify(diagnostic), request.name).toContain(
JSON.stringify(missing).slice(1, -1),
);
// The diagnostic travels once, as text, so the advertised success schema
// never sees it.
expect(reply.isError, request.name).toBe(true);
expect(reply.structuredContent, request.name).toBeUndefined();
}
const successful = await call("get_evidence_bundle", {});
expect(successful.isError).not.toBe(true);
const validate = new Ajv2020({
strict: false,
validateFormats: false,
}).compile(canonicalOutputSchema("get_evidence_bundle"));
expect(
validate(successful.structuredContent),
JSON.stringify(validate.errors),
).toBe(true);
await client.ping();
});