fix windows escaping (and broken tests) (#19011)

This commit is contained in:
Tommaso Sciortino
2026-02-13 14:19:08 -08:00
committed by GitHub
parent c7237f0c79
commit e7e4c68c5c
4 changed files with 16 additions and 14 deletions

View File

@@ -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', () => {
@@ -1063,9 +1063,11 @@ describe('useTextBuffer', () => {
const { result } = renderHook(() =>
useTextBuffer({ viewport, escapePastedPaths: true }),
);
const filePaths = `${file1} ${file2}`;
const filePaths = `${escapePath(file1)} ${escapePath(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', () => {
@@ -1077,13 +1079,12 @@ describe('useTextBuffer', () => {
const { result } = renderHook(() =>
useTextBuffer({ viewport, escapePastedPaths: true }),
);
// Construct escaped path string: "/path/to/my\ file.txt /path/to/other.txt"
const filePaths = `${escapePath(file1)} ${file2}`;
const filePaths = `${escapePath(file1)} ${escapePath(file2)}`;
act(() => result.current.insert(filePaths, { paste: true }));
expect(getBufferState(result).text).toBe(
`@${escapePath(file1)} @${file2} `,
`@${escapePath(file1)} @${escapePath(file2)} `,
);
});

View File

@@ -290,8 +290,8 @@ describe('handleAtCommand', () => {
path.join(testRootDir, 'path', 'to', 'my file.txt'),
fileContent,
);
const escapedpath = path.join(testRootDir, 'path', 'to', 'my\\ file.txt');
const query = `@${escapedpath}`;
const query = `@${core.escapePath(filePath)}`;
const result = await handleAtCommand({
query,
@@ -960,8 +960,8 @@ describe('handleAtCommand', () => {
path.join(testRootDir, 'spaced file.txt'),
fileContent,
);
const escapedPath = path.join(testRootDir, 'spaced\\ file.txt');
const query = `Check @${escapedPath}, it has spaces.`;
const query = `Check @${core.escapePath(filePath)}, it has spaces.`;
const result = await handleAtCommand({
query,

View File

@@ -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';
@@ -90,7 +91,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',
]);