|
1 | 1 | import { describe, it, expect, beforeEach, afterEach } from "bun:test" |
2 | 2 | import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs" |
3 | 3 | import { join } from "node:path" |
4 | | -import { tmpdir } from "node:os" |
| 4 | +import { tmpdir, homedir } from "node:os" |
5 | 5 | import { loadMcpCliConfigs } from "./loader" |
6 | 6 | import type { McpCliConfig } from "./types" |
7 | 7 |
|
| 8 | +function isMcpCliInstalled(): boolean { |
| 9 | + try { |
| 10 | + const result = Bun.spawnSync(["which", "mcp-cli"]) |
| 11 | + return result.exitCode === 0 |
| 12 | + } catch { |
| 13 | + return false |
| 14 | + } |
| 15 | +} |
| 16 | + |
8 | 17 | describe("mcp_servers.json config loader", () => { |
9 | 18 | let tempDir: string |
10 | 19 | let originalCwd: string |
@@ -165,3 +174,55 @@ describe("mcp_servers.json config loader", () => { |
165 | 174 | expect(result.loadedServers).toHaveLength(1) |
166 | 175 | }) |
167 | 176 | }) |
| 177 | + |
| 178 | +describe("mcp-cli binary integration", () => { |
| 179 | + const MCP_CLI_INSTALLED = isMcpCliInstalled() |
| 180 | + |
| 181 | + it.skipIf(!MCP_CLI_INSTALLED)("should show help with --help flag", async () => { |
| 182 | + // #given - mcp-cli is installed |
| 183 | + |
| 184 | + // #when - run mcp-cli --help |
| 185 | + const proc = Bun.spawn(["mcp-cli", "--help"], { |
| 186 | + stdout: "pipe", |
| 187 | + stderr: "pipe", |
| 188 | + }) |
| 189 | + const stdout = await new Response(proc.stdout).text() |
| 190 | + const exitCode = await proc.exited |
| 191 | + |
| 192 | + // #then - should show usage info |
| 193 | + expect(exitCode).toBe(0) |
| 194 | + expect(stdout).toContain("mcp-cli") |
| 195 | + }) |
| 196 | + |
| 197 | + it.skipIf(!MCP_CLI_INSTALLED)("should show version with --version flag", async () => { |
| 198 | + // #given - mcp-cli is installed |
| 199 | + |
| 200 | + // #when - run mcp-cli --version |
| 201 | + const proc = Bun.spawn(["mcp-cli", "--version"], { |
| 202 | + stdout: "pipe", |
| 203 | + stderr: "pipe", |
| 204 | + }) |
| 205 | + const stdout = await new Response(proc.stdout).text() |
| 206 | + const exitCode = await proc.exited |
| 207 | + |
| 208 | + // #then - should show version |
| 209 | + expect(exitCode).toBe(0) |
| 210 | + expect(stdout).toMatch(/\d+\.\d+\.\d+/) |
| 211 | + }) |
| 212 | + |
| 213 | + it.skipIf(!MCP_CLI_INSTALLED)("should accept -c flag for config path", async () => { |
| 214 | + // #given - a non-existent config path |
| 215 | + const fakePath = "/tmp/nonexistent-mcp-config.json" |
| 216 | + |
| 217 | + // #when - run mcp-cli with -c flag (will error but shows flag is recognized) |
| 218 | + const proc = Bun.spawn(["mcp-cli", "-c", fakePath], { |
| 219 | + stdout: "pipe", |
| 220 | + stderr: "pipe", |
| 221 | + }) |
| 222 | + const stderr = await new Response(proc.stderr).text() |
| 223 | + await proc.exited |
| 224 | + |
| 225 | + // #then - should mention config file in error |
| 226 | + expect(stderr).toContain("Config") |
| 227 | + }) |
| 228 | +}) |
0 commit comments