mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 18:06:46 +00:00
test(mcp): share caller-owned in-memory handshakes (#14424)
This commit is contained in:
1 parent
299c592b63
commit
efeac85e0f
13 files changed
+92
-171
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import type { Client } from "@modelcontextprotocol/client";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -27,7 +28,6 @@ import {
|
||||
jsonResult,
|
||||
resources,
|
||||
} from "./enhancedToolsHarness.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
|
||||
afterEach(closeEnhancedToolResources);
|
||||
|
||||
@@ -320,15 +320,11 @@ const openSession = async (port: AnalysisOperationPort) => {
|
||||
},
|
||||
);
|
||||
const server = createServer({ kind: "session", session });
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{ name: "call-graph-cleanup", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: target, format: "dos-com" },
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { join } from "node:path";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { PROCEDURES, inventory, jsonResult } from "./enhancedToolsHarness.js";
|
||||
|
||||
@@ -15,7 +15,6 @@ import { createAnalysisExecution } from "../../../src/ports/AnalysisProvider.js"
|
||||
import { ok as resultOk, err } from "../../../src/domain/result.js";
|
||||
import { AnalysisCapabilityUnavailableError } from "../../../src/domain/analysisErrorCore.js";
|
||||
import { nativeDispatchMetadataResultSchema } from "../../../src/domain/native/objcSwiftMetadata.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const targetObservation = (value: unknown) =>
|
||||
@@ -225,16 +224,11 @@ afterEach(async () => {
|
||||
|
||||
const connect = async (analysis: AnalysisOperationPort = fixturePort()) => {
|
||||
const server = createServer({ kind: "fixed", analysis });
|
||||
const client = new Client(
|
||||
return connectFixtureClient(
|
||||
server,
|
||||
{ name: "enhanced-test", version: "1.0.0" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return client;
|
||||
};
|
||||
|
||||
// oxlint-disable-next-line max-lines-per-function -- keep the complete production registration checks together.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
@@ -5,10 +6,8 @@ import {
|
||||
jsonValueSchema,
|
||||
type JsonValue,
|
||||
} from "../../../src/domain/jsonValue.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import type { AnalysisOperationPort } from "../../../src/ports/AnalysisProvider.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
|
||||
export const PROCEDURES = {
|
||||
"0x1": "_TtC7Fixture5Class",
|
||||
@@ -29,16 +28,11 @@ export const connect = async (
|
||||
environment: Readonly<NodeJS.ProcessEnv> = process.env,
|
||||
) => {
|
||||
const server = createServer({ kind: "fixed", analysis }, { environment });
|
||||
const client = new Client(
|
||||
return connectFixtureClient(
|
||||
server,
|
||||
{ name: "enhanced-test", version: "1.0.0" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return client;
|
||||
};
|
||||
|
||||
/** Close every client/server pair opened by `connect` in this module. */
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import type { Client } from "@modelcontextprotocol/client";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import type { AnalysisOperationPort } from "../../../src/ports/AnalysisProvider.js";
|
||||
@@ -8,7 +9,6 @@ import type { JsonValue } from "../../../src/domain/jsonValue.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
import { createAnalysisExecution } from "../../../src/ports/AnalysisProvider.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
|
||||
const provider = {
|
||||
id: "fixture-native",
|
||||
@@ -37,16 +37,11 @@ const connect = async (
|
||||
execute: AnalysisOperationPort["execute"],
|
||||
): Promise<Client> => {
|
||||
const server = createServer({ kind: "fixed", analysis: { execute } });
|
||||
const client = new Client(
|
||||
return connectFixtureClient(
|
||||
server,
|
||||
{ name: "native-contract-test", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return client;
|
||||
};
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { unknownTarget } from "../../../src/domain/targetIdentity.js";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -32,7 +32,6 @@ import {
|
||||
jsonResult,
|
||||
resources,
|
||||
} from "./enhancedToolsHarness.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
|
||||
afterEach(closeEnhancedToolResources);
|
||||
|
||||
@@ -275,15 +274,11 @@ const openSession = async (port: AnalysisOperationPort) => {
|
||||
}),
|
||||
});
|
||||
const server = createServer({ kind: "session", session });
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{ name: "value-trace-cleanup", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: target, format: "dos-com" },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import {
|
||||
valueTraceDiamond,
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
closeEnhancedToolResources,
|
||||
resources,
|
||||
} from "./enhancedToolsHarness.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
|
||||
afterEach(closeEnhancedToolResources);
|
||||
|
||||
@@ -44,16 +43,11 @@ const connectTraceSession = async (
|
||||
{ kind: "session", session },
|
||||
{ environment: { REA_MCP_OUTPUT_SCHEMA_PROFILE: profile } },
|
||||
);
|
||||
const client = new Client(
|
||||
return connectFixtureClient(
|
||||
server,
|
||||
{ name: "value-trace-test", version: "1.0.0" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return client;
|
||||
};
|
||||
|
||||
it.each(["compact"] as const)(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import type { AnalysisOperationPort } from "../../../src/ports/AnalysisProvider.js";
|
||||
@@ -19,7 +19,6 @@ import { composeBinarySession } from "../../../src/application/binary/BinarySess
|
||||
import { AnalysisProviderRegistry } from "../../../src/application/binary/AnalysisProviderRegistry.js";
|
||||
import { createBinarySessionTargets } from "../../fixtures/binarySession.js";
|
||||
import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
|
||||
interface Invocation {
|
||||
readonly name: string;
|
||||
@@ -130,16 +129,11 @@ afterEach(async () => {
|
||||
|
||||
const connect = async (analysis: AnalysisOperationPort) => {
|
||||
const server = createServer({ kind: "fixed", analysis });
|
||||
const client = new Client(
|
||||
return connectFixtureClient(
|
||||
server,
|
||||
{ name: "contract-test", version: "1.0.0" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return client;
|
||||
};
|
||||
|
||||
describe("official tool input contracts", () => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { unknownTarget } from "../../../src/domain/targetIdentity.js";
|
||||
import { ok as resultOk } from "../../../src/domain/result.js";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { INLINE_EVIDENCE_MCP_ENVIRONMENT } from "../../../scripts/lib/mcp-verification-environment.mjs";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
@@ -17,7 +17,6 @@ import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { observed as ok } from "../../fixtures/analysisExecution.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
|
||||
const resources: Array<{ close(): Promise<void> }> = [];
|
||||
const temporaryRoots: string[] = [];
|
||||
@@ -51,16 +50,11 @@ const comparisonClient = async (
|
||||
{ kind: "session", session },
|
||||
{ environment: { ...process.env, ...INLINE_EVIDENCE_MCP_ENVIRONMENT } },
|
||||
);
|
||||
const client = new Client(
|
||||
return connectFixtureClient(
|
||||
server,
|
||||
{ name: "trace-parity", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return client;
|
||||
};
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { parseMcpEvidenceBundle } from "../../fixtures/mcpEvidenceBundle.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
@@ -545,19 +546,14 @@ afterEach(async () => {
|
||||
|
||||
const connect = async (analysis: AnalysisOperationPort) => {
|
||||
const server = createServer({ kind: "fixed", analysis });
|
||||
const client = new Client(
|
||||
return connectFixtureClient(
|
||||
server,
|
||||
{
|
||||
name: "integration-test",
|
||||
version: "1.0.0",
|
||||
},
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return client;
|
||||
};
|
||||
|
||||
const text = (result: CallToolResult): string => {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { unknownTarget } from "../../../src/domain/targetIdentity.js";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { createToolResultDelivery } from "../../../src/server/toolResult.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
|
||||
@@ -33,7 +33,6 @@ import { EMPTY_PROCESS_CAPTURE_EXAMPLE } from "../../../src/domain/process/proce
|
||||
import { PROCESS_PROVIDER } from "../../../src/domain/process/processEvidenceProvider.js";
|
||||
|
||||
import { processCaptureSchema } from "../../../src/domain/process/processCapture.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
const resources: Array<{ close(): Promise<void> }> = [];
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -155,15 +154,11 @@ it("rejects divergent imported histories without suggesting an unchanged retry",
|
||||
throw new Error("no target");
|
||||
});
|
||||
const server = createServer({ kind: "session", session });
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{ name: "conflicting-history", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const emptyExport = await client.callTool({
|
||||
name: "export_evidence_bundle",
|
||||
arguments: { path: join(root, "empty-export.json") },
|
||||
@@ -213,15 +208,11 @@ it("does not record capability unavailability without supporting Evidence", asyn
|
||||
providerWithCapabilities(["procedure_pseudo_code"]),
|
||||
);
|
||||
const server = createServer({ kind: "session", session });
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{ name: "unavailable-unknown", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: process.execPath },
|
||||
@@ -284,15 +275,11 @@ it("records capture disagreement as a contradicted unknown", async () => {
|
||||
expect(session.recordEvidence(leftEvidence).ok).toBe(true);
|
||||
expect(session.recordEvidence(rightEvidence).ok).toBe(true);
|
||||
const server = createServer({ kind: "session", session });
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{ name: "comparison-unknown", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
|
||||
const mismatched = await client.callTool({
|
||||
name: "compare_process_captures",
|
||||
@@ -380,15 +367,11 @@ it("records capture disagreement as a contradicted unknown", async () => {
|
||||
it("pages filtered unknown heads through the public MCP contract", async () => {
|
||||
const session = createTestBinarySession(providerWithCapabilities([]));
|
||||
const server = createServer({ kind: "session", session });
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{ name: "unknown-pagination", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
|
||||
const created = [
|
||||
["matching c", "high", "pagination"],
|
||||
@@ -537,15 +520,11 @@ it("pages filtered unknown heads through the public MCP contract", async () => {
|
||||
it("reports contradictory unknown input as a correctable request", async () => {
|
||||
const session = createTestBinarySession(providerWithCapabilities([]));
|
||||
const server = createServer({ kind: "session", session });
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{ name: "unknown-input", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const fields = {
|
||||
severity: "medium",
|
||||
required_authority: "analyst-inference",
|
||||
@@ -654,14 +633,11 @@ it("returns exact committed unknown receipts when creation and update replies ov
|
||||
{ kind: "session", session },
|
||||
{ delivery: createToolResultDelivery(8 * 1024) },
|
||||
);
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{ name: "unknown-overflow-receipt", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [ct, st] = InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(st);
|
||||
await client.connect(ct);
|
||||
const fields = {
|
||||
severity: "medium",
|
||||
supporting_evidence_ids: [],
|
||||
@@ -741,15 +717,11 @@ it("returns exact committed unknown receipts when creation and update replies ov
|
||||
it("preserves graph constraint facts and rejects atomically until input is corrected", async () => {
|
||||
const session = createTestBinarySession(providerWithCapabilities([]));
|
||||
const server = createServer({ kind: "session", session });
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{ name: "unknown-constraint", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const fields = {
|
||||
severity: "medium",
|
||||
required_authority: "controlled-replay",
|
||||
@@ -862,14 +834,11 @@ it("recovers an oversized list with same-session paging or export", async () =>
|
||||
{ kind: "session", session },
|
||||
{ delivery: createToolResultDelivery(8 * 1024) },
|
||||
);
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{ name: "unknown-list-recovery", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [ct, st] = InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(st);
|
||||
await client.connect(ct);
|
||||
const fields = {
|
||||
severity: "medium",
|
||||
domain: "overflow-list",
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import {
|
||||
canonicalOutputSchema,
|
||||
withCanonicalOutputSchema,
|
||||
} from "../../fixtures/canonicalOutputSchema.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { ok as resultOk } from "../../../src/domain/result.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
} from "../../../src/contracts/toolContracts.js";
|
||||
import { expandToolAvailability } from "../../../src/contracts/toolOutputSchemaPrimitives.js";
|
||||
import { advertisedToolPresentation } from "../../../src/contracts/mcpSchemaPresentation.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
|
||||
const resources: Array<{ close(): Promise<void> }> = [];
|
||||
|
||||
@@ -35,19 +34,14 @@ afterEach(async () => {
|
||||
|
||||
const connect = async (analysis: AnalysisOperationPort) => {
|
||||
const server = createServer({ kind: "fixed", analysis });
|
||||
const client = new Client(
|
||||
return connectFixtureClient(
|
||||
server,
|
||||
{
|
||||
name: "integration-test",
|
||||
version: "1.0.0",
|
||||
},
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return client;
|
||||
};
|
||||
|
||||
const structured = (result: CallToolResult): Record<string, unknown> => {
|
||||
@@ -121,18 +115,14 @@ it("advertises the complete currently available inventory with a session", async
|
||||
}) satisfies AnalysisClient,
|
||||
);
|
||||
const server = createServer({ kind: "session", session });
|
||||
const client = new Client(
|
||||
const client = await connectFixtureClient(
|
||||
server,
|
||||
{
|
||||
name: "integration-test",
|
||||
version: "1.0.0",
|
||||
},
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
|
||||
const listed = await client.listTools();
|
||||
const names = listed.tools.map((t) => t.name);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { connectFixtureClient } from "../support/mcp/mcpFixture.js";
|
||||
import { STDIO_DEFAULT_MAX_BUFFER_SIZE } from "@modelcontextprotocol/server";
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { z } from "zod";
|
||||
@@ -11,7 +11,6 @@ import { run } from "../../src/main.js";
|
||||
import { createServer } from "../../src/server/createServer.js";
|
||||
import type { EvidenceMcpServer } from "../../src/server/EvidenceMcpServer.js";
|
||||
import { parseMcpToolError } from "../fixtures/mcpToolError.js";
|
||||
import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js";
|
||||
|
||||
const resources: Array<{ close(): Promise<void> }> = [];
|
||||
afterEach(async () => {
|
||||
@@ -19,18 +18,12 @@ afterEach(async () => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
const connect = async (server: EvidenceMcpServer) => {
|
||||
const client = new Client(
|
||||
const connect = (server: EvidenceMcpServer) =>
|
||||
connectFixtureClient(
|
||||
server,
|
||||
{ name: "selected-delivery", version: "1" },
|
||||
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
||||
resources,
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return client;
|
||||
};
|
||||
|
||||
it("keeps independent server budgets for successful results and oversized errors after environment mutation", async () => {
|
||||
const smallBudget = STDIO_DEFAULT_MAX_BUFFER_SIZE;
|
||||
|
||||
@@ -13,6 +13,23 @@ export interface McpClientIdentity {
|
||||
readonly version: string;
|
||||
}
|
||||
|
||||
/** Connect an SDK client while leaving teardown with the caller, including a partial handshake. */
|
||||
export const connectFixtureClient = async (
|
||||
server: McpServer,
|
||||
identity: McpClientIdentity,
|
||||
resources: Array<{ close(): Promise<void> }>,
|
||||
): Promise<Client> => {
|
||||
const client = new Client(identity, {
|
||||
jsonSchemaValidator: createMcpSchemaValidation(),
|
||||
});
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
resources.push(client, server);
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return client;
|
||||
};
|
||||
|
||||
/** Registry for production MCP servers and SDK clients owned by one test. */
|
||||
export interface TestMcp {
|
||||
/** Transfer server ownership on admission; a closed registry leaves it with the caller. */
|
||||
|
||||
Reference in new issue
Block a user