|
6 | 6 |
|
7 | 7 | import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; |
8 | 8 | import * as os from 'os'; |
| 9 | +import * as fs from 'fs'; |
| 10 | +import * as path from 'path'; |
9 | 11 | import { loadCliConfig, parseArguments } from './config.js'; |
10 | 12 | import { Settings } from './settings.js'; |
11 | 13 | import { Extension } from './extension.js'; |
@@ -44,7 +46,7 @@ vi.mock('@google/gemini-cli-core', async () => { |
44 | 46 | }, |
45 | 47 | loadEnvironment: vi.fn(), |
46 | 48 | loadServerHierarchicalMemory: vi.fn( |
47 | | - (cwd, debug, fileService, extensionPaths, _maxDirs) => |
| 49 | + (cwd, dirs, debug, fileService, extensionPaths, _maxDirs) => |
48 | 50 | Promise.resolve({ |
49 | 51 | memoryContent: extensionPaths?.join(',') || '', |
50 | 52 | fileCount: extensionPaths?.length || 0, |
@@ -487,6 +489,7 @@ describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => { |
487 | 489 | await loadCliConfig(settings, extensions, 'session-id', argv); |
488 | 490 | expect(ServerConfig.loadServerHierarchicalMemory).toHaveBeenCalledWith( |
489 | 491 | expect.any(String), |
| 492 | + [], |
490 | 493 | false, |
491 | 494 | expect.any(Object), |
492 | 495 | [ |
@@ -1015,3 +1018,85 @@ describe('loadCliConfig ideModeFeature', () => { |
1015 | 1018 | expect(config.getIdeModeFeature()).toBe(false); |
1016 | 1019 | }); |
1017 | 1020 | }); |
| 1021 | + |
| 1022 | +vi.mock('fs', async () => { |
| 1023 | + const actualFs = await vi.importActual<typeof fs>('fs'); |
| 1024 | + const MOCK_CWD1 = process.cwd(); |
| 1025 | + const MOCK_CWD2 = path.resolve(path.sep, 'home', 'user', 'project'); |
| 1026 | + |
| 1027 | + const mockPaths = new Set([ |
| 1028 | + MOCK_CWD1, |
| 1029 | + MOCK_CWD2, |
| 1030 | + path.resolve(path.sep, 'cli', 'path1'), |
| 1031 | + path.resolve(path.sep, 'settings', 'path1'), |
| 1032 | + path.join(os.homedir(), 'settings', 'path2'), |
| 1033 | + path.join(MOCK_CWD2, 'cli', 'path2'), |
| 1034 | + path.join(MOCK_CWD2, 'settings', 'path3'), |
| 1035 | + ]); |
| 1036 | + |
| 1037 | + return { |
| 1038 | + ...actualFs, |
| 1039 | + existsSync: vi.fn((p) => mockPaths.has(p.toString())), |
| 1040 | + statSync: vi.fn((p) => { |
| 1041 | + if (mockPaths.has(p.toString())) { |
| 1042 | + return { isDirectory: () => true }; |
| 1043 | + } |
| 1044 | + // Fallback for other paths if needed, though the test should be specific. |
| 1045 | + return actualFs.statSync(p); |
| 1046 | + }), |
| 1047 | + realpathSync: vi.fn((p) => p), |
| 1048 | + }; |
| 1049 | +}); |
| 1050 | + |
| 1051 | +describe('loadCliConfig with includeDirectories', () => { |
| 1052 | + const originalArgv = process.argv; |
| 1053 | + const originalEnv = { ...process.env }; |
| 1054 | + |
| 1055 | + beforeEach(() => { |
| 1056 | + vi.resetAllMocks(); |
| 1057 | + vi.mocked(os.homedir).mockReturnValue('/mock/home/user'); |
| 1058 | + process.env.GEMINI_API_KEY = 'test-api-key'; |
| 1059 | + vi.spyOn(process, 'cwd').mockReturnValue( |
| 1060 | + path.resolve(path.sep, 'home', 'user', 'project'), |
| 1061 | + ); |
| 1062 | + }); |
| 1063 | + |
| 1064 | + afterEach(() => { |
| 1065 | + process.argv = originalArgv; |
| 1066 | + process.env = originalEnv; |
| 1067 | + vi.restoreAllMocks(); |
| 1068 | + }); |
| 1069 | + |
| 1070 | + it('should combine and resolve paths from settings and CLI arguments', async () => { |
| 1071 | + const mockCwd = path.resolve(path.sep, 'home', 'user', 'project'); |
| 1072 | + process.argv = [ |
| 1073 | + 'node', |
| 1074 | + 'script.js', |
| 1075 | + '--include-directories', |
| 1076 | + `${path.resolve(path.sep, 'cli', 'path1')},${path.join(mockCwd, 'cli', 'path2')}`, |
| 1077 | + ]; |
| 1078 | + const argv = await parseArguments(); |
| 1079 | + const settings: Settings = { |
| 1080 | + includeDirectories: [ |
| 1081 | + path.resolve(path.sep, 'settings', 'path1'), |
| 1082 | + path.join(os.homedir(), 'settings', 'path2'), |
| 1083 | + path.join(mockCwd, 'settings', 'path3'), |
| 1084 | + ], |
| 1085 | + }; |
| 1086 | + const config = await loadCliConfig(settings, [], 'test-session', argv); |
| 1087 | + const expected = [ |
| 1088 | + mockCwd, |
| 1089 | + path.resolve(path.sep, 'cli', 'path1'), |
| 1090 | + path.join(mockCwd, 'cli', 'path2'), |
| 1091 | + path.resolve(path.sep, 'settings', 'path1'), |
| 1092 | + path.join(os.homedir(), 'settings', 'path2'), |
| 1093 | + path.join(mockCwd, 'settings', 'path3'), |
| 1094 | + ]; |
| 1095 | + expect(config.getWorkspaceContext().getDirectories()).toEqual( |
| 1096 | + expect.arrayContaining(expected), |
| 1097 | + ); |
| 1098 | + expect(config.getWorkspaceContext().getDirectories()).toHaveLength( |
| 1099 | + expected.length, |
| 1100 | + ); |
| 1101 | + }); |
| 1102 | +}); |
0 commit comments