diff --git a/src/tests/mcp-server.test.ts b/src/tests/mcp-server.test.ts index 9e4f5cb8a..9581809dd 100644 --- a/src/tests/mcp-server.test.ts +++ b/src/tests/mcp-server.test.ts @@ -1,30 +1,37 @@ import test from 'node:test' import assert from 'node:assert/strict' import { join } from 'node:path' -import { fileURLToPath } from 'node:url' +import { fileURLToPath, pathToFileURL } from 'node:url' const projectRoot = join(fileURLToPath(import.meta.url), '..', '..', '..') +/** + * Resolve dist path as a file:// URL for cross-platform dynamic import. + * On Windows, bare paths like `D:\...\mcp-server.js` fail with + * ERR_UNSUPPORTED_ESM_URL_SCHEME because Node's ESM loader requires + * file:// URLs for absolute paths. + */ +function distUrl(filename: string): string { + return pathToFileURL(join(projectRoot, 'dist', filename)).href +} + test('mcp-server module imports without errors', async () => { // Import from the compiled dist output to avoid subpath resolution issues // that occur when the resolve-ts test hook rewrites .js -> .ts paths. - const distPath = join(projectRoot, 'dist', 'mcp-server.js') - const mod = await import(distPath) + const mod = await import(distUrl('mcp-server.js')) assert.ok(mod, 'module should be importable') assert.strictEqual(typeof mod.startMcpServer, 'function', 'startMcpServer should be a function') }) test('startMcpServer accepts the correct argument shape', async () => { - const distPath = join(projectRoot, 'dist', 'mcp-server.js') - const { startMcpServer } = await import(distPath) + const { startMcpServer } = await import(distUrl('mcp-server.js')) assert.strictEqual(typeof startMcpServer, 'function') assert.strictEqual(startMcpServer.length, 1, 'startMcpServer should accept one argument') }) test('startMcpServer can be called with mock tools', async () => { - const distPath = join(projectRoot, 'dist', 'mcp-server.js') - const { startMcpServer } = await import(distPath) + const { startMcpServer } = await import(distUrl('mcp-server.js')) // Create a mock tool matching the McpToolDef interface const mockTool = {