summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/commands
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/ui/commands')
-rw-r--r--packages/cli/src/ui/commands/helpCommand.test.ts46
-rw-r--r--packages/cli/src/ui/commands/helpCommand.ts16
-rw-r--r--packages/cli/src/ui/commands/types.ts2
3 files changed, 39 insertions, 25 deletions
diff --git a/packages/cli/src/ui/commands/helpCommand.test.ts b/packages/cli/src/ui/commands/helpCommand.test.ts
index b0441106..566eead7 100644
--- a/packages/cli/src/ui/commands/helpCommand.test.ts
+++ b/packages/cli/src/ui/commands/helpCommand.test.ts
@@ -4,37 +4,49 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import { vi, describe, it, expect, beforeEach } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { helpCommand } from './helpCommand.js';
import { type CommandContext } from './types.js';
+import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
+import { MessageType } from '../types.js';
+import { CommandKind } from './types.js';
describe('helpCommand', () => {
let mockContext: CommandContext;
+ const originalEnv = { ...process.env };
beforeEach(() => {
- mockContext = {} as unknown as CommandContext;
+ mockContext = createMockCommandContext({
+ ui: {
+ addItem: vi.fn(),
+ },
+ } as unknown as CommandContext);
});
- it("should return a dialog action and log a debug message for '/help'", () => {
- const consoleDebugSpy = vi
- .spyOn(console, 'debug')
- .mockImplementation(() => {});
+ afterEach(() => {
+ process.env = { ...originalEnv };
+ vi.clearAllMocks();
+ });
+
+ it('should add a help message to the UI history', async () => {
if (!helpCommand.action) {
throw new Error('Help command has no action');
}
- const result = helpCommand.action(mockContext, '');
- expect(result).toEqual({
- type: 'dialog',
- dialog: 'help',
- });
- expect(consoleDebugSpy).toHaveBeenCalledWith('Opening help UI ...');
+ await helpCommand.action(mockContext, '');
+
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
+ expect.objectContaining({
+ type: MessageType.HELP,
+ timestamp: expect.any(Date),
+ }),
+ expect.any(Number),
+ );
});
- it("should also be triggered by its alternative name '?'", () => {
- // This test is more conceptual. The routing of altNames to the command
- // is handled by the slash command processor, but we can assert the
- // altNames is correctly defined on the command object itself.
- expect(helpCommand.altNames).toContain('?');
+ it('should have the correct command properties', () => {
+ expect(helpCommand.name).toBe('help');
+ expect(helpCommand.kind).toBe(CommandKind.BUILT_IN);
+ expect(helpCommand.description).toBe('for help on gemini-cli');
});
});
diff --git a/packages/cli/src/ui/commands/helpCommand.ts b/packages/cli/src/ui/commands/helpCommand.ts
index 03c64615..0b71ce8f 100644
--- a/packages/cli/src/ui/commands/helpCommand.ts
+++ b/packages/cli/src/ui/commands/helpCommand.ts
@@ -4,18 +4,20 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import { CommandKind, OpenDialogActionReturn, SlashCommand } from './types.js';
+import { CommandKind, SlashCommand } from './types.js';
+import { MessageType, type HistoryItemHelp } from '../types.js';
export const helpCommand: SlashCommand = {
name: 'help',
altNames: ['?'],
- description: 'for help on gemini-cli',
kind: CommandKind.BUILT_IN,
- action: (_context, _args): OpenDialogActionReturn => {
- console.debug('Opening help UI ...');
- return {
- type: 'dialog',
- dialog: 'help',
+ description: 'for help on gemini-cli',
+ action: async (context) => {
+ const helpItem: Omit<HistoryItemHelp, 'id'> = {
+ type: MessageType.HELP,
+ timestamp: new Date(),
};
+
+ context.ui.addItem(helpItem, Date.now());
},
};
diff --git a/packages/cli/src/ui/commands/types.ts b/packages/cli/src/ui/commands/types.ts
index 900be866..2de221f0 100644
--- a/packages/cli/src/ui/commands/types.ts
+++ b/packages/cli/src/ui/commands/types.ts
@@ -98,7 +98,7 @@ export interface MessageActionReturn {
*/
export interface OpenDialogActionReturn {
type: 'dialog';
- dialog: 'help' | 'auth' | 'theme' | 'editor' | 'privacy';
+ dialog: 'auth' | 'theme' | 'editor' | 'privacy';
}
/**