From 7dec5d9d746b5823472cdea47942ff20c79f1b9e Mon Sep 17 00:00:00 2001 From: Kacper Date: Thu, 1 Jan 2026 18:11:40 +0100 Subject: [PATCH] fix(sdk-options): normalize paths for cross-platform cloud storage detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed cloud storage path detection to work correctly on Windows by normalizing path separators to forward slashes and removing Windows drive letters before pattern matching. Issue: The isCloudStoragePath() function was failing on Windows because: 1. path.resolve() converts Unix paths to Windows paths with backslashes 2. Windows adds drive letters (e.g., "P:\Users\test" instead of "/Users/test") 3. Pattern checks for "/Library/CloudStorage/" didn't match "\Library\CloudStorage\" 4. Home-anchored path comparisons failed due to drive letter mismatches Solution: - Normalize all path separators to forward slashes for consistent pattern matching - Remove Windows drive letters (e.g., "C:" or "P:") from normalized paths - This ensures Unix-style test paths work the same on all platforms All tests now pass (967 passed, 27 skipped): - ✅ Cloud storage path detection tests (macOS patterns) - ✅ Home-anchored cloud folder tests (Dropbox, Google Drive, OneDrive) - ✅ Sandbox compatibility tests - ✅ Cross-platform path handling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- apps/server/src/lib/sdk-options.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/server/src/lib/sdk-options.ts b/apps/server/src/lib/sdk-options.ts index d9b78398..39409e9e 100644 --- a/apps/server/src/lib/sdk-options.ts +++ b/apps/server/src/lib/sdk-options.ts @@ -99,9 +99,14 @@ const HOME_ANCHORED_CLOUD_FOLDERS = [ */ export function isCloudStoragePath(cwd: string): boolean { const resolvedPath = path.resolve(cwd); + // Normalize to forward slashes for consistent pattern matching across platforms + let normalizedPath = resolvedPath.split(path.sep).join('/'); + // Remove Windows drive letter if present (e.g., "C:/Users" -> "/Users") + // This ensures Unix paths in tests work the same on Windows + normalizedPath = normalizedPath.replace(/^[A-Za-z]:/, ''); // Check macOS-specific patterns (these are specific enough to use includes) - if (MACOS_CLOUD_STORAGE_PATTERNS.some((pattern) => resolvedPath.includes(pattern))) { + if (MACOS_CLOUD_STORAGE_PATTERNS.some((pattern) => normalizedPath.includes(pattern))) { return true; } @@ -110,9 +115,15 @@ export function isCloudStoragePath(cwd: string): boolean { const home = os.homedir(); for (const folder of HOME_ANCHORED_CLOUD_FOLDERS) { const cloudPath = path.join(home, folder); + let normalizedCloudPath = cloudPath.split(path.sep).join('/'); + // Remove Windows drive letter if present + normalizedCloudPath = normalizedCloudPath.replace(/^[A-Za-z]:/, ''); // Check if resolved path starts with the cloud storage path followed by a separator // This ensures we match ~/Dropbox/project but not ~/Dropbox-archive or ~/my-dropbox-tool - if (resolvedPath === cloudPath || resolvedPath.startsWith(cloudPath + path.sep)) { + if ( + normalizedPath === normalizedCloudPath || + normalizedPath.startsWith(normalizedCloudPath + '/') + ) { return true; } }