Files
rea/tests/boundary/mcp/replayMachineMcp.test.ts
T
morlutoandGitHub b8a9da0c0f refactor(mcp): make analysis states unrepresentable (#468)
* refactor(config): parse capability settings into exact states

* refactor(runtime): encode replay and process outcomes exactly

* refactor: make analysis states unrepresentable

* refactor(mcp): register canonical schemas with SDK

* fix: preserve capability and catalog invariants

* fix(build): remove stale compiled modules

* fix(replay): update real verifier policy dependency

* fix(package): verify the complete MCP catalog

* fix(test): supply complete replay reload policy

* refactor(contracts): centralize output schema lookup

* refactor(mcp): delegate protocol boundaries to SDK

* fix(browser): approve real source capture

* fix(mcp): preserve catalog guidance
2026-08-10 02:28:11 +08:00

72 lines
2.5 KiB
TypeScript

import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
import { describe, expect, it } from "vitest";
import { composeBinarySessionFromFactory } from "../../../src/application/BinarySessionComposition.js";
import { REPLAY_MACHINE_RUN_EXAMPLE } from "../../../src/contracts/replayMachineExample.js";
import { createServer } from "../../../src/server/createServer.js";
import { observed } from "../../fixtures/analysisExecution.js";
describe("direct replay machine MCP parity", () => {
it("returns typed journal output and safe validation failures", async () => {
const session = composeBinarySessionFromFactory(() => ({
execute: () => Promise.resolve(observed(null)),
close: () => Promise.resolve(),
}));
const server = createServer(session, session);
const client = new Client({ name: "replay-machine-test", version: "1" });
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
const example = REPLAY_MACHINE_RUN_EXAMPLE;
try {
await server.connect(serverTransport);
await client.connect(clientTransport);
const result = await client.callTool({
name: "run_replay_machine",
arguments: example,
});
expect(result).toMatchObject({
structuredContent: {
result: {
schema_version: 1,
final_state: "complete",
terminal: true,
decisions: [{ outcome: "matched", transition_sequence: 0 }],
transition_journal: [
{
transition_id: "accept_callback",
captured_aliases: [{ name: "token", sensitive: true }],
},
],
},
},
});
expect(JSON.stringify(result)).not.toContain("opaque");
const invalid = await client.callTool({
name: "run_replay_machine",
arguments: {
...example,
events: [
{
protocol: "http",
connection: "not_applicable",
at_ms: 0,
method: null,
path: "/callback",
headers: {},
body: "private-request-body",
},
],
},
});
expect(invalid.isError).toBe(true);
expect(invalid.structuredContent).toBeUndefined();
expect(JSON.stringify(invalid)).not.toContain("private-request-body");
} finally {
await client.close();
await server.close();
await session.close();
}
});
});