* test: strengthen integration oracles and verification * test: bound lifecycle gates and strengthen workflow checks * test: verify complete paged and extracted results * test: preserve bytecode and cancellation evidence * test: strengthen retained evidence and fixture cleanup * test: require cross-projection bridge identities * test: retain fixture owners through cleanup failures * test: verify graph examples and project selectors * test: tighten provider and lifecycle regressions * test: consolidate hex coverage and bound cutter cleanup * test: bound subprocess output waits and strengthen graph checks * test: check mcp recovery and preserve cleanup owners * test: verify structured mcp argument failures * test: preserve artifact cleanup and gdb limit evidence * test: preserve evidence identities and bound provider gates * test: retain browser and comparison cleanup owners * test: bound startup and strengthen fixture oracles * test: bound lifecycle gates and verify recovered evidence * test: verify public outcomes and lifecycle ownership * test: assert precise evidence and release lifecycle gates * test: verify selected facts and bound cleanup waits * test: check retained evidence and decoded records * test: verify final reports and retain cleanup ownership * test: bound reviewed startup gates and retain cleanup * test: verify PE errors and preserve MCP cleanup * test: preserve MCP fixture cleanup ownership * test: release provider gates before late startup
102 lines
3.9 KiB
TypeScript
102 lines
3.9 KiB
TypeScript
import {
|
|
Client,
|
|
StreamableHTTPClientTransport,
|
|
} from "@modelcontextprotocol/client";
|
|
import { describe, expect, onTestFinished } from "vitest";
|
|
|
|
import { advertisedMcpToolSchemas } from "../../fixtures/advertisedMcpTool.js";
|
|
import { expectForeignHostRefused } from "../../support/http/rawRequest.js";
|
|
import { startMcpHttpProcess } from "../../support/mcp/streamableHttpProcess.js";
|
|
import { processTest } from "../../support/process/processFixture.js";
|
|
import { assertAdvertisedMcpContracts } from "./mcpContractHarness.js";
|
|
|
|
const HTTP_BOUNDARY_TIMEOUT_MS = 90_000;
|
|
|
|
const openSession = async (url: URL, name: string) => {
|
|
const transport = new StreamableHTTPClientTransport(url);
|
|
const client = new Client({ name, version: "1" });
|
|
onTestFinished(() => client.close());
|
|
await client.connect(transport);
|
|
expect(transport.sessionId).toEqual(expect.any(String));
|
|
const { toolDefinition } = await advertisedMcpToolSchemas(
|
|
client,
|
|
"binary_session",
|
|
);
|
|
assertAdvertisedMcpContracts(["binary_session"], [toolDefinition]);
|
|
return { transport, client, toolDefinition };
|
|
};
|
|
|
|
/** The shared target answers with its identity only while its providers are still open. */
|
|
const expectIdentity = async ({
|
|
client,
|
|
toolDefinition,
|
|
}: Awaited<ReturnType<typeof openSession>>): Promise<void> => {
|
|
const identity = await client.callTool(
|
|
{ name: "binary_session", arguments: {} },
|
|
{ toolDefinition },
|
|
);
|
|
expect(identity.isError).toBeFalsy();
|
|
expect(identity.structuredContent).toMatchObject({
|
|
result: {
|
|
server_identity: { package: { version: expect.any(String) } },
|
|
},
|
|
});
|
|
};
|
|
|
|
describe("rea mcp --http", () => {
|
|
processTest(
|
|
"serves initialize, tools/list, a tool call and DELETE, then keeps serving later clients",
|
|
async ({ processes }) => {
|
|
const started = await startMcpHttpProcess(processes);
|
|
expect(started.url.hostname).toBe("127.0.0.1");
|
|
expect(started.url.pathname).toBe("/mcp");
|
|
let stdout = "";
|
|
started.child.stdout.on("data", (chunk: Buffer) => {
|
|
stdout += chunk.toString("utf8");
|
|
});
|
|
const first = await openSession(started.url, "streamable-http-boundary");
|
|
expect(() =>
|
|
assertAdvertisedMcpContracts(
|
|
["binary_session"],
|
|
[first.toolDefinition, first.toolDefinition],
|
|
),
|
|
).toThrow();
|
|
const { name } = first.toolDefinition;
|
|
expect(() =>
|
|
assertAdvertisedMcpContracts(["binary_session"], [{ name }]),
|
|
).toThrow();
|
|
await expectIdentity(first);
|
|
await first.transport.terminateSession();
|
|
expect(first.transport.sessionId).toBeUndefined();
|
|
await first.client.close();
|
|
// DELETE ended the session, not the server: the next client's tools still work.
|
|
const second = await openSession(started.url, "next-session");
|
|
await expectIdentity(second);
|
|
// A client that leaves without DELETE does not block the listener: the next initialize replaces it.
|
|
const third = await openSession(started.url, "replacing-session");
|
|
expect(third.transport.sessionId).not.toBe(second.transport.sessionId);
|
|
await expectIdentity(third);
|
|
await expect(expectIdentity(second)).rejects.toThrow("Session not found");
|
|
await second.client.close();
|
|
await third.transport.terminateSession();
|
|
await third.client.close();
|
|
expect(stdout).toBe("");
|
|
expect(started.stderr()).toContain('"transport":"streamable-http"');
|
|
expect(started.stderr()).toContain(
|
|
"MCP HTTP session replaced by a new client",
|
|
);
|
|
},
|
|
HTTP_BOUNDARY_TIMEOUT_MS,
|
|
);
|
|
|
|
processTest(
|
|
"refuses a non-loopback Host header on the loopback bind",
|
|
async ({ processes }) => {
|
|
const { url } = await startMcpHttpProcess(processes);
|
|
const refused = await expectForeignHostRefused(url);
|
|
expect(refused.body).not.toContain("127.0.0.1");
|
|
},
|
|
HTTP_BOUNDARY_TIMEOUT_MS,
|
|
);
|
|
});
|