mirror of
https://github.com/morluto/rea.git
synced 2026-10-31 03:45:39 +00:00
Route application and provider-environment harnesses through the shared MCP connection owner. Join accepted handshakes during shutdown, retain each failed close for retry, preserve primary and independent cleanup failures, and release provider files only after their session closes. Surface BinarySession close Result errors in production and artifact fixture teardown. Add real SDK and descriptor-boundary regressions for startup races, concurrent cleanup, mixed failures and recovery. Use a provider-free plist for descriptor ownership so installed deep engines cannot change the test outcome.
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
import type { Client } from "@modelcontextprotocol/client";
|
|
import { expect, type OnTestFinishedHandler } from "vitest";
|
|
|
|
import { createArtifactBinarySession } from "../../../src/composition/binary.js";
|
|
import { createServer } from "../../../src/server/createServer.js";
|
|
import type { TestMcp } from "./mcpFixture.js";
|
|
|
|
const openSessionTarget = async (
|
|
mcp: TestMcp,
|
|
onTestFinished: (handler: OnTestFinishedHandler) => void,
|
|
operation: "open_binary" | "open_bundle_resources",
|
|
path: string,
|
|
): Promise<Client> => {
|
|
const session = await createArtifactBinarySession(process.env);
|
|
onTestFinished(async () => {
|
|
const result = await session.close();
|
|
if (!result.ok) throw result.error;
|
|
});
|
|
const client = await mcp.connect(createServer({ kind: "session", session }));
|
|
const opened = await client.callTool({
|
|
name: operation,
|
|
arguments: { path },
|
|
});
|
|
expect(opened.isError, JSON.stringify(opened.content)).not.toBe(true);
|
|
return client;
|
|
};
|
|
|
|
/** Open a static artifact target in the production artifact-only MCP composition. */
|
|
export const openArtifactTarget = (
|
|
mcp: TestMcp,
|
|
onTestFinished: (handler: OnTestFinishedHandler) => void,
|
|
path: string,
|
|
): Promise<Client> =>
|
|
openSessionTarget(mcp, onTestFinished, "open_binary", path);
|
|
|
|
/** Open a caller-selected bundle resource root in the production MCP session. */
|
|
export const openBundleResourcesTarget = (
|
|
mcp: TestMcp,
|
|
onTestFinished: (handler: OnTestFinishedHandler) => void,
|
|
path: string,
|
|
): Promise<Client> =>
|
|
openSessionTarget(mcp, onTestFinished, "open_bundle_resources", path);
|