From 90a0c8f0196e5c5dcd1026ead0daa8418c719428 Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Sat, 4 Apr 2026 01:09:24 +0800 Subject: [PATCH] test(filesystem): add regression tests for Docker Linux path handling Add tests for issue #3628 where single-letter root directories (/h/, /u/, /d/) on Linux Docker containers were incorrectly converted to Windows drive letter paths (H:\, U:\, D:\). The code fix exists on main via platform detection in normalizePath and convertToWindowsPath. These tests mock process.platform to 'linux' and verify paths are preserved as-is. Signed-off-by: majiayu000 <1835304752@qq.com> --- src/filesystem/__tests__/path-utils.test.ts | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/filesystem/__tests__/path-utils.test.ts b/src/filesystem/__tests__/path-utils.test.ts index 3f6072377b..e8abf5ca58 100644 --- a/src/filesystem/__tests__/path-utils.test.ts +++ b/src/filesystem/__tests__/path-utils.test.ts @@ -379,4 +379,62 @@ describe('Path Utilities', () => { } }); }); + + describe('Linux Docker path handling (issue #3628 fix)', () => { + const originalPlatform = process.platform; + + afterEach(() => { + Object.defineProperty(process, 'platform', { + value: originalPlatform, + writable: true, + configurable: true + }); + }); + + it('reproduces exact scenario from issue #3628', () => { + // Docker Alpine Linux container where /h/username/MCP_Development/data + // was incorrectly converted to H:\username\MCP_Development\data + Object.defineProperty(process, 'platform', { + value: 'linux', + writable: true, + configurable: true + }); + + const inputPath = '/h/username/MCP_Development/data'; + const result = normalizePath(inputPath); + + expect(result).toBe('/h/username/MCP_Development/data'); + expect(result).not.toContain('H:'); + expect(result).not.toContain('\\'); + }); + + it('preserves single-letter root directories on Linux', () => { + Object.defineProperty(process, 'platform', { + value: 'linux', + writable: true, + configurable: true + }); + + // These look like drive letters but are valid Linux directories + expect(normalizePath('/u/local/share')).toBe('/u/local/share'); + expect(normalizePath('/d/projects/app')).toBe('/d/projects/app'); + expect(normalizePath('/s/data/files')).toBe('/s/data/files'); + expect(normalizePath('/e/backups/daily')).toBe('/e/backups/daily'); + }); + + it('convertToWindowsPath leaves single-letter root paths unchanged on Linux', () => { + Object.defineProperty(process, 'platform', { + value: 'linux', + writable: true, + configurable: true + }); + + expect(convertToWindowsPath('/h/username/MCP_Development/data')) + .toBe('/h/username/MCP_Development/data'); + expect(convertToWindowsPath('/c/some/path')) + .toBe('/c/some/path'); + expect(convertToWindowsPath('/d/projects/app')) + .toBe('/d/projects/app'); + }); + }); });