fix(filesystem): fix quote style and add fileURLToPath regression test#3353
fix(filesystem): fix quote style and add fileURLToPath regression test#3353olaservo wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Follow-up to modelcontextprotocol#3205. Fixes import quote style inconsistency (double to single quotes) and adds a regression test using pathToFileURL() to verify properly-encoded file:// URIs are handled correctly on all platforms. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| it('should handle standard file URIs from pathToFileURL', async () => { | ||
| // pathToFileURL produces properly-encoded URIs (e.g. file:///C:/... on Windows) | ||
| // This is the format VS Code and other editors send via MCP roots | ||
| const roots: Root[] = [ | ||
| { uri: pathToFileURL(testDir1).href, name: 'Standard File URI' }, | ||
| { uri: pathToFileURL(testDir2).href, name: 'Standard File URI 2' }, | ||
| ]; | ||
|
|
||
| const result = await getValidRootDirectories(roots); | ||
|
|
||
| expect(result).toContain(testDir1); | ||
| expect(result).toContain(testDir2); | ||
| expect(result).toHaveLength(2); | ||
| }); |
There was a problem hiding this comment.
It appears that the tests pass on non-Windows platforms regardless of the changes in #3205. Since CI also does not seem to run tests on Windows, how about converting this into a regression test that can be reproduced on macOS and other platforms as shown below?
| it('should handle standard file URIs from pathToFileURL', async () => { | |
| // pathToFileURL produces properly-encoded URIs (e.g. file:///C:/... on Windows) | |
| // This is the format VS Code and other editors send via MCP roots | |
| const roots: Root[] = [ | |
| { uri: pathToFileURL(testDir1).href, name: 'Standard File URI' }, | |
| { uri: pathToFileURL(testDir2).href, name: 'Standard File URI 2' }, | |
| ]; | |
| const result = await getValidRootDirectories(roots); | |
| expect(result).toContain(testDir1); | |
| expect(result).toContain(testDir2); | |
| expect(result).toHaveLength(2); | |
| }); | |
| it('should handle standard file URIs from pathToFileURL', async () => { | |
| // pathToFileURL encodes special characters (e.g. spaces become %20, # becomes %23). | |
| // fileURLToPath() decodes them correctly; slice(7) does not. | |
| // e.g. pathToFileURL('/tmp/my dir').href => 'file:///tmp/my%20dir' | |
| // fileURLToPath('file:///tmp/my%20dir') => '/tmp/my dir' (correct) | |
| // 'file:///tmp/my%20dir'.slice(7) => '/tmp/my%20dir' (wrong) | |
| const dirWithSpaces = join(testDir1, 'dir with spaces'); | |
| const dirWithHash = join(testDir1, 'dir#hash'); | |
| mkdirSync(dirWithSpaces); | |
| mkdirSync(dirWithHash); | |
| const roots: Root[] = [ | |
| { uri: pathToFileURL(dirWithSpaces).href }, | |
| { uri: pathToFileURL(dirWithHash).href }, | |
| ]; | |
| const result = await getValidRootDirectories(roots); | |
| expect(result).toContain(dirWithSpaces); | |
| expect(result).toContain(dirWithHash); | |
| expect(result).toHaveLength(2); | |
| }); |
|
@claude review |
|
Claude finished @cliffhall's task in 1m 4s —— View job PR Review
This is a clean, focused PR. Here's my assessment of both changes:
|
| Change | Assessment |
|---|---|
| Quote style fix | ✅ Approve |
| Regression test |
The PR is mergeable as-is (both changes are correct), but incorporating koic's suggestion before merge would meaningfully strengthen the test coverage.
Summary
Follow-up to #3205 with two small improvements:
import { fileURLToPath } from "url"to use single quotes, matching the rest of the filepathToFileURL()to verify properly-encodedfile://URIs (the format VS Code sends via MCP roots) are handled correctly on all platformsTest plan
npx vitest run src/filesystem/__tests__/roots-utils.test.ts— all 4 tests pass (3 existing + 1 new)🦉 Generated with Claude Code