Files
reverse-engineering-anything/tests/boundary/mcp/javascriptEndpointCandidate.test.ts
T
morluto 71712f27f7 test(mcp): open stdio clients through the shared local-tools fixture (#10411)
* test(mcp): open stdio clients through the shared local-tools fixture

Twelve files built their own StdioClientTransport and Client for
`rea mcp`. Those clients never listed tools, so the SDK did not
validate structured results against advertised output schemas, and each
file repeated transport setup, stderr draining and close ordering.

Use connectLocalToolsMcp, which lists tools, validates replies,
silences logging, leaves deep providers unconfigured and owns cleanup.
Per-test clients register test-scoped cleanup; module-level clients
collect cleanup for afterAll.

* test(mcp): keep failed file-scoped MCP cleanup owned

The three module-level clients removed every cleanup callback before
running them, so a failed cleanup lost its only handle. Add
fileLocalToolsMcp, which connects before the file's tests and removes
each cleanup only after it succeeds, and use it in those files.
2026-11-14 11:47:55 +08:00

71 lines
2.4 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it } from "vitest";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it("preserves Map omission and uncertain endpoint Evidence through public MCP", async () => {
const root = await createTestTempDirectory("rea-map-endpoint-mcp-");
await writeFile(
join(root, "app.mjs"),
`
const records = new Map();
const alias = records;
alias.get('/accounts');
records.delete('/accounts');
client.get('/uncertain');
fetch('/network');
`,
);
const { client } = await connectLocalToolsMcp();
const output = await client.callTool({
name: "analyze_javascript_application",
arguments: { input_path: root },
});
expect(output.isError).not.toBe(true);
const evidence = parseEvidence(output.structuredContent);
const text = output.content.find((block) => block.type === "text");
expect(text?.type === "text" ? JSON.parse(text.text) : undefined).toEqual(
evidence,
);
const result = javascriptApplicationAnalysisResultSchema.parse(
evidence.normalized_result,
);
const endpoints = result.graph.nodes.filter(
({ kind }) => kind === "endpoint",
);
expect(
endpoints
.flatMap(({ observations }) =>
observations.map(({ properties }) => properties.value),
)
.sort(),
).toEqual(["/network", "/uncertain"]);
const candidate = endpoints.find(
({ observations }) => observations[0]?.properties.value === "/uncertain",
);
expect(candidate?.observations[0]).toMatchObject({
properties: { interpretation: "candidate" },
evidence: {
state: "inferred",
confidence: "low",
limitations: expect.arrayContaining([
expect.stringContaining("only a candidate"),
]),
},
});
expect(
result.graph.edges.find(
({ target_node_id }) => target_node_id === candidate?.node_id,
)?.evidence,
).toMatchObject({ state: "inferred", confidence: "low" });
expect(
endpoints.find(
({ observations }) => observations[0]?.properties.value === "/network",
)?.observations[0]?.evidence,
).toMatchObject({ state: "observed", confidence: "exact" });
});