From 743dc97ef4d1276464a261496c4be398fcb4bd54 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Tue, 22 Jul 2025 16:46:30 +0000 Subject: [PATCH] fix: normalize path separators for cross-platform compatibility - Ensure consistent cache keys across Windows and Unix systems - Replace backslashes with forward slashes in relative paths --- src/services/code-index/__tests__/cache-manager.spec.ts | 4 +++- src/services/code-index/cache-manager.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/services/code-index/__tests__/cache-manager.spec.ts b/src/services/code-index/__tests__/cache-manager.spec.ts index bbdab5ff07..a5b34a4e8c 100644 --- a/src/services/code-index/__tests__/cache-manager.spec.ts +++ b/src/services/code-index/__tests__/cache-manager.spec.ts @@ -80,7 +80,9 @@ describe("CacheManager", () => { relativePath = path.relative(homedir, mockWorkspacePath) } - const compositeKey = `${workspaceName}::${relativePath}` + // Normalize path separators for consistency + const normalizedRelativePath = relativePath.replace(/\\/g, "/") + const compositeKey = `${workspaceName}::${normalizedRelativePath}` const expectedHash = createHash("sha256").update(compositeKey).digest("hex") expect(vscode.Uri.joinPath).toHaveBeenCalledWith( diff --git a/src/services/code-index/cache-manager.ts b/src/services/code-index/cache-manager.ts index dc43ea8384..19cb6e835a 100644 --- a/src/services/code-index/cache-manager.ts +++ b/src/services/code-index/cache-manager.ts @@ -56,10 +56,14 @@ export class CacheManager implements ICacheManager { console.warn("Failed to get relative path from home directory:", error) } - // Create a composite key using workspace name and relative path + // Normalize path separators to forward slashes for consistency across platforms + // This ensures the same cache key is generated regardless of the OS + const normalizedRelativePath = relativePath.replace(/\\/g, "/") + + // Create a composite key using workspace name and normalized relative path // This should be more stable across SSH sessions where the absolute path might change // but the relative structure remains the same - const compositeKey = `${workspaceName}::${relativePath}` + const compositeKey = `${workspaceName}::${normalizedRelativePath}` // Generate hash from the composite key return createHash("sha256").update(compositeKey).digest("hex")