diff --git a/packages/cli/src/ui/components/shared/text-buffer.test.ts b/packages/cli/src/ui/components/shared/text-buffer.test.ts index 85754f9f62..43f9e53700 100644 --- a/packages/cli/src/ui/components/shared/text-buffer.test.ts +++ b/packages/cli/src/ui/components/shared/text-buffer.test.ts @@ -1023,7 +1023,7 @@ describe('useTextBuffer', () => { useTextBuffer({ viewport, escapePastedPaths: true }), ); act(() => result.current.insert(filePath, { paste: true })); - expect(getBufferState(result).text).toBe(`@${filePath} `); + expect(getBufferState(result).text).toBe(`@${escapePath(filePath)} `); }); it('should not prepend @ to an invalid file path on insert', () => { @@ -1042,7 +1042,7 @@ describe('useTextBuffer', () => { ); const quotedPath = `'${filePath}'`; act(() => result.current.insert(quotedPath, { paste: true })); - expect(getBufferState(result).text).toBe(`@${filePath} `); + expect(getBufferState(result).text).toBe(`@${escapePath(filePath)} `); }); it('should not prepend @ to short text that is not a path', () => { @@ -1065,7 +1065,9 @@ describe('useTextBuffer', () => { ); const filePaths = `${file1} ${file2}`; act(() => result.current.insert(filePaths, { paste: true })); - expect(getBufferState(result).text).toBe(`@${file1} @${file2} `); + expect(getBufferState(result).text).toBe( + `@${escapePath(file1)} @${escapePath(file2)} `, + ); }); it('should handle multiple paths with escaped spaces', () => { @@ -1083,7 +1085,7 @@ describe('useTextBuffer', () => { act(() => result.current.insert(filePaths, { paste: true })); expect(getBufferState(result).text).toBe( - `@${escapePath(file1)} @${file2} `, + `@${escapePath(file1)} @${escapePath(file2)} `, ); }); diff --git a/packages/cli/src/ui/hooks/atCommandProcessor.test.ts b/packages/cli/src/ui/hooks/atCommandProcessor.test.ts index 76848ea821..9e925364c2 100644 --- a/packages/cli/src/ui/hooks/atCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/atCommandProcessor.test.ts @@ -285,6 +285,16 @@ describe('handleAtCommand', () => { }); it('should correctly unescape paths with escaped spaces', async () => { + // Mock platform to linux so unescapePath handles backslash escapes + vi.stubGlobal( + 'process', + Object.create(process, { + platform: { + get: () => 'linux', + }, + }), + ); + const fileContent = 'This is the file content.'; const filePath = await createTestFile( path.join(testRootDir, 'path', 'to', 'my file.txt'), @@ -955,6 +965,16 @@ describe('handleAtCommand', () => { }); it('should still handle escaped spaces in paths before punctuation', async () => { + // Mock platform to linux so unescapePath handles backslash escapes + vi.stubGlobal( + 'process', + Object.create(process, { + platform: { + get: () => 'linux', + }, + }), + ); + const fileContent = 'Spaced file content'; const filePath = await createTestFile( path.join(testRootDir, 'spaced file.txt'), diff --git a/packages/cli/src/ui/hooks/useAtCompletion.test.ts b/packages/cli/src/ui/hooks/useAtCompletion.test.ts index 7c41b7593d..518a27d30b 100644 --- a/packages/cli/src/ui/hooks/useAtCompletion.test.ts +++ b/packages/cli/src/ui/hooks/useAtCompletion.test.ts @@ -13,6 +13,7 @@ import type { Config, FileSearch } from '@google/gemini-cli-core'; import { FileSearchFactory, FileDiscoveryService, + escapePath, } from '@google/gemini-cli-core'; import type { FileSystemStructure } from '@google/gemini-cli-test-utils'; import { createTmpDir, cleanupTmpDir } from '@google/gemini-cli-test-utils'; @@ -64,6 +65,7 @@ describe('useAtCompletion', () => { await cleanupTmpDir(testRootDir); } vi.restoreAllMocks(); + vi.unstubAllGlobals(); }); describe('File Search Logic', () => { @@ -90,7 +92,7 @@ describe('useAtCompletion', () => { 'src/', 'src/components/', 'file.txt', - 'src/components/Button\\ with\\ spaces.tsx', + escapePath('src/components/Button with spaces.tsx'), 'src/components/Button.tsx', 'src/index.js', ]);