mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
* test: own temporary directories through createTestTempDirectory in remaining tests/ Give per-test directories in the remaining tests/ suites to createTestTempDirectory so onTestFinished removes them through removeTestWorkspace. Keep suite-scoped roots and child-process directories whose removal is the assertion. * test: drop empty cleanup callbacks and keep the capture skip reason visible Remove the no-op withVerifierCleanup steps left after directory removal moved to createTestTempDirectory. Put the native capture skip explanation in the Linux sample test name, because it.skipIf only tests truthiness. Co-authored-by: morluto <morluto@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
import { canonicalOutputSchema } from "../../fixtures/canonicalOutputSchema.js";
|
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
|
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
import { expect, it, onTestFinished } from "vitest";
|
|
import { z } from "zod";
|
|
|
|
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 failures: string[] = [];
|
|
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),
|
|
);
|
|
if (reply.structuredContent !== undefined) {
|
|
const validate = new Ajv2020({
|
|
strict: false,
|
|
validateFormats: false,
|
|
}).compile(canonicalOutputSchema(tool.name));
|
|
if (!validate(reply.structuredContent)) failures.push(request.name);
|
|
}
|
|
}
|
|
expect(failures).toEqual([]);
|
|
const successful = await call("get_evidence_bundle", {});
|
|
expect(successful.isError).not.toBe(true);
|
|
expect(successful.structuredContent).toBeDefined();
|
|
await client.ping();
|
|
});
|