2025-05-16 16:36:50 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const { mockProcessExit } = vi.hoisted(() => ({
|
|
|
|
|
mockProcessExit: vi.fn((_code?: number): never => undefined as never),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
vi.mock('node:process', () => ({
|
2025-05-30 22:18:01 +00:00
|
|
|
default: {
|
|
|
|
|
exit: mockProcessExit,
|
|
|
|
|
cwd: vi.fn(() => '/mock/cwd'),
|
|
|
|
|
get env() {
|
|
|
|
|
return process.env;
|
2025-07-17 19:40:36 -04:00
|
|
|
},
|
2025-05-30 22:18:01 +00:00
|
|
|
platform: 'test-platform',
|
|
|
|
|
version: 'test-node-version',
|
|
|
|
|
memoryUsage: vi.fn(() => ({
|
|
|
|
|
rss: 12345678,
|
|
|
|
|
heapTotal: 23456789,
|
|
|
|
|
heapUsed: 10234567,
|
|
|
|
|
external: 1234567,
|
|
|
|
|
arrayBuffers: 123456,
|
|
|
|
|
})),
|
|
|
|
|
},
|
2025-05-16 16:36:50 -07:00
|
|
|
exit: mockProcessExit,
|
|
|
|
|
cwd: vi.fn(() => '/mock/cwd'),
|
2025-05-30 22:18:01 +00:00
|
|
|
get env() {
|
|
|
|
|
return process.env;
|
2025-07-17 19:40:36 -04:00
|
|
|
},
|
2025-05-30 22:18:01 +00:00
|
|
|
platform: 'test-platform',
|
|
|
|
|
version: 'test-node-version',
|
|
|
|
|
memoryUsage: vi.fn(() => ({
|
|
|
|
|
rss: 12345678,
|
|
|
|
|
heapTotal: 23456789,
|
|
|
|
|
heapUsed: 10234567,
|
|
|
|
|
external: 1234567,
|
|
|
|
|
arrayBuffers: 123456,
|
|
|
|
|
})),
|
2025-05-16 16:36:50 -07:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
vi.mock('node:fs/promises', () => ({
|
|
|
|
|
readFile: vi.fn(),
|
|
|
|
|
writeFile: vi.fn(),
|
|
|
|
|
mkdir: vi.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
2025-06-18 09:57:17 -07:00
|
|
|
const mockGetCliVersionFn = vi.fn(() => Promise.resolve('0.1.0'));
|
2025-06-15 16:35:15 -04:00
|
|
|
vi.mock('../../utils/version.js', () => ({
|
|
|
|
|
getCliVersion: (...args: []) => mockGetCliVersionFn(...args),
|
|
|
|
|
}));
|
|
|
|
|
|
2025-05-16 16:36:50 -07:00
|
|
|
import { act, renderHook } from '@testing-library/react';
|
2025-07-16 22:40:56 -04:00
|
|
|
import { vi, describe, it, expect, beforeEach, beforeAll, Mock } from 'vitest';
|
2025-05-19 16:56:32 -07:00
|
|
|
import open from 'open';
|
2025-07-07 16:45:44 -04:00
|
|
|
import { useSlashCommandProcessor } from './slashCommandProcessor.js';
|
2025-07-16 16:12:22 -04:00
|
|
|
import { SlashCommandProcessorResult } from '../types.js';
|
2025-07-15 22:35:05 -04:00
|
|
|
import { Config, GeminiClient } from '@google/gemini-cli-core';
|
2025-06-09 20:25:37 -04:00
|
|
|
import { useSessionStats } from '../contexts/SessionContext.js';
|
2025-06-21 12:15:43 -07:00
|
|
|
import { LoadedSettings } from '../../config/settings.js';
|
2025-05-16 16:36:50 -07:00
|
|
|
import * as ShowMemoryCommandModule from './useShowMemoryCommand.js';
|
2025-07-07 16:45:44 -04:00
|
|
|
import { CommandService } from '../../services/CommandService.js';
|
|
|
|
|
import { SlashCommand } from '../commands/types.js';
|
2025-05-16 16:36:50 -07:00
|
|
|
|
2025-06-08 18:01:02 -04:00
|
|
|
vi.mock('../contexts/SessionContext.js', () => ({
|
2025-06-09 20:25:37 -04:00
|
|
|
useSessionStats: vi.fn(),
|
2025-06-08 18:01:02 -04:00
|
|
|
}));
|
|
|
|
|
|
2025-07-07 16:45:44 -04:00
|
|
|
vi.mock('../../services/CommandService.js');
|
|
|
|
|
|
2025-05-16 16:36:50 -07:00
|
|
|
vi.mock('./useShowMemoryCommand.js', () => ({
|
|
|
|
|
SHOW_MEMORY_COMMAND_NAME: '/memory show',
|
|
|
|
|
createShowMemoryAction: vi.fn(() => vi.fn()),
|
|
|
|
|
}));
|
|
|
|
|
|
2025-05-19 16:56:32 -07:00
|
|
|
vi.mock('open', () => ({
|
|
|
|
|
default: vi.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
2025-07-07 16:45:44 -04:00
|
|
|
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
|
|
|
|
const actual =
|
|
|
|
|
await importOriginal<typeof import('@google/gemini-cli-core')>();
|
|
|
|
|
return {
|
|
|
|
|
...actual,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-16 16:36:50 -07:00
|
|
|
describe('useSlashCommandProcessor', () => {
|
|
|
|
|
let mockAddItem: ReturnType<typeof vi.fn>;
|
|
|
|
|
let mockClearItems: ReturnType<typeof vi.fn>;
|
2025-06-11 15:33:09 -04:00
|
|
|
let mockLoadHistory: ReturnType<typeof vi.fn>;
|
2025-05-16 16:36:50 -07:00
|
|
|
let mockRefreshStatic: ReturnType<typeof vi.fn>;
|
|
|
|
|
let mockSetShowHelp: ReturnType<typeof vi.fn>;
|
|
|
|
|
let mockOnDebugMessage: ReturnType<typeof vi.fn>;
|
|
|
|
|
let mockOpenThemeDialog: ReturnType<typeof vi.fn>;
|
2025-06-19 16:52:22 -07:00
|
|
|
let mockOpenAuthDialog: ReturnType<typeof vi.fn>;
|
2025-06-12 02:21:54 +01:00
|
|
|
let mockOpenEditorDialog: ReturnType<typeof vi.fn>;
|
2025-06-11 20:08:32 -04:00
|
|
|
let mockSetQuittingMessages: ReturnType<typeof vi.fn>;
|
2025-06-13 21:21:40 -07:00
|
|
|
let mockTryCompressChat: ReturnType<typeof vi.fn>;
|
|
|
|
|
let mockGeminiClient: GeminiClient;
|
2025-05-16 16:36:50 -07:00
|
|
|
let mockConfig: Config;
|
2025-05-17 21:57:27 -07:00
|
|
|
let mockCorgiMode: ReturnType<typeof vi.fn>;
|
2025-06-09 20:25:37 -04:00
|
|
|
const mockUseSessionStats = useSessionStats as Mock;
|
2025-05-16 16:36:50 -07:00
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2025-07-07 16:45:44 -04:00
|
|
|
vi.clearAllMocks();
|
|
|
|
|
|
2025-05-16 16:36:50 -07:00
|
|
|
mockAddItem = vi.fn();
|
|
|
|
|
mockClearItems = vi.fn();
|
2025-06-11 15:33:09 -04:00
|
|
|
mockLoadHistory = vi.fn();
|
2025-05-16 16:36:50 -07:00
|
|
|
mockRefreshStatic = vi.fn();
|
|
|
|
|
mockSetShowHelp = vi.fn();
|
|
|
|
|
mockOnDebugMessage = vi.fn();
|
|
|
|
|
mockOpenThemeDialog = vi.fn();
|
2025-06-19 16:52:22 -07:00
|
|
|
mockOpenAuthDialog = vi.fn();
|
2025-06-12 02:21:54 +01:00
|
|
|
mockOpenEditorDialog = vi.fn();
|
2025-06-11 20:08:32 -04:00
|
|
|
mockSetQuittingMessages = vi.fn();
|
2025-06-13 21:21:40 -07:00
|
|
|
mockTryCompressChat = vi.fn();
|
|
|
|
|
mockGeminiClient = {
|
|
|
|
|
tryCompressChat: mockTryCompressChat,
|
|
|
|
|
} as unknown as GeminiClient;
|
2025-05-19 16:56:32 -07:00
|
|
|
mockConfig = {
|
|
|
|
|
getDebugMode: vi.fn(() => false),
|
2025-06-13 21:21:40 -07:00
|
|
|
getGeminiClient: () => mockGeminiClient,
|
2025-05-23 08:47:19 -07:00
|
|
|
getSandbox: vi.fn(() => 'test-sandbox'),
|
|
|
|
|
getModel: vi.fn(() => 'test-model'),
|
2025-06-11 15:33:09 -04:00
|
|
|
getProjectRoot: vi.fn(() => '/test/dir'),
|
2025-06-20 00:39:15 -04:00
|
|
|
getCheckpointingEnabled: vi.fn(() => true),
|
2025-06-14 00:00:24 -07:00
|
|
|
getBugCommand: vi.fn(() => undefined),
|
2025-07-07 16:45:44 -04:00
|
|
|
getSessionId: vi.fn(() => 'test-session-id'),
|
2025-07-16 18:36:14 -04:00
|
|
|
getIdeMode: vi.fn(() => false),
|
2025-05-19 16:56:32 -07:00
|
|
|
} as unknown as Config;
|
2025-05-17 21:57:27 -07:00
|
|
|
mockCorgiMode = vi.fn();
|
2025-06-09 20:25:37 -04:00
|
|
|
mockUseSessionStats.mockReturnValue({
|
|
|
|
|
stats: {
|
|
|
|
|
sessionStartTime: new Date('2025-01-01T00:00:00.000Z'),
|
|
|
|
|
cumulative: {
|
2025-07-10 00:19:30 +05:30
|
|
|
promptCount: 0,
|
2025-06-09 20:25:37 -04:00
|
|
|
promptTokenCount: 0,
|
|
|
|
|
candidatesTokenCount: 0,
|
|
|
|
|
totalTokenCount: 0,
|
|
|
|
|
cachedContentTokenCount: 0,
|
|
|
|
|
toolUsePromptTokenCount: 0,
|
|
|
|
|
thoughtsTokenCount: 0,
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-06-08 18:01:02 -04:00
|
|
|
});
|
2025-05-16 16:36:50 -07:00
|
|
|
|
2025-05-19 16:56:32 -07:00
|
|
|
(open as Mock).mockClear();
|
2025-05-16 16:36:50 -07:00
|
|
|
mockProcessExit.mockClear();
|
|
|
|
|
(ShowMemoryCommandModule.createShowMemoryAction as Mock).mockClear();
|
2025-05-23 08:47:19 -07:00
|
|
|
process.env = { ...globalThis.process.env };
|
2025-05-16 16:36:50 -07:00
|
|
|
});
|
|
|
|
|
|
2025-07-16 16:12:22 -04:00
|
|
|
const getProcessorHook = () => {
|
2025-06-21 12:15:43 -07:00
|
|
|
const settings = {
|
|
|
|
|
merged: {
|
|
|
|
|
contextFileName: 'GEMINI.md',
|
|
|
|
|
},
|
2025-07-07 16:45:44 -04:00
|
|
|
} as unknown as LoadedSettings;
|
2025-06-21 12:15:43 -07:00
|
|
|
return renderHook(() =>
|
2025-05-16 16:36:50 -07:00
|
|
|
useSlashCommandProcessor(
|
|
|
|
|
mockConfig,
|
2025-06-21 12:15:43 -07:00
|
|
|
settings,
|
2025-05-16 16:36:50 -07:00
|
|
|
mockAddItem,
|
|
|
|
|
mockClearItems,
|
2025-06-11 15:33:09 -04:00
|
|
|
mockLoadHistory,
|
2025-05-16 16:36:50 -07:00
|
|
|
mockRefreshStatic,
|
|
|
|
|
mockSetShowHelp,
|
|
|
|
|
mockOnDebugMessage,
|
|
|
|
|
mockOpenThemeDialog,
|
2025-06-19 16:52:22 -07:00
|
|
|
mockOpenAuthDialog,
|
2025-06-12 02:21:54 +01:00
|
|
|
mockOpenEditorDialog,
|
2025-05-17 21:57:27 -07:00
|
|
|
mockCorgiMode,
|
2025-06-11 20:08:32 -04:00
|
|
|
mockSetQuittingMessages,
|
2025-07-07 16:45:44 -04:00
|
|
|
vi.fn(), // mockOpenPrivacyNotice
|
2025-05-16 16:36:50 -07:00
|
|
|
),
|
|
|
|
|
);
|
2025-06-21 12:15:43 -07:00
|
|
|
};
|
2025-06-17 08:44:54 -07:00
|
|
|
|
2025-07-17 19:40:36 -04:00
|
|
|
describe('Command Processing', () => {
|
2025-07-07 16:45:44 -04:00
|
|
|
let ActualCommandService: typeof CommandService;
|
2025-06-16 02:33:59 -04:00
|
|
|
|
2025-07-07 16:45:44 -04:00
|
|
|
beforeAll(async () => {
|
|
|
|
|
const actual = (await vi.importActual(
|
|
|
|
|
'../../services/CommandService.js',
|
|
|
|
|
)) as { CommandService: typeof CommandService };
|
|
|
|
|
ActualCommandService = actual.CommandService;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-17 19:40:36 -04:00
|
|
|
it('should execute a registered command', async () => {
|
2025-07-07 16:45:44 -04:00
|
|
|
const mockAction = vi.fn();
|
|
|
|
|
const newCommand: SlashCommand = { name: 'test', action: mockAction };
|
|
|
|
|
const mockLoader = async () => [newCommand];
|
|
|
|
|
|
|
|
|
|
// We create the instance outside the mock implementation.
|
2025-07-16 18:36:14 -04:00
|
|
|
const commandServiceInstance = new ActualCommandService(
|
|
|
|
|
mockConfig,
|
|
|
|
|
mockLoader,
|
|
|
|
|
);
|
2025-07-07 16:45:44 -04:00
|
|
|
|
|
|
|
|
// This mock ensures the hook uses our pre-configured instance.
|
|
|
|
|
vi.mocked(CommandService).mockImplementation(
|
|
|
|
|
() => commandServiceInstance,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { result } = getProcessorHook();
|
|
|
|
|
|
|
|
|
|
await vi.waitFor(() => {
|
|
|
|
|
// We check that the `slashCommands` array, which is the public API
|
|
|
|
|
// of our hook, eventually contains the command we injected.
|
|
|
|
|
expect(
|
|
|
|
|
result.current.slashCommands.some((c) => c.name === 'test'),
|
|
|
|
|
).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let commandResult: SlashCommandProcessorResult | false = false;
|
2025-06-16 02:33:59 -04:00
|
|
|
await act(async () => {
|
2025-07-07 16:45:44 -04:00
|
|
|
commandResult = await result.current.handleSlashCommand('/test');
|
2025-06-16 02:33:59 -04:00
|
|
|
});
|
|
|
|
|
|
2025-07-07 16:45:44 -04:00
|
|
|
expect(mockAction).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(commandResult).toEqual({ type: 'handled' });
|
2025-06-16 02:33:59 -04:00
|
|
|
});
|
|
|
|
|
|
2025-07-17 19:40:36 -04:00
|
|
|
it('should return "schedule_tool" for a command returning a tool action', async () => {
|
2025-07-07 16:45:44 -04:00
|
|
|
const mockAction = vi.fn().mockResolvedValue({
|
|
|
|
|
type: 'tool',
|
|
|
|
|
toolName: 'my_tool',
|
|
|
|
|
toolArgs: { arg1: 'value1' },
|
|
|
|
|
});
|
|
|
|
|
const newCommand: SlashCommand = { name: 'test', action: mockAction };
|
|
|
|
|
const mockLoader = async () => [newCommand];
|
2025-07-16 18:36:14 -04:00
|
|
|
const commandServiceInstance = new ActualCommandService(
|
|
|
|
|
mockConfig,
|
|
|
|
|
mockLoader,
|
|
|
|
|
);
|
2025-07-07 16:45:44 -04:00
|
|
|
vi.mocked(CommandService).mockImplementation(
|
|
|
|
|
() => commandServiceInstance,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { result } = getProcessorHook();
|
|
|
|
|
await vi.waitFor(() => {
|
|
|
|
|
expect(
|
|
|
|
|
result.current.slashCommands.some((c) => c.name === 'test'),
|
|
|
|
|
).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const commandResult = await result.current.handleSlashCommand('/test');
|
|
|
|
|
|
|
|
|
|
expect(mockAction).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(commandResult).toEqual({
|
|
|
|
|
type: 'schedule_tool',
|
|
|
|
|
toolName: 'my_tool',
|
|
|
|
|
toolArgs: { arg1: 'value1' },
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-17 19:40:36 -04:00
|
|
|
it('should return "handled" for a command returning a message action', async () => {
|
2025-07-07 16:45:44 -04:00
|
|
|
const mockAction = vi.fn().mockResolvedValue({
|
|
|
|
|
type: 'message',
|
|
|
|
|
messageType: 'info',
|
|
|
|
|
content: 'This is a message',
|
|
|
|
|
});
|
|
|
|
|
const newCommand: SlashCommand = { name: 'test', action: mockAction };
|
|
|
|
|
const mockLoader = async () => [newCommand];
|
2025-07-16 18:36:14 -04:00
|
|
|
const commandServiceInstance = new ActualCommandService(
|
|
|
|
|
mockConfig,
|
|
|
|
|
mockLoader,
|
|
|
|
|
);
|
2025-07-07 16:45:44 -04:00
|
|
|
vi.mocked(CommandService).mockImplementation(
|
|
|
|
|
() => commandServiceInstance,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { result } = getProcessorHook();
|
|
|
|
|
await vi.waitFor(() => {
|
|
|
|
|
expect(
|
|
|
|
|
result.current.slashCommands.some((c) => c.name === 'test'),
|
|
|
|
|
).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const commandResult = await result.current.handleSlashCommand('/test');
|
|
|
|
|
|
|
|
|
|
expect(mockAction).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(mockAddItem).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
type: 'info',
|
|
|
|
|
text: 'This is a message',
|
|
|
|
|
}),
|
|
|
|
|
expect.any(Number),
|
|
|
|
|
);
|
|
|
|
|
expect(commandResult).toEqual({ type: 'handled' });
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-17 19:40:36 -04:00
|
|
|
it('should return "handled" for a command returning a dialog action', async () => {
|
2025-07-07 16:45:44 -04:00
|
|
|
const mockAction = vi.fn().mockResolvedValue({
|
|
|
|
|
type: 'dialog',
|
|
|
|
|
dialog: 'help',
|
|
|
|
|
});
|
|
|
|
|
const newCommand: SlashCommand = { name: 'test', action: mockAction };
|
|
|
|
|
const mockLoader = async () => [newCommand];
|
2025-07-16 18:36:14 -04:00
|
|
|
const commandServiceInstance = new ActualCommandService(
|
|
|
|
|
mockConfig,
|
|
|
|
|
mockLoader,
|
|
|
|
|
);
|
2025-07-07 16:45:44 -04:00
|
|
|
vi.mocked(CommandService).mockImplementation(
|
|
|
|
|
() => commandServiceInstance,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { result } = getProcessorHook();
|
|
|
|
|
await vi.waitFor(() => {
|
|
|
|
|
expect(
|
|
|
|
|
result.current.slashCommands.some((c) => c.name === 'test'),
|
|
|
|
|
).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const commandResult = await result.current.handleSlashCommand('/test');
|
|
|
|
|
|
|
|
|
|
expect(mockAction).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(mockSetShowHelp).toHaveBeenCalledWith(true);
|
|
|
|
|
expect(commandResult).toEqual({ type: 'handled' });
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-17 19:40:36 -04:00
|
|
|
it('should open the auth dialog for a command returning an auth dialog action', async () => {
|
2025-07-14 12:22:37 -04:00
|
|
|
const mockAction = vi.fn().mockResolvedValue({
|
|
|
|
|
type: 'dialog',
|
|
|
|
|
dialog: 'auth',
|
|
|
|
|
});
|
|
|
|
|
const newAuthCommand: SlashCommand = { name: 'auth', action: mockAction };
|
|
|
|
|
|
|
|
|
|
const mockLoader = async () => [newAuthCommand];
|
2025-07-16 18:36:14 -04:00
|
|
|
const commandServiceInstance = new ActualCommandService(
|
|
|
|
|
mockConfig,
|
|
|
|
|
mockLoader,
|
|
|
|
|
);
|
2025-07-14 12:22:37 -04:00
|
|
|
vi.mocked(CommandService).mockImplementation(
|
|
|
|
|
() => commandServiceInstance,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { result } = getProcessorHook();
|
|
|
|
|
await vi.waitFor(() => {
|
|
|
|
|
expect(
|
|
|
|
|
result.current.slashCommands.some((c) => c.name === 'auth'),
|
|
|
|
|
).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const commandResult = await result.current.handleSlashCommand('/auth');
|
|
|
|
|
|
|
|
|
|
expect(mockAction).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(mockOpenAuthDialog).toHaveBeenCalledWith();
|
|
|
|
|
expect(commandResult).toEqual({ type: 'handled' });
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-17 19:40:36 -04:00
|
|
|
it('should open the theme dialog for a command returning a theme dialog action', async () => {
|
2025-07-11 16:01:28 -04:00
|
|
|
const mockAction = vi.fn().mockResolvedValue({
|
|
|
|
|
type: 'dialog',
|
|
|
|
|
dialog: 'theme',
|
|
|
|
|
});
|
|
|
|
|
const newCommand: SlashCommand = { name: 'test', action: mockAction };
|
|
|
|
|
const mockLoader = async () => [newCommand];
|
2025-07-16 18:36:14 -04:00
|
|
|
const commandServiceInstance = new ActualCommandService(
|
|
|
|
|
mockConfig,
|
|
|
|
|
mockLoader,
|
|
|
|
|
);
|
2025-07-11 16:01:28 -04:00
|
|
|
vi.mocked(CommandService).mockImplementation(
|
|
|
|
|
() => commandServiceInstance,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { result } = getProcessorHook();
|
|
|
|
|
await vi.waitFor(() => {
|
|
|
|
|
expect(
|
|
|
|
|
result.current.slashCommands.some((c) => c.name === 'test'),
|
|
|
|
|
).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const commandResult = await result.current.handleSlashCommand('/test');
|
|
|
|
|
|
|
|
|
|
expect(mockAction).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(mockOpenThemeDialog).toHaveBeenCalledWith();
|
|
|
|
|
expect(commandResult).toEqual({ type: 'handled' });
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-07 16:45:44 -04:00
|
|
|
it('should show help for a parent command with no action', async () => {
|
|
|
|
|
const parentCommand: SlashCommand = {
|
|
|
|
|
name: 'parent',
|
|
|
|
|
subCommands: [
|
|
|
|
|
{ name: 'child', description: 'A child.', action: vi.fn() },
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mockLoader = async () => [parentCommand];
|
2025-07-16 18:36:14 -04:00
|
|
|
const commandServiceInstance = new ActualCommandService(
|
|
|
|
|
mockConfig,
|
|
|
|
|
mockLoader,
|
|
|
|
|
);
|
2025-07-07 16:45:44 -04:00
|
|
|
vi.mocked(CommandService).mockImplementation(
|
|
|
|
|
() => commandServiceInstance,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { result } = getProcessorHook();
|
|
|
|
|
|
|
|
|
|
await vi.waitFor(() => {
|
|
|
|
|
expect(
|
|
|
|
|
result.current.slashCommands.some((c) => c.name === 'parent'),
|
|
|
|
|
).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
2025-06-12 02:21:54 +01:00
|
|
|
await act(async () => {
|
2025-07-07 16:45:44 -04:00
|
|
|
await result.current.handleSlashCommand('/parent');
|
2025-06-12 02:21:54 +01:00
|
|
|
});
|
2025-07-07 16:45:44 -04:00
|
|
|
|
|
|
|
|
expect(mockAddItem).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
type: 'info',
|
|
|
|
|
text: expect.stringContaining(
|
|
|
|
|
"Command '/parent' requires a subcommand.",
|
|
|
|
|
),
|
|
|
|
|
}),
|
|
|
|
|
expect.any(Number),
|
|
|
|
|
);
|
2025-06-12 02:21:54 +01:00
|
|
|
});
|
2025-05-16 16:36:50 -07:00
|
|
|
});
|
|
|
|
|
});
|