Skip to content

Commit 4d28235

Browse files
committed
test(mcp-cli): add binary integration tests
- Add tests for mcp-cli --help, --version, and -c flag - Fix loader to respect HOME env var for testability - Tests skip gracefully if mcp-cli not installed
1 parent 37b6b2f commit 4d28235

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

src/features/mcp-cli-loader/loader.test.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { describe, it, expect, beforeEach, afterEach } from "bun:test"
22
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
33
import { join } from "node:path"
4-
import { tmpdir } from "node:os"
4+
import { tmpdir, homedir } from "node:os"
55
import { loadMcpCliConfigs } from "./loader"
66
import type { McpCliConfig } from "./types"
77

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+
817
describe("mcp_servers.json config loader", () => {
918
let tempDir: string
1019
let originalCwd: string
@@ -165,3 +174,55 @@ describe("mcp_servers.json config loader", () => {
165174
expect(result.loadedServers).toHaveLength(1)
166175
})
167176
})
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+
})

src/features/mcp-cli-loader/loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface McpCliConfigPath {
1616

1717
function getMcpCliConfigPaths(): McpCliConfigPath[] {
1818
const cwd = process.cwd()
19-
const home = homedir()
19+
const home = process.env.HOME || homedir()
2020

2121
return [
2222
{ path: join(home, ".config", "opencode", "mcp_servers.json"), scope: "user" },

0 commit comments

Comments
 (0)