summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/bfsFileSearch.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src/utils/bfsFileSearch.test.ts')
-rw-r--r--packages/core/src/utils/bfsFileSearch.test.ts101
1 files changed, 32 insertions, 69 deletions
diff --git a/packages/core/src/utils/bfsFileSearch.test.ts b/packages/core/src/utils/bfsFileSearch.test.ts
index ce19f80e..f9d76e38 100644
--- a/packages/core/src/utils/bfsFileSearch.test.ts
+++ b/packages/core/src/utils/bfsFileSearch.test.ts
@@ -190,80 +190,43 @@ describe('bfsFileSearch', () => {
});
});
- it('should perform parallel directory scanning efficiently (performance test)', async () => {
- // Create a more complex directory structure for performance testing
- console.log('\nšŸš€ Testing Parallel BFS Performance...');
+ it('should find all files in a complex directory structure', async () => {
+ // Create a complex directory structure to test correctness at scale
+ // without flaky performance checks.
+ const numDirs = 50;
+ const numFilesPerDir = 2;
+ const numTargetDirs = 10;
- // Create 50 directories with multiple levels for faster test execution
- for (let i = 0; i < 50; i++) {
- await createEmptyDir(`dir${i}`);
- await createEmptyDir(`dir${i}`, 'subdir1');
- await createEmptyDir(`dir${i}`, 'subdir2');
- await createEmptyDir(`dir${i}`, 'subdir1', 'deep');
- if (i < 10) {
- // Add target files in some directories
- await createTestFile('content', `dir${i}`, 'GEMINI.md');
- await createTestFile('content', `dir${i}`, 'subdir1', 'GEMINI.md');
- }
+ const dirCreationPromises: Array<Promise<unknown>> = [];
+ for (let i = 0; i < numDirs; i++) {
+ dirCreationPromises.push(createEmptyDir(`dir${i}`));
+ dirCreationPromises.push(createEmptyDir(`dir${i}`, 'subdir1'));
+ dirCreationPromises.push(createEmptyDir(`dir${i}`, 'subdir2'));
+ dirCreationPromises.push(createEmptyDir(`dir${i}`, 'subdir1', 'deep'));
}
+ await Promise.all(dirCreationPromises);
- // Run multiple iterations to ensure consistency
- const iterations = 3;
- const durations: number[] = [];
- let foundFiles = 0;
- let firstResultSorted: string[] | undefined;
-
- for (let i = 0; i < iterations; i++) {
- const searchStartTime = performance.now();
- const result = await bfsFileSearch(testRootDir, {
- fileName: 'GEMINI.md',
- maxDirs: 200,
- debug: false,
- });
- const duration = performance.now() - searchStartTime;
- durations.push(duration);
-
- // Verify consistency: all iterations should find the exact same files
- if (firstResultSorted === undefined) {
- foundFiles = result.length;
- firstResultSorted = result.sort();
- } else {
- expect(result.sort()).toEqual(firstResultSorted);
- }
-
- console.log(`šŸ“Š Iteration ${i + 1}: ${duration.toFixed(2)}ms`);
+ const fileCreationPromises: Array<Promise<string>> = [];
+ for (let i = 0; i < numTargetDirs; i++) {
+ // Add target files in some directories
+ fileCreationPromises.push(
+ createTestFile('content', `dir${i}`, 'GEMINI.md'),
+ );
+ fileCreationPromises.push(
+ createTestFile('content', `dir${i}`, 'subdir1', 'GEMINI.md'),
+ );
}
+ const expectedFiles = await Promise.all(fileCreationPromises);
- const avgDuration = durations.reduce((a, b) => a + b, 0) / durations.length;
- const maxDuration = Math.max(...durations);
- const minDuration = Math.min(...durations);
-
- console.log(`šŸ“Š Average Duration: ${avgDuration.toFixed(2)}ms`);
- console.log(
- `šŸ“Š Min/Max Duration: ${minDuration.toFixed(2)}ms / ${maxDuration.toFixed(2)}ms`,
- );
- console.log(`šŸ“ Found ${foundFiles} GEMINI.md files`);
- console.log(
- `šŸŽļø Processing ~${Math.round(200 / (avgDuration / 1000))} dirs/second`,
- );
-
- // Verify we found the expected files
- expect(foundFiles).toBe(20); // 10 dirs * 2 files each
-
- // Performance expectation: check consistency rather than absolute time
- const variance = maxDuration - minDuration;
- const consistencyRatio = variance / avgDuration;
-
- // Ensure reasonable performance (generous limit for CI environments)
- expect(avgDuration).toBeLessThan(2000); // Very generous limit
-
- // Ensure consistency across runs (variance should not be too high)
- // More tolerant in CI environments where performance can be variable
- const maxConsistencyRatio = process.env.CI ? 3.0 : 1.5;
- expect(consistencyRatio).toBeLessThan(maxConsistencyRatio); // Max variance should be reasonable
+ const result = await bfsFileSearch(testRootDir, {
+ fileName: 'GEMINI.md',
+ // Provide a generous maxDirs limit to ensure it doesn't prematurely stop
+ // in this large test case. Total dirs created is 200.
+ maxDirs: 250,
+ });
- console.log(
- `āœ… Performance test passed: avg=${avgDuration.toFixed(2)}ms, consistency=${(consistencyRatio * 100).toFixed(1)}% (threshold: ${(maxConsistencyRatio * 100).toFixed(0)}%)`,
- );
+ // Verify we found the exact files we created
+ expect(result.length).toBe(numTargetDirs * numFilesPerDir);
+ expect(result.sort()).toEqual(expectedFiles.sort());
});
});