mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 05:51:06 +00:00
* test(settings): fail analysis settings setup steps with the refusal Setup MCP calls asserted only `isError` was not true, so a refused setup step failed as "expected true not to be true" without the refusal, and several setup calls were not checked at all. They now use callOk, which fails at that step with the tool's content. Inventory lookups no longer hide a missing substep or occurrence behind optional chaining. * test(settings): keep the fixture's reply checks on setup steps callOk now also accepts a fixture's call function, so setup steps keep the output-schema checks connectLocalToolsMcp applies to replies.
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import type { Client } from "@modelcontextprotocol/client";
|
|
import type { CallToolResult } from "@modelcontextprotocol/server";
|
|
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
|
|
|
export const text = (result: CallToolResult): string => {
|
|
const content = result.content.find((item) => item.type === "text");
|
|
if (content?.type !== "text") throw new Error("missing text result");
|
|
return content.text;
|
|
};
|
|
|
|
/** Read structured success fields or the typed error carried in text. */
|
|
export const structured = (result: CallToolResult): Record<string, unknown> => {
|
|
if (result.isError === true) return parseMcpToolError(result);
|
|
if (
|
|
typeof result.structuredContent !== "object" ||
|
|
result.structuredContent === null
|
|
)
|
|
throw new Error("missing structured result");
|
|
return Object.fromEntries(Object.entries(result.structuredContent));
|
|
};
|
|
|
|
/**
|
|
* Call a tool whose success the rest of the test depends on, such as
|
|
* `open_binary` or a `start_*` tool used as fixture setup, and fail at that
|
|
* step when it refuses. Refusals such as "nothing is open" otherwise satisfy
|
|
* later assertions that expect an error, an empty list or a null result.
|
|
*/
|
|
export const callOk = async (
|
|
client:
|
|
| Pick<Client, "callTool">
|
|
| ((
|
|
name: string,
|
|
args: Record<string, unknown>,
|
|
) => Promise<CallToolResult>),
|
|
name: string,
|
|
args: Record<string, unknown> = {},
|
|
): Promise<CallToolResult> => {
|
|
// A fixture's own call function keeps the checks it applies to replies,
|
|
// such as output-schema validation.
|
|
const result =
|
|
typeof client === "function"
|
|
? await client(name, args)
|
|
: ((await client.callTool({ name, arguments: args })) as CallToolResult);
|
|
if (result.isError === true)
|
|
throw new Error(
|
|
`Setup step ${name} failed: ${JSON.stringify(result.content)}`,
|
|
);
|
|
return result;
|
|
};
|