Skip to content

Commit fdd507e

Browse files
committed
test: stabilize Windows path-sensitive tests (normalize fs paths, deterministic roomodes/mcp discovery)
1 parent e6a4b0c commit fdd507e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/core/config/__tests__/CustomModesManager.yamlEdgeCases.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe("CustomModesManager - YAML Edge Cases", () => {
6060
}
6161

6262
beforeEach(() => {
63+
process.env.NODE_ENV = "test"
6364
mockOnUpdate = vi.fn()
6465
mockContext = {
6566
globalState: {
@@ -98,6 +99,10 @@ describe("CustomModesManager - YAML Edge Cases", () => {
9899
}
99100
;(vscode.workspace.createFileSystemWatcher as Mock).mockReturnValue(mockWatcher)
100101

102+
// Force deterministic paths independent of OS path semantics
103+
vi.spyOn(CustomModesManager.prototype as any, "getHierarchicalRoomodes").mockResolvedValue([mockRoomodes])
104+
vi.spyOn(CustomModesManager.prototype as any, "getCustomModesFilePath").mockResolvedValue(mockSettingsPath)
105+
101106
manager = new CustomModesManager(mockContext, mockOnUpdate)
102107
})
103108

src/services/mcp/__tests__/hierarchical-mcp.spec.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ vi.mock("vscode", () => ({
5151
},
5252
}))
5353

54+
// Normalize paths across platforms for test lookups
55+
const normalizePathForTest = (p: string) =>
56+
String(p)
57+
.replace(/^[A-Za-z]:/i, "")
58+
.replace(/\\/g, "/")
59+
5460
describe("Hierarchical project MCP configuration resolution", () => {
5561
const fileMap: Record<string, string> = {}
5662
const workspaceRoot = "/home/user/mono-repo/packages/frontend"
@@ -63,18 +69,18 @@ describe("Hierarchical project MCP configuration resolution", () => {
6369
vi.clearAllMocks()
6470
process.env.NODE_ENV = "test"
6571

66-
// Prepare hierarchical files
67-
fileMap[repoLevel] = JSON.stringify({
72+
// Prepare hierarchical files (store using normalized keys)
73+
fileMap[normalizePathForTest(repoLevel)] = JSON.stringify({
6874
mcpServers: {
6975
alpha: { type: "stdio", command: "node", args: ["repo.js"], disabled: true },
7076
},
7177
})
72-
fileMap[packagesLevel] = JSON.stringify({
78+
fileMap[normalizePathForTest(packagesLevel)] = JSON.stringify({
7379
mcpServers: {
7480
beta: { type: "stdio", command: "node", args: ["pkg.js"], disabled: true },
7581
},
7682
})
77-
fileMap[appLevel] = JSON.stringify({
83+
fileMap[normalizePathForTest(appLevel)] = JSON.stringify({
7884
mcpServers: {
7985
// Override alpha at most specific level
8086
alpha: { type: "stdio", command: "node", args: ["app.js"], disabled: true },
@@ -83,14 +89,14 @@ describe("Hierarchical project MCP configuration resolution", () => {
8389

8490
// Configure fs.promises mocks
8591
;(fs as any).access.mockImplementation(async (p: any) => {
86-
const key = String(p)
92+
const key = normalizePathForTest(String(p))
8793
if (fileMap[key]) return
8894
const err: any = new Error("ENOENT")
8995
err.code = "ENOENT"
9096
throw err
9197
})
9298
;(fs as any).readFile.mockImplementation(async (p: any, _enc?: any) => {
93-
const key = String(p)
99+
const key = normalizePathForTest(String(p))
94100
if (fileMap[key]) return fileMap[key]
95101
// default empty config to avoid syntax errors
96102
return "{}"

0 commit comments

Comments
 (0)