|
1 | 1 | import { mkdtemp, rm } from "node:fs/promises"; |
2 | 2 | import { tmpdir } from "node:os"; |
3 | 3 | import { join } from "node:path"; |
4 | | -import { fileURLToPath } from "node:url"; |
5 | | -import { test } from "bun:test"; |
| 4 | +import { test, expect } from "bun:test"; |
6 | 5 | import { |
| 6 | + openMcpTestClientInMemory, |
7 | 7 | callMcpListProjects, |
8 | | - openMcpTestClient, |
9 | 8 | verifyMcpToolsAndResources, |
10 | 9 | } from "../src/mcp/test-utils.ts"; |
11 | 10 |
|
12 | | -const cliRoot = fileURLToPath(new URL("../", import.meta.url)); |
13 | | - |
14 | | -// TODO: Fix flaky test - MCP SDK has race condition in StdioClientTransport |
15 | | -// See: https://github.com/modelcontextprotocol/typescript-sdk/issues/1049 |
16 | | -test.skip("jack mcp serve exposes tools without deploying", async () => { |
| 11 | +test("MCP server exposes tools and resources", async () => { |
17 | 12 | const projectDir = await mkdtemp(join(tmpdir(), "jack-mcp-test-")); |
18 | | - const configDir = await mkdtemp(join(tmpdir(), "jack-config-")); |
19 | | - const clientEnv = { |
20 | | - ...process.env, |
21 | | - CI: "1", |
22 | | - JACK_TELEMETRY_DISABLED: "1", |
23 | | - JACK_CONFIG_DIR: configDir, |
24 | | - }; |
25 | | - |
26 | | - let client: Awaited<ReturnType<typeof openMcpTestClient>> | null = null; |
| 13 | + |
| 14 | + let client: Awaited<ReturnType<typeof openMcpTestClientInMemory>> | null = null; |
27 | 15 | try { |
28 | | - client = await openMcpTestClient({ |
29 | | - command: "bun", |
30 | | - args: ["run", "src/index.ts", "mcp", "serve", "--project", projectDir], |
31 | | - cwd: cliRoot, |
32 | | - env: clientEnv, |
33 | | - }); |
| 16 | + // Use in-memory transport - no process spawning, no race conditions |
| 17 | + client = await openMcpTestClientInMemory({ projectPath: projectDir }); |
34 | 18 |
|
| 19 | + // Verify tools and resources are exposed |
35 | 20 | await verifyMcpToolsAndResources(client.client); |
| 21 | + |
| 22 | + // Test list_projects tool |
36 | 23 | const projects = await callMcpListProjects(client.client, "local"); |
37 | | - if (!Array.isArray(projects)) { |
38 | | - throw new Error("list_projects returned unexpected data"); |
39 | | - } |
40 | | - } catch (err) { |
41 | | - // Log stderr to help debug CI failures |
42 | | - const stderr = client?.getStderr() ?? "(no client)"; |
43 | | - console.error("MCP test failed. Server stderr:", stderr); |
44 | | - throw err; |
| 24 | + expect(Array.isArray(projects)).toBe(true); |
45 | 25 | } finally { |
46 | 26 | await client?.close(); |
47 | 27 | await rm(projectDir, { recursive: true, force: true }); |
48 | | - await rm(configDir, { recursive: true, force: true }); |
| 28 | + } |
| 29 | +}); |
| 30 | + |
| 31 | +test("MCP server has expected tools", async () => { |
| 32 | + const client = await openMcpTestClientInMemory(); |
| 33 | + |
| 34 | + try { |
| 35 | + const tools = await client.client.listTools(); |
| 36 | + const toolNames = tools.tools?.map((t) => t.name) ?? []; |
| 37 | + |
| 38 | + // Core tools should always be present |
| 39 | + expect(toolNames).toContain("create_project"); |
| 40 | + expect(toolNames).toContain("deploy_project"); |
| 41 | + expect(toolNames).toContain("get_project_status"); |
| 42 | + expect(toolNames).toContain("list_projects"); |
| 43 | + expect(toolNames).toContain("execute_sql"); |
| 44 | + } finally { |
| 45 | + await client.close(); |
| 46 | + } |
| 47 | +}); |
| 48 | + |
| 49 | +test("MCP server has expected resources", async () => { |
| 50 | + const client = await openMcpTestClientInMemory(); |
| 51 | + |
| 52 | + try { |
| 53 | + const resources = await client.client.listResources(); |
| 54 | + const resourceUris = resources.resources?.map((r) => r.uri) ?? []; |
| 55 | + |
| 56 | + expect(resourceUris).toContain("agents://context"); |
| 57 | + expect(resourceUris).toContain("jack://capabilities"); |
| 58 | + } finally { |
| 59 | + await client.close(); |
49 | 60 | } |
50 | 61 | }); |
0 commit comments