From ccaf61e09b30282d2de6939a340d22d9ed518c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=86=A0=E8=BE=B0?= Date: Fri, 22 May 2026 14:19:57 +0800 Subject: [PATCH] test(ast-grep): lock Windows backslash matching for ast_grep dist cli suffix (#4220) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dist-side bug reported in #4220 (`path.endsWith(\"dist/cli.js\")` failing on Windows backslash paths) has already been fixed in source by routing through `hasCliSuffix` in `src/mcp/ast-grep.ts` and `src/mcp/lsp.ts`. The `cli-suffix.test.ts` covered the lsp-tools-mcp shape but not the ast_grep shape. Adds a regression case that asserts a Windows-style absolute path containing `...\\packages\\ast-grep-mcp\\dist\\cli.js` matches both `\"dist/cli.js\"` and the fully-qualified `\"packages/ast-grep-mcp/dist/cli.js\"` suffix — closing the exact symptom from the bug report against future regressions. --- src/mcp/cli-suffix.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/mcp/cli-suffix.test.ts b/src/mcp/cli-suffix.test.ts index f0435d430..9e8d60ab6 100644 --- a/src/mcp/cli-suffix.test.ts +++ b/src/mcp/cli-suffix.test.ts @@ -29,4 +29,21 @@ describe("hasCliSuffix", () => { // then expect(result).toBe(false) }) + + // regression: issue #4220 — ast_grep MCP failed on Windows because the older + // dist used `path.endsWith("dist/cli.js")`. `hasCliSuffix` must match Windows + // backslash paths against the POSIX-shaped `dist/cli.js` suffix. + it("matches the ast_grep dist cli suffix on Windows path separators", () => { + // given + const windowsPath = "C:\\Users\\test\\AppData\\Local\\cache\\oh-my-opencode\\dist\\packages\\ast-grep-mcp\\dist\\cli.js" + + // when: matched against just the trailing `dist/cli.js` segment + const matchesShortSuffix = hasCliSuffix(windowsPath, "dist/cli.js") + // and the fully-qualified package suffix + const matchesPackageSuffix = hasCliSuffix(windowsPath, "packages/ast-grep-mcp/dist/cli.js") + + // then: both must succeed despite the backslashes + expect(matchesShortSuffix).toBe(true) + expect(matchesPackageSuffix).toBe(true) + }) })