|
| 1 | +import path from "node:path" |
1 | 2 | import { expect, mock, beforeEach } from "bun:test" |
2 | 3 | import { ToolListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js" |
3 | 4 | import { Cause, Effect, Exit } from "effect" |
4 | 5 | import type { MCP as MCPNS } from "../../src/mcp/index" |
5 | 6 | import { testEffect } from "../lib/effect" |
| 7 | +import { TestInstance } from "../fixture/fixture" |
6 | 8 |
|
7 | 9 | // --- Mock infrastructure --- |
8 | 10 |
|
@@ -48,6 +50,8 @@ let connectError = "Mock transport cannot connect" |
48 | 50 | let clientCreateCount = 0 |
49 | 51 | // Tracks how many times transport.close() is called across all mock transports |
50 | 52 | let transportCloseCount = 0 |
| 53 | +// Captures the opts passed to each MockStdioTransport, keyed by lastCreatedClientName |
| 54 | +const stdioOptsByName = new Map<string, any>() |
51 | 55 |
|
52 | 56 | function getOrCreateClientState(name?: string): MockClientState { |
53 | 57 | const key = name ?? "default" |
@@ -82,8 +86,9 @@ function getOrCreateClientState(name?: string): MockClientState { |
82 | 86 | class MockStdioTransport { |
83 | 87 | stderr: null = null |
84 | 88 | pid = 12345 |
85 | | - // oxlint-disable-next-line no-useless-constructor |
86 | | - constructor(_opts: any) {} |
| 89 | + constructor(opts: any) { |
| 90 | + if (lastCreatedClientName) stdioOptsByName.set(lastCreatedClientName, opts) |
| 91 | + } |
87 | 92 | async start() { |
88 | 93 | if (connectShouldHang) return new Promise<void>(() => {}) // never resolves |
89 | 94 | if (connectShouldFail) throw new Error(connectError) |
@@ -246,6 +251,20 @@ function statusName(status: Record<string, MCPNS.Status> | MCPNS.Status, server: |
246 | 251 | return status[server]?.status |
247 | 252 | } |
248 | 253 |
|
| 254 | +it.instance( |
| 255 | + "local mcp cwd resolves relative paths against instance directory", |
| 256 | + () => |
| 257 | + MCP.Service.use((mcp: MCPNS.Interface) => |
| 258 | + Effect.gen(function* () { |
| 259 | + const { directory } = yield* TestInstance |
| 260 | + lastCreatedClientName = "rel-cwd" |
| 261 | + yield* mcp.add("rel-cwd", { type: "local", command: ["echo", "test"], cwd: "plugins/sub" }) |
| 262 | + expect(stdioOptsByName.get("rel-cwd")?.cwd).toBe(path.resolve(directory, "plugins/sub")) |
| 263 | + }), |
| 264 | + ), |
| 265 | + { config: { mcp: {} } }, |
| 266 | +) |
| 267 | + |
249 | 268 | // ======================================================================== |
250 | 269 | // Test: tools() are cached after connect |
251 | 270 | // ======================================================================== |
|
0 commit comments