|
| 1 | +import { Client } from "@modelcontextprotocol/sdk/client/index.js"; |
| 2 | +import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | +import { |
| 5 | + createMinerMcpServer, |
| 6 | + MINER_PING_STATUS, |
| 7 | +} from "../../packages/gittensory-miner/bin/gittensory-miner-mcp.js"; |
| 8 | + |
| 9 | +// Smoke test for the gittensory-miner MCP scaffold (#5153). Drives the real server over an in-memory |
| 10 | +// transport (no child process, no AMS state on disk) and exercises the single gittensory_miner_ping tool. |
| 11 | + |
| 12 | +async function connectedClient(): Promise<Client> { |
| 13 | + const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); |
| 14 | + const client = new Client({ name: "miner-mcp-test", version: "0.0.0" }); |
| 15 | + await Promise.all([createMinerMcpServer().connect(serverTransport), client.connect(clientTransport)]); |
| 16 | + return client; |
| 17 | +} |
| 18 | + |
| 19 | +function pingText(result: { content: Array<{ type: string; text?: string }> }): string { |
| 20 | + const first = result.content[0]; |
| 21 | + if (!first || first.type !== "text" || typeof first.text !== "string") { |
| 22 | + throw new Error("expected a single text content block"); |
| 23 | + } |
| 24 | + return first.text; |
| 25 | +} |
| 26 | + |
| 27 | +describe("gittensory-miner MCP scaffold (#5153)", () => { |
| 28 | + it("exposes exactly the gittensory_miner_ping tool", async () => { |
| 29 | + const client = await connectedClient(); |
| 30 | + const { tools } = await client.listTools(); |
| 31 | + expect(tools.map((tool) => tool.name)).toEqual(["gittensory_miner_ping"]); |
| 32 | + }); |
| 33 | + |
| 34 | + it("gittensory_miner_ping returns the static, non-secret status object", async () => { |
| 35 | + const client = await connectedClient(); |
| 36 | + const result = (await client.callTool({ name: "gittensory_miner_ping", arguments: {} })) as { |
| 37 | + content: Array<{ type: string; text?: string }>; |
| 38 | + }; |
| 39 | + expect(JSON.parse(pingText(result))).toEqual({ status: "ok", tool: "gittensory_miner_ping" }); |
| 40 | + expect(JSON.parse(pingText(result))).toEqual(MINER_PING_STATUS); |
| 41 | + }); |
| 42 | + |
| 43 | + it("returns the same object on every call, with no AMS state required on disk (invariant)", async () => { |
| 44 | + const client = await connectedClient(); |
| 45 | + const first = (await client.callTool({ name: "gittensory_miner_ping", arguments: {} })) as { |
| 46 | + content: Array<{ type: string; text?: string }>; |
| 47 | + }; |
| 48 | + const second = (await client.callTool({ name: "gittensory_miner_ping", arguments: {} })) as { |
| 49 | + content: Array<{ type: string; text?: string }>; |
| 50 | + }; |
| 51 | + expect(pingText(first)).toBe(pingText(second)); |
| 52 | + expect(JSON.parse(pingText(first))).toEqual(MINER_PING_STATUS); |
| 53 | + }); |
| 54 | +}); |
0 commit comments