diff --git a/packages/cli/src/services/CommandService.test.ts b/packages/cli/src/services/CommandService.test.ts index d9799146..b94e265b 100644 --- a/packages/cli/src/services/CommandService.test.ts +++ b/packages/cli/src/services/CommandService.test.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { vi, describe, it, expect, beforeEach } from 'vitest'; +import { vi, describe, it, expect, beforeEach, type Mocked } from 'vitest'; import { CommandService } from './CommandService.js'; import { type Config } from '@google/gemini-cli-core'; import { type SlashCommand } from '../ui/commands/types.js'; @@ -23,6 +23,7 @@ import { extensionsCommand } from '../ui/commands/extensionsCommand.js'; import { toolsCommand } from '../ui/commands/toolsCommand.js'; import { compressCommand } from '../ui/commands/compressCommand.js'; import { mcpCommand } from '../ui/commands/mcpCommand.js'; +import { editorCommand } from '../ui/commands/editorCommand.js'; // Mock the command modules to isolate the service from the command implementations. vi.mock('../ui/commands/memoryCommand.js', () => ({ @@ -67,15 +68,18 @@ vi.mock('../ui/commands/compressCommand.js', () => ({ vi.mock('../ui/commands/mcpCommand.js', () => ({ mcpCommand: { name: 'mcp', description: 'Mock MCP' }, })); +vi.mock('../ui/commands/editorCommand.js', () => ({ + editorCommand: { name: 'editor', description: 'Mock Editor' }, +})); describe('CommandService', () => { - const subCommandLen = 14; - let mockConfig: vi.Mocked; + const subCommandLen = 15; + let mockConfig: Mocked; beforeEach(() => { mockConfig = { getIdeMode: vi.fn(), - } as unknown as vi.Mocked; + } as unknown as Mocked; vi.mocked(ideCommand).mockReturnValue(null); }); @@ -134,6 +138,7 @@ describe('CommandService', () => { expect(tree.length).toBe(subCommandLen + 1); const commandNames = tree.map((cmd) => cmd.name); expect(commandNames).toContain('ide'); + expect(commandNames).toContain('editor'); }); it('should overwrite any existing commands when called again', async () => { @@ -166,6 +171,7 @@ describe('CommandService', () => { clearCommand, compressCommand, docsCommand, + editorCommand, extensionsCommand, helpCommand, mcpCommand, diff --git a/packages/cli/src/services/CommandService.ts b/packages/cli/src/services/CommandService.ts index d8604276..acd73dd9 100644 --- a/packages/cli/src/services/CommandService.ts +++ b/packages/cli/src/services/CommandService.ts @@ -13,6 +13,7 @@ import { docsCommand } from '../ui/commands/docsCommand.js'; import { mcpCommand } from '../ui/commands/mcpCommand.js'; import { authCommand } from '../ui/commands/authCommand.js'; import { themeCommand } from '../ui/commands/themeCommand.js'; +import { editorCommand } from '../ui/commands/editorCommand.js'; import { chatCommand } from '../ui/commands/chatCommand.js'; import { statsCommand } from '../ui/commands/statsCommand.js'; import { privacyCommand } from '../ui/commands/privacyCommand.js'; @@ -32,6 +33,7 @@ const loadBuiltInCommands = async ( clearCommand, compressCommand, docsCommand, + editorCommand, extensionsCommand, helpCommand, ideCommand(config), diff --git a/packages/cli/src/ui/commands/editorCommand.test.ts b/packages/cli/src/ui/commands/editorCommand.test.ts new file mode 100644 index 00000000..9b5e84d3 --- /dev/null +++ b/packages/cli/src/ui/commands/editorCommand.test.ts @@ -0,0 +1,30 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { describe, it, expect } from 'vitest'; +import { editorCommand } from './editorCommand.js'; +// 1. Import the mock context utility +import { createMockCommandContext } from '../../test-utils/mockCommandContext.js'; + +describe('editorCommand', () => { + it('should return a dialog action to open the editor dialog', () => { + if (!editorCommand.action) { + throw new Error('The editor command must have an action.'); + } + const mockContext = createMockCommandContext(); + const result = editorCommand.action(mockContext, ''); + + expect(result).toEqual({ + type: 'dialog', + dialog: 'editor', + }); + }); + + it('should have the correct name and description', () => { + expect(editorCommand.name).toBe('editor'); + expect(editorCommand.description).toBe('set external editor preference'); + }); +}); diff --git a/packages/cli/src/ui/commands/editorCommand.ts b/packages/cli/src/ui/commands/editorCommand.ts new file mode 100644 index 00000000..dbfafa51 --- /dev/null +++ b/packages/cli/src/ui/commands/editorCommand.ts @@ -0,0 +1,16 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { type OpenDialogActionReturn, type SlashCommand } from './types.js'; + +export const editorCommand: SlashCommand = { + name: 'editor', + description: 'set external editor preference', + action: (): OpenDialogActionReturn => ({ + type: 'dialog', + dialog: 'editor', + }), +}; diff --git a/packages/cli/src/ui/commands/types.ts b/packages/cli/src/ui/commands/types.ts index 85a85abe..a61a29f2 100644 --- a/packages/cli/src/ui/commands/types.ts +++ b/packages/cli/src/ui/commands/types.ts @@ -71,8 +71,7 @@ export interface MessageActionReturn { */ export interface OpenDialogActionReturn { type: 'dialog'; - // TODO: Add 'theme' | 'auth' | 'editor' | 'privacy' as migration happens. - dialog: 'help' | 'auth' | 'theme' | 'privacy'; + dialog: 'help' | 'auth' | 'theme' | 'editor' | 'privacy'; } /** diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index 399a923b..ab16d813 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -206,18 +206,6 @@ describe('useSlashCommandProcessor', () => { const getProcessor = () => getProcessorHook().result.current; - describe('Other commands', () => { - it('/editor should open editor dialog and return handled', async () => { - const { handleSlashCommand } = getProcessor(); - let commandResult: SlashCommandProcessorResult | false = false; - await act(async () => { - commandResult = await handleSlashCommand('/editor'); - }); - expect(mockOpenEditorDialog).toHaveBeenCalled(); - expect(commandResult).toEqual({ type: 'handled' }); - }); - }); - describe('New command registry', () => { let ActualCommandService: typeof CommandService; diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index c1c65080..237356fa 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -199,11 +199,6 @@ export const useSlashCommandProcessor = ( const legacyCommands: LegacySlashCommand[] = useMemo(() => { const commands: LegacySlashCommand[] = [ // `/help` and `/clear` have been migrated and REMOVED from this list. - { - name: 'editor', - description: 'set external editor preference', - action: (_mainCommand, _subCommand, _args) => openEditorDialog(), - }, { name: 'corgi', action: (_mainCommand, _subCommand, _args) => { @@ -425,7 +420,6 @@ export const useSlashCommandProcessor = ( return commands; }, [ addMessage, - openEditorDialog, toggleCorgiMode, config, session, @@ -519,6 +513,9 @@ export const useSlashCommandProcessor = ( case 'theme': openThemeDialog(); return { type: 'handled' }; + case 'editor': + openEditorDialog(); + return { type: 'handled' }; case 'privacy': openPrivacyNotice(); return { type: 'handled' }; @@ -617,6 +614,7 @@ export const useSlashCommandProcessor = ( addMessage, openThemeDialog, openPrivacyNotice, + openEditorDialog, ], );