fix(cli): prevent OOM crash by limiting file search traversal and adding timeout (#16696)

This commit is contained in:
Gal Zahavi
2026-01-15 12:04:22 -08:00
committed by GitHub
parent 48fdb9872f
commit e77d7b2e1e
7 changed files with 126 additions and 3 deletions
@@ -7,6 +7,7 @@
import { describe, it, expect, afterEach, vi } from 'vitest';
import { FileSearchFactory, AbortError, filter } from './fileSearch.js';
import { createTmpDir, cleanupTmpDir } from '@google/gemini-cli-test-utils';
import * as crawler from './crawler.js';
describe('FileSearch', () => {
let tmpDir: string;
@@ -481,6 +482,33 @@ describe('FileSearch', () => {
expect(results).toEqual(['src/', 'src/main.js']);
});
it('should respect default maxFiles budget of 20000 in RecursiveFileSearch', async () => {
const crawlSpy = vi.spyOn(crawler, 'crawl');
tmpDir = await createTmpDir({
'file1.js': '',
});
const fileSearch = FileSearchFactory.create({
projectRoot: tmpDir,
useGitignore: false,
useGeminiignore: false,
ignoreDirs: [],
cache: false,
cacheTtl: 0,
enableRecursiveFileSearch: true,
disableFuzzySearch: false,
});
await fileSearch.initialize();
expect(crawlSpy).toHaveBeenCalledWith(
expect.objectContaining({
maxFiles: 20000,
}),
);
});
it('should be cancellable via AbortSignal', async () => {
const largeDir: Record<string, string> = {};
for (let i = 0; i < 100; i++) {