From e4473a9007e7555809ec9e4087be636e8aadf017 Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Wed, 13 Aug 2025 11:13:18 -0700 Subject: Revert "chore(cli/slashcommands): Add status enum to SlashCommandEvent telemetry" (#6161) --- .../cli/src/ui/hooks/slashCommandProcessor.test.ts | 110 ++++++--------------- 1 file changed, 31 insertions(+), 79 deletions(-) (limited to 'packages/cli/src/ui/hooks/slashCommandProcessor.test.ts') diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts index 24880fc1..66c1b883 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts @@ -4,17 +4,18 @@ * SPDX-License-Identifier: Apache-2.0 */ -const { logSlashCommand } = vi.hoisted(() => ({ +const { logSlashCommand, SlashCommandEvent } = vi.hoisted(() => ({ logSlashCommand: vi.fn(), + SlashCommandEvent: vi.fn((command, subCommand) => ({ command, subCommand })), })); vi.mock('@google/gemini-cli-core', async (importOriginal) => { const original = await importOriginal(); - return { ...original, logSlashCommand, + SlashCommandEvent, getIdeInstaller: vi.fn().mockReturnValue(null), }; }); @@ -24,10 +25,10 @@ const { mockProcessExit } = vi.hoisted(() => ({ })); vi.mock('node:process', () => { - const mockProcess: Partial = { + const mockProcess = { exit: mockProcessExit, - platform: 'sunos', - } as unknown as NodeJS.Process; + platform: 'test-platform', + }; return { ...mockProcess, default: mockProcess, @@ -76,28 +77,22 @@ import { ConfirmShellCommandsActionReturn, SlashCommand, } from '../commands/types.js'; -import { ToolConfirmationOutcome } from '@google/gemini-cli-core'; +import { Config, ToolConfirmationOutcome } from '@google/gemini-cli-core'; import { LoadedSettings } from '../../config/settings.js'; import { MessageType } from '../types.js'; import { BuiltinCommandLoader } from '../../services/BuiltinCommandLoader.js'; import { FileCommandLoader } from '../../services/FileCommandLoader.js'; import { McpPromptLoader } from '../../services/McpPromptLoader.js'; -import { - SlashCommandStatus, - makeFakeConfig, -} from '@google/gemini-cli-core/index.js'; -function createTestCommand( +const createTestCommand = ( overrides: Partial, kind: CommandKind = CommandKind.BUILT_IN, -): SlashCommand { - return { - name: 'test', - description: 'a test command', - kind, - ...overrides, - }; -} +): SlashCommand => ({ + name: 'test', + description: 'a test command', + kind, + ...overrides, +}); describe('useSlashCommandProcessor', () => { const mockAddItem = vi.fn(); @@ -107,7 +102,15 @@ describe('useSlashCommandProcessor', () => { const mockOpenAuthDialog = vi.fn(); const mockSetQuittingMessages = vi.fn(); - const mockConfig = makeFakeConfig({}); + const mockConfig = { + getProjectRoot: vi.fn(() => '/mock/cwd'), + getSessionId: vi.fn(() => 'test-session'), + getGeminiClient: vi.fn(() => ({ + setHistory: vi.fn().mockResolvedValue(undefined), + })), + getExtensions: vi.fn(() => []), + getIdeMode: vi.fn(() => false), + } as unknown as Config; const mockSettings = {} as LoadedSettings; @@ -881,9 +884,7 @@ describe('useSlashCommandProcessor', () => { const loggingTestCommands: SlashCommand[] = [ createTestCommand({ name: 'logtest', - action: vi - .fn() - .mockResolvedValue({ type: 'message', content: 'hello world' }), + action: mockCommandAction, }), createTestCommand({ name: 'logwithsub', @@ -894,10 +895,6 @@ describe('useSlashCommandProcessor', () => { }), ], }), - createTestCommand({ - name: 'fail', - action: vi.fn().mockRejectedValue(new Error('oh no!')), - }), createTestCommand({ name: 'logalias', altNames: ['la'], @@ -908,6 +905,7 @@ describe('useSlashCommandProcessor', () => { beforeEach(() => { mockCommandAction.mockClear(); vi.mocked(logSlashCommand).mockClear(); + vi.mocked(SlashCommandEvent).mockClear(); }); it('should log a simple slash command', async () => { @@ -919,45 +917,8 @@ describe('useSlashCommandProcessor', () => { await result.current.handleSlashCommand('/logtest'); }); - expect(logSlashCommand).toHaveBeenCalledWith( - mockConfig, - expect.objectContaining({ - command: 'logtest', - subcommand: undefined, - status: SlashCommandStatus.SUCCESS, - }), - ); - }); - - it('logs nothing for a bogus command', async () => { - const result = setupProcessorHook(loggingTestCommands); - await waitFor(() => - expect(result.current.slashCommands.length).toBeGreaterThan(0), - ); - await act(async () => { - await result.current.handleSlashCommand('/bogusbogusbogus'); - }); - - expect(logSlashCommand).not.toHaveBeenCalled(); - }); - - it('logs a failure event for a failed command', async () => { - const result = setupProcessorHook(loggingTestCommands); - await waitFor(() => - expect(result.current.slashCommands.length).toBeGreaterThan(0), - ); - await act(async () => { - await result.current.handleSlashCommand('/fail'); - }); - - expect(logSlashCommand).toHaveBeenCalledWith( - mockConfig, - expect.objectContaining({ - command: 'fail', - status: 'error', - subcommand: undefined, - }), - ); + expect(logSlashCommand).toHaveBeenCalledTimes(1); + expect(SlashCommandEvent).toHaveBeenCalledWith('logtest', undefined); }); it('should log a slash command with a subcommand', async () => { @@ -969,13 +930,8 @@ describe('useSlashCommandProcessor', () => { await result.current.handleSlashCommand('/logwithsub sub'); }); - expect(logSlashCommand).toHaveBeenCalledWith( - mockConfig, - expect.objectContaining({ - command: 'logwithsub', - subcommand: 'sub', - }), - ); + expect(logSlashCommand).toHaveBeenCalledTimes(1); + expect(SlashCommandEvent).toHaveBeenCalledWith('logwithsub', 'sub'); }); it('should log the command path when an alias is used', async () => { @@ -986,12 +942,8 @@ describe('useSlashCommandProcessor', () => { await act(async () => { await result.current.handleSlashCommand('/la'); }); - expect(logSlashCommand).toHaveBeenCalledWith( - mockConfig, - expect.objectContaining({ - command: 'logalias', - }), - ); + expect(logSlashCommand).toHaveBeenCalledTimes(1); + expect(SlashCommandEvent).toHaveBeenCalledWith('logalias', undefined); }); it('should not log for unknown commands', async () => { -- cgit v1.2.3