fix(mcp): normalize path separators in LSP/ast-grep cli candidate detection (fixes #4151)
On Windows, path.resolve() returns paths with backslash separators. The previous endsWith("dist/cli.js") check uses forward slashes and always returned false on Windows, causing both LSP and ast-grep MCPs to fall through to the bootstrap path even when the dist cli exists. Result: LSP MCP completely unusable on Windows with MODULE_NOT_FOUND for dist/packages/lsp-tools-mcp/dist/cli.js.
Fix: derive a platform-aware suffix at module load time by replacing forward slashes in DIST_CLI_REL / SOURCE_CLI_REL with path.sep, then use that suffix in the endsWith check.
Verification: all 4 src/mcp/lsp.test.ts cases pass on Windows (previously 2 failed); all 13 src/mcp/ast-grep.test.ts cases pass (previously 2 failed). Total: 17/17 src/mcp tests green. bun run typecheck clean.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from "bun:test"
|
||||
import { hasCliSuffix } from "./cli-suffix"
|
||||
|
||||
describe("hasCliSuffix", () => {
|
||||
it("matches cli suffixes across platform separators", () => {
|
||||
// given
|
||||
const suffix = "packages/lsp-tools-mcp/dist/cli.js"
|
||||
const candidatePaths = [
|
||||
"/home/user/project/packages/lsp-tools-mcp/dist/cli.js",
|
||||
"C:\\Users\\yeongyu\\project\\packages\\lsp-tools-mcp\\dist\\cli.js",
|
||||
"\\\\server\\share\\project\\packages\\lsp-tools-mcp\\dist\\cli.js",
|
||||
"C:/Users/yeongyu/project\\packages/lsp-tools-mcp\\dist/cli.js",
|
||||
]
|
||||
|
||||
// when
|
||||
const results = candidatePaths.map((candidatePath) => hasCliSuffix(candidatePath, suffix))
|
||||
|
||||
// then
|
||||
expect(results).toEqual([true, true, true, true])
|
||||
})
|
||||
|
||||
it("does not match unrelated cli suffixes", () => {
|
||||
// given
|
||||
const candidatePath = "C:\\Users\\yeongyu\\project\\packages\\other-mcp\\dist\\cli.js"
|
||||
|
||||
// when
|
||||
const result = hasCliSuffix(candidatePath, "packages/lsp-tools-mcp/dist/cli.js")
|
||||
|
||||
// then
|
||||
expect(result).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user