From 02bf87b0b040801d0bdef3f61389fa0dc094bcf3 Mon Sep 17 00:00:00 2001 From: iliya Date: Sun, 1 Mar 2026 13:12:08 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Windows=20test=20compatibility=20?= =?UTF-8?q?=E2=80=94=20path.resolve=20in=20atomicWrite=20and=20pathValidat?= =?UTF-8?q?ion=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/main/utils/atomicWrite.test.ts | 5 +++-- test/main/utils/pathValidation.test.ts | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/test/main/utils/atomicWrite.test.ts b/test/main/utils/atomicWrite.test.ts index f4a6ffef..14137c1a 100644 --- a/test/main/utils/atomicWrite.test.ts +++ b/test/main/utils/atomicWrite.test.ts @@ -30,7 +30,7 @@ const mockRename = vi.mocked(fs.promises.rename); const mockCopyFile = vi.mocked(fs.promises.copyFile); const mockUnlink = vi.mocked(fs.promises.unlink); -const TARGET_PATH = '/Users/test/project/src/index.ts'; +const TARGET_PATH = path.resolve('/Users/test/project/src/index.ts'); const TARGET_DIR = path.dirname(TARGET_PATH); const CONTENT = 'export const hello = "world";'; @@ -65,7 +65,8 @@ describe('atomicWriteAsync', () => { // writeFile should be called with a tmp path in the same directory expect(mockWriteFile).toHaveBeenCalledTimes(1); const tmpPath = getTmpPath(); - expect(tmpPath).toMatch(new RegExp(`^${TARGET_DIR}/\\.tmp\\.[a-f0-9-]+$`)); + const escapedDir = TARGET_DIR.replace(/[\\]/g, '\\\\'); + expect(tmpPath).toMatch(new RegExp(`^${escapedDir}[/\\\\]\\.tmp\\.[a-f0-9-]+$`)); // rename from tmp to target expect(mockRename).toHaveBeenCalledWith(tmpPath, TARGET_PATH); diff --git a/test/main/utils/pathValidation.test.ts b/test/main/utils/pathValidation.test.ts index 1423b086..dcaf8e47 100644 --- a/test/main/utils/pathValidation.test.ts +++ b/test/main/utils/pathValidation.test.ts @@ -223,14 +223,18 @@ describe('pathValidation', () => { it('should expand ~ to home directory for paths within ~/.claude', () => { const result = validateFilePath('~/.claude/projects/test.jsonl', null); expect(result.valid).toBe(true); - expect(result.normalizedPath).toBe(path.join(homeDir, '.claude', 'projects', 'test.jsonl')); + expect(result.normalizedPath).toBe( + path.resolve(path.join(homeDir, '.claude', 'projects', 'test.jsonl')) + ); }); it('should expand ~ to home directory for project paths', () => { const projectInHome = path.join(homeDir, 'my-project'); const result = validateFilePath('~/my-project/src/index.ts', projectInHome); expect(result.valid).toBe(true); - expect(result.normalizedPath).toBe(path.join(projectInHome, 'src', 'index.ts')); + expect(result.normalizedPath).toBe( + path.resolve(path.join(projectInHome, 'src', 'index.ts')) + ); }); it('should reject tilde paths to sensitive files', () => { @@ -250,7 +254,7 @@ describe('pathValidation', () => { it('should expand tilde in paths', () => { const result = validateOpenPath('~/.claude', null); expect(result.valid).toBe(true); - expect(result.normalizedPath).toBe(path.normalize(claudeDir)); + expect(result.normalizedPath).toBe(path.resolve(claudeDir)); }); it('should reject sensitive files', () => {