diff options
Diffstat (limited to 'packages/cli/src/services')
| -rw-r--r-- | packages/cli/src/services/CommandService.test.ts | 32 | ||||
| -rw-r--r-- | packages/cli/src/services/CommandService.ts | 50 |
2 files changed, 62 insertions, 20 deletions
diff --git a/packages/cli/src/services/CommandService.test.ts b/packages/cli/src/services/CommandService.test.ts index 5c28228e..d9799146 100644 --- a/packages/cli/src/services/CommandService.test.ts +++ b/packages/cli/src/services/CommandService.test.ts @@ -6,6 +6,7 @@ import { vi, describe, it, expect, beforeEach } from 'vitest'; import { CommandService } from './CommandService.js'; +import { type Config } from '@google/gemini-cli-core'; import { type SlashCommand } from '../ui/commands/types.js'; import { memoryCommand } from '../ui/commands/memoryCommand.js'; import { helpCommand } from '../ui/commands/helpCommand.js'; @@ -17,6 +18,7 @@ import { themeCommand } from '../ui/commands/themeCommand.js'; import { statsCommand } from '../ui/commands/statsCommand.js'; import { privacyCommand } from '../ui/commands/privacyCommand.js'; import { aboutCommand } from '../ui/commands/aboutCommand.js'; +import { ideCommand } from '../ui/commands/ideCommand.js'; import { extensionsCommand } from '../ui/commands/extensionsCommand.js'; import { toolsCommand } from '../ui/commands/toolsCommand.js'; import { compressCommand } from '../ui/commands/compressCommand.js'; @@ -50,6 +52,9 @@ vi.mock('../ui/commands/statsCommand.js', () => ({ vi.mock('../ui/commands/aboutCommand.js', () => ({ aboutCommand: { name: 'about', description: 'Mock About' }, })); +vi.mock('../ui/commands/ideCommand.js', () => ({ + ideCommand: vi.fn(), +})); vi.mock('../ui/commands/extensionsCommand.js', () => ({ extensionsCommand: { name: 'extensions', description: 'Mock Extensions' }, })); @@ -65,12 +70,20 @@ vi.mock('../ui/commands/mcpCommand.js', () => ({ describe('CommandService', () => { const subCommandLen = 14; + let mockConfig: vi.Mocked<Config>; + + beforeEach(() => { + mockConfig = { + getIdeMode: vi.fn(), + } as unknown as vi.Mocked<Config>; + vi.mocked(ideCommand).mockReturnValue(null); + }); describe('when using default production loader', () => { let commandService: CommandService; beforeEach(() => { - commandService = new CommandService(); + commandService = new CommandService(mockConfig); }); it('should initialize with an empty command tree', () => { @@ -106,6 +119,21 @@ describe('CommandService', () => { expect(commandNames).toContain('tools'); expect(commandNames).toContain('compress'); expect(commandNames).toContain('mcp'); + expect(commandNames).not.toContain('ide'); + }); + + it('should include ide command when ideMode is on', async () => { + mockConfig.getIdeMode.mockReturnValue(true); + vi.mocked(ideCommand).mockReturnValue({ + name: 'ide', + description: 'Mock IDE', + }); + await commandService.loadCommands(); + const tree = commandService.getCommands(); + + expect(tree.length).toBe(subCommandLen + 1); + const commandNames = tree.map((cmd) => cmd.name); + expect(commandNames).toContain('ide'); }); it('should overwrite any existing commands when called again', async () => { @@ -163,7 +191,7 @@ describe('CommandService', () => { const mockLoader = vi.fn().mockResolvedValue(mockCommands); // Act: Instantiate the service WITH the injected loader function. - const commandService = new CommandService(mockLoader); + const commandService = new CommandService(mockConfig, mockLoader); await commandService.loadCommands(); const tree = commandService.getCommands(); diff --git a/packages/cli/src/services/CommandService.ts b/packages/cli/src/services/CommandService.ts index 51fe2ad8..d8604276 100644 --- a/packages/cli/src/services/CommandService.ts +++ b/packages/cli/src/services/CommandService.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { Config } from '@google/gemini-cli-core'; import { SlashCommand } from '../ui/commands/types.js'; import { memoryCommand } from '../ui/commands/memoryCommand.js'; import { helpCommand } from '../ui/commands/helpCommand.js'; @@ -19,29 +20,42 @@ import { aboutCommand } from '../ui/commands/aboutCommand.js'; import { extensionsCommand } from '../ui/commands/extensionsCommand.js'; import { toolsCommand } from '../ui/commands/toolsCommand.js'; import { compressCommand } from '../ui/commands/compressCommand.js'; +import { ideCommand } from '../ui/commands/ideCommand.js'; -const loadBuiltInCommands = async (): Promise<SlashCommand[]> => [ - aboutCommand, - authCommand, - chatCommand, - clearCommand, - compressCommand, - docsCommand, - extensionsCommand, - helpCommand, - mcpCommand, - memoryCommand, - privacyCommand, - statsCommand, - themeCommand, - toolsCommand, -]; +const loadBuiltInCommands = async ( + config: Config | null, +): Promise<SlashCommand[]> => { + const allCommands = [ + aboutCommand, + authCommand, + chatCommand, + clearCommand, + compressCommand, + docsCommand, + extensionsCommand, + helpCommand, + ideCommand(config), + mcpCommand, + memoryCommand, + privacyCommand, + statsCommand, + themeCommand, + toolsCommand, + ]; + + return allCommands.filter( + (command): command is SlashCommand => command !== null, + ); +}; export class CommandService { private commands: SlashCommand[] = []; constructor( - private commandLoader: () => Promise<SlashCommand[]> = loadBuiltInCommands, + private config: Config | null, + private commandLoader: ( + config: Config | null, + ) => Promise<SlashCommand[]> = loadBuiltInCommands, ) { // The constructor can be used for dependency injection in the future. } @@ -49,7 +63,7 @@ export class CommandService { async loadCommands(): Promise<void> { // For now, we only load the built-in commands. // File-based and remote commands will be added later. - this.commands = await this.commandLoader(); + this.commands = await this.commandLoader(this.config); } getCommands(): SlashCommand[] { |
