Skip to content

Commit 2f5ebdf

Browse files
committed
fix: make McpHub tests cross-platform compatible
Fixed cross-platform compatibility issues in the McpHub tests that were causing failures on Windows but passing on Linux: 1. Made the toggleToolAlwaysAllow tests more platform-agnostic by: - No longer relying on specific path formats which differ between Windows and Linux - Using the last write call instead of searching for a specific path string - Adding more robust assertions that verify structure instead of exact path matches - Properly handling array existence checks 2. These tests would fail on Windows because paths are formatted with backslashes instead of forward slashes, causing path equality checks to fail. The changes maintain test intent while ensuring cross-platform compatibility.
1 parent 4eb4cbb commit 2f5ebdf

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/services/mcp/__tests__/McpHub.test.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,19 @@ describe("McpHub", () => {
113113
await mcpHub.toggleToolAlwaysAllow("test-server", "new-tool", true)
114114

115115
// Verify the config was updated correctly
116-
// Find the write call with the normalized path
117-
const normalizedSettingsPath = "/mock/settings/path/cline_mcp_settings.json"
118116
const writeCalls = (fs.writeFile as jest.Mock).mock.calls
117+
expect(writeCalls.length).toBeGreaterThan(0)
119118

120-
// Find the write call with the normalized path
121-
const writeCall = writeCalls.find((call) => call[0] === normalizedSettingsPath)
122-
const callToUse = writeCall || writeCalls[0]
119+
// Find the write call
120+
const callToUse = writeCalls[writeCalls.length - 1]
121+
expect(callToUse).toBeTruthy()
123122

123+
// The path might be normalized differently on different platforms,
124+
// so we'll just check that we have a call with valid content
124125
const writtenConfig = JSON.parse(callToUse[1])
126+
expect(writtenConfig.mcpServers).toBeDefined()
127+
expect(writtenConfig.mcpServers["test-server"]).toBeDefined()
128+
expect(Array.isArray(writtenConfig.mcpServers["test-server"].alwaysAllow)).toBe(true)
125129
expect(writtenConfig.mcpServers["test-server"].alwaysAllow).toContain("new-tool")
126130
})
127131

@@ -143,15 +147,19 @@ describe("McpHub", () => {
143147
await mcpHub.toggleToolAlwaysAllow("test-server", "existing-tool", false)
144148

145149
// Verify the config was updated correctly
146-
// Find the write call with the normalized path
147-
const normalizedSettingsPath = "/mock/settings/path/cline_mcp_settings.json"
148150
const writeCalls = (fs.writeFile as jest.Mock).mock.calls
151+
expect(writeCalls.length).toBeGreaterThan(0)
149152

150-
// Find the write call with the normalized path
151-
const writeCall = writeCalls.find((call) => call[0] === normalizedSettingsPath)
152-
const callToUse = writeCall || writeCalls[0]
153+
// Find the write call
154+
const callToUse = writeCalls[writeCalls.length - 1]
155+
expect(callToUse).toBeTruthy()
153156

157+
// The path might be normalized differently on different platforms,
158+
// so we'll just check that we have a call with valid content
154159
const writtenConfig = JSON.parse(callToUse[1])
160+
expect(writtenConfig.mcpServers).toBeDefined()
161+
expect(writtenConfig.mcpServers["test-server"]).toBeDefined()
162+
expect(Array.isArray(writtenConfig.mcpServers["test-server"].alwaysAllow)).toBe(true)
155163
expect(writtenConfig.mcpServers["test-server"].alwaysAllow).not.toContain("existing-tool")
156164
})
157165

0 commit comments

Comments
 (0)