mirror of
https://github.com/morluto/rea.git
synced 2026-11-14 10:43:30 +00:00
* 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.
72 lines
2.6 KiB
TypeScript
72 lines
2.6 KiB
TypeScript
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
|
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
|
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
cliTest(
|
|
"preserves caller unknown capacities and omission coverage through real worker, CLI and stdio MCP",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-js-unknown-capacity-");
|
|
for (const name of ["first.js", "second.js"])
|
|
await writeFile(
|
|
join(root, name),
|
|
"globalThis.u.p(globalThis.v[k]);\n".repeat(4),
|
|
);
|
|
const options = {
|
|
max_semantic_nodes: 100,
|
|
max_semantic_nodes_per_file: 100,
|
|
max_semantic_unknowns: 3,
|
|
max_semantic_unknowns_per_file: 2,
|
|
};
|
|
const contract = toolContract("analyze_javascript_application");
|
|
const output = await cli.run({
|
|
arguments: [
|
|
"analyze-javascript-application",
|
|
root,
|
|
"--format",
|
|
"json",
|
|
"--max-semantic-nodes",
|
|
"100",
|
|
"--max-semantic-nodes-per-file",
|
|
"100",
|
|
"--max-semantic-unknowns",
|
|
"3",
|
|
"--max-semantic-unknowns-per-file",
|
|
"2",
|
|
],
|
|
});
|
|
expect(output.exitCode).toBe(0);
|
|
const evidence = contract.outputSchema.parse(output.json);
|
|
expect(evidence.parameters).toMatchObject(options);
|
|
const result = javascriptApplicationAnalysisResultSchema.parse(
|
|
evidence.normalized_result,
|
|
);
|
|
expect(result.semantic_graph.unknowns).toHaveLength(3);
|
|
expect(result.semantic_graph.coverage).toMatchObject({
|
|
status: "partial",
|
|
truncated: true,
|
|
omitted_nodes: 0,
|
|
});
|
|
expect(
|
|
result.semantic_graph.coverage.omitted_unknown_occurrences!.reduce(
|
|
(sum, row) => sum + row.occurrences,
|
|
0,
|
|
),
|
|
).toBe(29);
|
|
const { client } = await connectLocalToolsMcp();
|
|
const response = await client.callTool({
|
|
name: contract.name,
|
|
arguments: { input_path: root, detail: "complete", ...options },
|
|
});
|
|
expect(response.isError, JSON.stringify(response)).not.toBe(true);
|
|
const mcp = contract.outputSchema.parse(response.structuredContent);
|
|
expect(mcp.parameters).toEqual(evidence.parameters);
|
|
expect(mcp.evidence_id).toBe(evidence.evidence_id);
|
|
expect(mcp.normalized_result).toEqual(evidence.normalized_result);
|
|
},
|
|
);
|