summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useCompletion.integration.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/ui/hooks/useCompletion.integration.test.ts')
-rw-r--r--packages/cli/src/ui/hooks/useCompletion.integration.test.ts95
1 files changed, 65 insertions, 30 deletions
diff --git a/packages/cli/src/ui/hooks/useCompletion.integration.test.ts b/packages/cli/src/ui/hooks/useCompletion.integration.test.ts
index 37075e3c..f6f0944b 100644
--- a/packages/cli/src/ui/hooks/useCompletion.integration.test.ts
+++ b/packages/cli/src/ui/hooks/useCompletion.integration.test.ts
@@ -14,7 +14,10 @@ import { CommandContext, SlashCommand } from '../commands/types.js';
import { Config, FileDiscoveryService } from '@google/gemini-cli-core';
interface MockConfig {
- getFileFilteringRespectGitIgnore: () => boolean;
+ getFileFilteringOptions: () => {
+ respectGitIgnore: boolean;
+ respectGeminiIgnore: boolean;
+ };
getEnableRecursiveFileSearch: () => boolean;
getFileService: () => FileDiscoveryService | null;
}
@@ -118,12 +121,16 @@ describe('useCompletion git-aware filtering integration', () => {
projectRoot: '',
gitIgnoreFilter: null,
geminiIgnoreFilter: null,
+ isFileIgnored: vi.fn(),
} as unknown as Mocked<FileDiscoveryService>;
mockConfig = {
- getFileFilteringRespectGitIgnore: vi.fn(() => true),
- getFileService: vi.fn().mockReturnValue(mockFileDiscoveryService),
+ getFileFilteringOptions: vi.fn(() => ({
+ respectGitIgnore: true,
+ respectGeminiIgnore: true,
+ })),
getEnableRecursiveFileSearch: vi.fn(() => true),
+ getFileService: vi.fn(() => mockFileDiscoveryService),
};
vi.mocked(FileDiscoveryService).mockImplementation(
@@ -186,7 +193,7 @@ describe('useCompletion git-aware filtering integration', () => {
{ name: '.env', isDirectory: () => false },
] as unknown as Awaited<ReturnType<typeof fs.readdir>>);
- // Mock git ignore service to ignore certain files
+ // Mock ignore service to ignore certain files
mockFileDiscoveryService.shouldGitIgnoreFile.mockImplementation(
(path: string) =>
path.includes('node_modules') ||
@@ -195,8 +202,17 @@ describe('useCompletion git-aware filtering integration', () => {
);
mockFileDiscoveryService.shouldIgnoreFile.mockImplementation(
(path: string, options) => {
- if (options?.respectGitIgnore !== false) {
- return mockFileDiscoveryService.shouldGitIgnoreFile(path);
+ if (
+ options?.respectGitIgnore &&
+ mockFileDiscoveryService.shouldGitIgnoreFile(path)
+ ) {
+ return true;
+ }
+ if (
+ options?.respectGeminiIgnore &&
+ mockFileDiscoveryService.shouldGeminiIgnoreFile
+ ) {
+ return mockFileDiscoveryService.shouldGeminiIgnoreFile(path);
}
return false;
},
@@ -231,38 +247,54 @@ describe('useCompletion git-aware filtering integration', () => {
it('should handle recursive search with git-aware filtering', async () => {
// Mock the recursive file search scenario
vi.mocked(fs.readdir).mockImplementation(
- async (dirPath: string | Buffer | URL) => {
- if (dirPath === testCwd) {
- return [
- { name: 'src', isDirectory: () => true },
- { name: 'node_modules', isDirectory: () => true },
- { name: 'temp', isDirectory: () => true },
- ] as Array<{ name: string; isDirectory: () => boolean }>;
- }
- if (dirPath.endsWith('/src')) {
- return [
- { name: 'index.ts', isDirectory: () => false },
- { name: 'components', isDirectory: () => true },
- ] as Array<{ name: string; isDirectory: () => boolean }>;
+ async (
+ dirPath: string | Buffer | URL,
+ options?: { withFileTypes?: boolean },
+ ) => {
+ const path = dirPath.toString();
+ if (options?.withFileTypes) {
+ if (path === testCwd) {
+ return [
+ { name: 'data', isDirectory: () => true },
+ { name: 'dist', isDirectory: () => true },
+ { name: 'node_modules', isDirectory: () => true },
+ { name: 'README.md', isDirectory: () => false },
+ { name: '.env', isDirectory: () => false },
+ ] as unknown as Awaited<ReturnType<typeof fs.readdir>>;
+ }
+ if (path.endsWith('/src')) {
+ return [
+ { name: 'index.ts', isDirectory: () => false },
+ { name: 'components', isDirectory: () => true },
+ ] as unknown as Awaited<ReturnType<typeof fs.readdir>>;
+ }
+ if (path.endsWith('/temp')) {
+ return [
+ { name: 'temp.log', isDirectory: () => false },
+ ] as unknown as Awaited<ReturnType<typeof fs.readdir>>;
+ }
}
- if (dirPath.endsWith('/temp')) {
- return [{ name: 'temp.log', isDirectory: () => false }] as Array<{
- name: string;
- isDirectory: () => boolean;
- }>;
- }
- return [] as Array<{ name: string; isDirectory: () => boolean }>;
+ return [];
},
);
- // Mock git ignore service
+ // Mock ignore service
mockFileDiscoveryService.shouldGitIgnoreFile.mockImplementation(
(path: string) => path.includes('node_modules') || path.includes('temp'),
);
mockFileDiscoveryService.shouldIgnoreFile.mockImplementation(
(path: string, options) => {
- if (options?.respectGitIgnore !== false) {
- return mockFileDiscoveryService.shouldGitIgnoreFile(path);
+ if (
+ options?.respectGitIgnore &&
+ mockFileDiscoveryService.shouldGitIgnoreFile(path)
+ ) {
+ return true;
+ }
+ if (
+ options?.respectGeminiIgnore &&
+ mockFileDiscoveryService.shouldGeminiIgnoreFile
+ ) {
+ return mockFileDiscoveryService.shouldGeminiIgnoreFile(path);
}
return false;
},
@@ -405,9 +437,12 @@ describe('useCompletion git-aware filtering integration', () => {
);
mockFileDiscoveryService.shouldIgnoreFile.mockImplementation(
(path: string, options) => {
- if (options?.respectGitIgnore !== false) {
+ if (options?.respectGitIgnore) {
return mockFileDiscoveryService.shouldGitIgnoreFile(path);
}
+ if (options?.respectGeminiIgnore) {
+ return mockFileDiscoveryService.shouldGeminiIgnoreFile(path);
+ }
return false;
},
);