mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-18 18:11:02 -07:00
fix(core,cli): enable recursive directory access for (#17094)
This commit is contained in:
@@ -374,6 +374,75 @@ describe('WorkspaceContext with real filesystem', () => {
|
||||
expect(dirs1).toEqual(dirs2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addDirectories', () => {
|
||||
it('should add multiple directories and emit one event', () => {
|
||||
const dir3 = path.join(tempDir, 'dir3');
|
||||
fs.mkdirSync(dir3);
|
||||
|
||||
const workspaceContext = new WorkspaceContext(cwd);
|
||||
const listener = vi.fn();
|
||||
workspaceContext.onDirectoriesChanged(listener);
|
||||
|
||||
const result = workspaceContext.addDirectories([otherDir, dir3]);
|
||||
|
||||
expect(workspaceContext.getDirectories()).toContain(otherDir);
|
||||
expect(workspaceContext.getDirectories()).toContain(dir3);
|
||||
expect(listener).toHaveBeenCalledOnce();
|
||||
expect(result.added).toHaveLength(2);
|
||||
expect(result.failed).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should handle partial failures', () => {
|
||||
const workspaceContext = new WorkspaceContext(cwd);
|
||||
const listener = vi.fn();
|
||||
workspaceContext.onDirectoriesChanged(listener);
|
||||
|
||||
const loggerSpy = vi
|
||||
.spyOn(debugLogger, 'warn')
|
||||
.mockImplementation(() => {});
|
||||
|
||||
const nonExistent = path.join(tempDir, 'does-not-exist');
|
||||
const result = workspaceContext.addDirectories([otherDir, nonExistent]);
|
||||
|
||||
expect(workspaceContext.getDirectories()).toContain(otherDir);
|
||||
expect(workspaceContext.getDirectories()).not.toContain(nonExistent);
|
||||
expect(listener).toHaveBeenCalledOnce();
|
||||
expect(loggerSpy).toHaveBeenCalled();
|
||||
expect(result.added).toEqual([otherDir]);
|
||||
expect(result.failed).toHaveLength(1);
|
||||
expect(result.failed[0].path).toBe(nonExistent);
|
||||
expect(result.failed[0].error).toBeDefined();
|
||||
|
||||
loggerSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('should not emit event if no directories added', () => {
|
||||
const workspaceContext = new WorkspaceContext(cwd);
|
||||
const listener = vi.fn();
|
||||
workspaceContext.onDirectoriesChanged(listener);
|
||||
const loggerSpy = vi
|
||||
.spyOn(debugLogger, 'warn')
|
||||
.mockImplementation(() => {});
|
||||
|
||||
const nonExistent = path.join(tempDir, 'does-not-exist');
|
||||
const result = workspaceContext.addDirectories([nonExistent]);
|
||||
|
||||
expect(listener).not.toHaveBeenCalled();
|
||||
expect(result.added).toHaveLength(0);
|
||||
expect(result.failed).toHaveLength(1);
|
||||
loggerSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('addDirectory', () => {
|
||||
it('should throw error if directory fails to add', () => {
|
||||
const workspaceContext = new WorkspaceContext(cwd);
|
||||
const nonExistent = path.join(tempDir, 'does-not-exist');
|
||||
|
||||
expect(() => workspaceContext.addDirectory(nonExistent)).toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('WorkspaceContext with optional directories', () => {
|
||||
|
||||
Reference in New Issue
Block a user