diff options
| author | JaeHo Jang <[email protected]> | 2025-08-22 03:21:04 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-21 18:21:04 +0000 |
| commit | 1e5ead6960d531c51593be25c8665e4e8f118562 (patch) | |
| tree | ad77be43cb289ab7a3705e8abd423432eb1ac161 /packages/core/src/utils/memoryDiscovery.test.ts | |
| parent | 714b3dab73bb2a6e0f3c66ac8142db9ea7cc5fc7 (diff) | |
perf(core): parallelize memory discovery file operations performance gain (#5751)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/core/src/utils/memoryDiscovery.test.ts')
| -rw-r--r-- | packages/core/src/utils/memoryDiscovery.test.ts | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/packages/core/src/utils/memoryDiscovery.test.ts b/packages/core/src/utils/memoryDiscovery.test.ts index d8f3ccc5..c67427e9 100644 --- a/packages/core/src/utils/memoryDiscovery.test.ts +++ b/packages/core/src/utils/memoryDiscovery.test.ts @@ -368,4 +368,75 @@ describe('loadServerHierarchicalMemory', () => { fileCount: 1, }); }); + + it('should handle multiple directories and files in parallel correctly', async () => { + // Create multiple test directories with GEMINI.md files + const numDirs = 5; + const createdFiles: string[] = []; + + for (let i = 0; i < numDirs; i++) { + const dirPath = await createEmptyDir( + path.join(testRootDir, `project-${i}`), + ); + const filePath = await createTestFile( + path.join(dirPath, DEFAULT_CONTEXT_FILENAME), + `Content from project ${i}`, + ); + createdFiles.push(filePath); + } + + // Load memory from all directories + const result = await loadServerHierarchicalMemory( + cwd, + createdFiles.map((f) => path.dirname(f)), + false, + new FileDiscoveryService(projectRoot), + ); + + // Should have loaded all files + expect(result.fileCount).toBe(numDirs); + + // Content should include all project contents + for (let i = 0; i < numDirs; i++) { + expect(result.memoryContent).toContain(`Content from project ${i}`); + } + }); + + it('should preserve order and prevent duplicates when processing multiple directories', async () => { + // Create overlapping directory structure + const parentDir = await createEmptyDir(path.join(testRootDir, 'parent')); + const childDir = await createEmptyDir(path.join(parentDir, 'child')); + + await createTestFile( + path.join(parentDir, DEFAULT_CONTEXT_FILENAME), + 'Parent content', + ); + await createTestFile( + path.join(childDir, DEFAULT_CONTEXT_FILENAME), + 'Child content', + ); + + // Include both parent and child directories + const result = await loadServerHierarchicalMemory( + parentDir, + [childDir, parentDir], // Deliberately include duplicates + false, + new FileDiscoveryService(projectRoot), + ); + + // Should have both files without duplicates + expect(result.fileCount).toBe(2); + expect(result.memoryContent).toContain('Parent content'); + expect(result.memoryContent).toContain('Child content'); + + // Check that files are not duplicated + const parentOccurrences = ( + result.memoryContent.match(/Parent content/g) || [] + ).length; + const childOccurrences = ( + result.memoryContent.match(/Child content/g) || [] + ).length; + expect(parentOccurrences).toBe(1); + expect(childOccurrences).toBe(1); + }); }); |
