mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 02:24:09 -07:00
fix(cli): prevent OOM crash by limiting file search traversal and adding timeout (#16696)
This commit is contained in:
@@ -503,14 +503,14 @@ describe('crawler', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const getCrawlResults = (maxDepth?: number) => {
|
||||
const getCrawlResults = async (maxDepth?: number) => {
|
||||
const ignore = loadIgnoreRules({
|
||||
projectRoot: tmpDir,
|
||||
useGitignore: false,
|
||||
useGeminiignore: false,
|
||||
ignoreDirs: [],
|
||||
});
|
||||
return crawl({
|
||||
const paths = await crawl({
|
||||
crawlDirectory: tmpDir,
|
||||
cwd: tmpDir,
|
||||
ignore,
|
||||
@@ -518,6 +518,7 @@ describe('crawler', () => {
|
||||
cacheTtl: 0,
|
||||
maxDepth,
|
||||
});
|
||||
return paths;
|
||||
};
|
||||
|
||||
it('should only crawl top-level files when maxDepth is 0', async () => {
|
||||
@@ -571,4 +572,34 @@ describe('crawler', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should detect truncation when maxFiles is hit', async () => {
|
||||
tmpDir = await createTmpDir({
|
||||
'file1.js': '',
|
||||
'file2.js': '',
|
||||
'file3.js': '',
|
||||
});
|
||||
|
||||
const ignore = loadIgnoreRules({
|
||||
projectRoot: tmpDir,
|
||||
useGitignore: false,
|
||||
useGeminiignore: false,
|
||||
ignoreDirs: [],
|
||||
});
|
||||
|
||||
const paths = await crawl({
|
||||
crawlDirectory: tmpDir,
|
||||
cwd: tmpDir,
|
||||
ignore,
|
||||
cache: false,
|
||||
cacheTtl: 0,
|
||||
maxFiles: 2,
|
||||
});
|
||||
|
||||
// fdir returns files and directories.
|
||||
// In our filter, we only increment fileCount for files.
|
||||
// So we should have 2 files + some directories.
|
||||
const files = paths.filter((p) => p !== '.' && !p.endsWith('/'));
|
||||
expect(files.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user