|
| 1 | +import { Client } from "@modelcontextprotocol/sdk/client/index.js"; |
| 2 | +import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; |
| 3 | +import { mkdtempSync, rmSync } from "node:fs"; |
| 4 | +import { tmpdir } from "node:os"; |
| 5 | +import { join } from "node:path"; |
| 6 | +import { afterEach, beforeEach, describe, expect, it } from "vitest"; |
| 7 | +import { |
| 8 | + closeFixtureServer, |
| 9 | + run, |
| 10 | + startFixtureServer, |
| 11 | +} from "./support/mcp-cli-harness"; |
| 12 | + |
| 13 | +// #6734: CLI stdio mirror of loopover_get_repo_outcome_patterns — thin GET proxy of the public |
| 14 | +// /v1/repos/:owner/:repo/outcome-patterns route (same ownerRepoShape + apiGet pattern as maintainer_noise). |
| 15 | +const bin = join(process.cwd(), "packages/loopover-mcp/bin/loopover-mcp.js"); |
| 16 | +const FORBIDDEN_PUBLIC_TERMS = |
| 17 | + /wallet\s*[:=]\s*\S+|hotkey\s*[:=]\s*\S+|coldkey\s*[:=]\s*\S+|raw trust score is|your trust score|reward estimate is|estimated reward/i; |
| 18 | + |
| 19 | +let client: Client; |
| 20 | +let transport: StdioClientTransport; |
| 21 | +let configDir: string; |
| 22 | +let apiUrl: string; |
| 23 | +let capturedRequests: Array<{ url: string; method: string }>; |
| 24 | + |
| 25 | +async function connect() { |
| 26 | + configDir = mkdtempSync(join(tmpdir(), "loopover-outcome-patterns-")); |
| 27 | + capturedRequests = []; |
| 28 | + apiUrl = await startFixtureServer({ |
| 29 | + onApiRequest: (request) => { |
| 30 | + if (request.url && request.url.includes("/outcome-patterns")) { |
| 31 | + capturedRequests.push({ |
| 32 | + url: request.url ?? "", |
| 33 | + method: request.method ?? "GET", |
| 34 | + }); |
| 35 | + } |
| 36 | + }, |
| 37 | + }); |
| 38 | + transport = new StdioClientTransport({ |
| 39 | + command: "node", |
| 40 | + args: [bin, "--stdio"], |
| 41 | + env: { |
| 42 | + ...process.env, |
| 43 | + LOOPOVER_CONFIG_DIR: configDir, |
| 44 | + LOOPOVER_API_URL: apiUrl, |
| 45 | + LOOPOVER_TOKEN: "session-token", |
| 46 | + LOOPOVER_API_TIMEOUT_MS: "5000", |
| 47 | + }, |
| 48 | + }); |
| 49 | + client = new Client({ name: "outcome-patterns-test", version: "0.0.1" }); |
| 50 | + await client.connect(transport); |
| 51 | +} |
| 52 | + |
| 53 | +async function disconnect() { |
| 54 | + await client.close().catch(() => undefined); |
| 55 | + await closeFixtureServer(); |
| 56 | + if (configDir) rmSync(configDir, { recursive: true, force: true }); |
| 57 | +} |
| 58 | + |
| 59 | +describe("loopover_get_repo_outcome_patterns stdio proxy (#6734)", () => { |
| 60 | + beforeEach(connect); |
| 61 | + afterEach(disconnect); |
| 62 | + |
| 63 | + it("registers the tool in the stdio server tool list", async () => { |
| 64 | + const { tools } = await client.listTools(); |
| 65 | + expect(tools.map((tool) => tool.name)).toContain( |
| 66 | + "loopover_get_repo_outcome_patterns", |
| 67 | + ); |
| 68 | + }); |
| 69 | + |
| 70 | + it("proxies the call to /outcome-patterns via apiGet and returns the payload", async () => { |
| 71 | + const result = await client.callTool({ |
| 72 | + name: "loopover_get_repo_outcome_patterns", |
| 73 | + arguments: { owner: "owner", repo: "repo" }, |
| 74 | + }); |
| 75 | + expect(capturedRequests.length).toBe(1); |
| 76 | + const captured = capturedRequests[0]!; |
| 77 | + expect(captured.url).toContain("/v1/repos/owner/repo/outcome-patterns"); |
| 78 | + expect(captured.method).toBe("GET"); |
| 79 | + expect(result.isError).toBeFalsy(); |
| 80 | + const text = JSON.stringify(result); |
| 81 | + expect(text).not.toMatch(FORBIDDEN_PUBLIC_TERMS); |
| 82 | + expect(text).toContain("owner/repo"); |
| 83 | + expect(text).toContain("patterns"); |
| 84 | + expect(text).toContain("fresh"); |
| 85 | + }); |
| 86 | + |
| 87 | + it("lists the tool via loopover-mcp tools", () => { |
| 88 | + const payload = JSON.parse(run(["tools", "--json"])) as { |
| 89 | + tools: Array<{ name: string; description: string }>; |
| 90 | + }; |
| 91 | + const tool = payload.tools.find( |
| 92 | + (entry) => entry.name === "loopover_get_repo_outcome_patterns", |
| 93 | + ); |
| 94 | + expect(tool?.description).toMatch(/outcome patterns/i); |
| 95 | + expect(tool?.description.trim().length).toBeGreaterThan(0); |
| 96 | + }); |
| 97 | +}); |
0 commit comments