style(cli) : Dialog pattern for /hooks Command (#17930)

This commit is contained in:
Abdul Tawab
2026-03-03 02:12:05 +05:00
committed by GitHub
parent 7ca3a33f8b
commit 1502e5cbc3
8 changed files with 653 additions and 187 deletions
@@ -7,7 +7,6 @@
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
import { hooksCommand } from './hooksCommand.js';
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
import { MessageType } from '../types.js';
import type { HookRegistryEntry } from '@google/gemini-cli-core';
import { HookType, HookEventName, ConfigSource } from '@google/gemini-cli-core';
import type { CommandContext } from './types.js';
@@ -127,13 +126,10 @@ describe('hooksCommand', () => {
createMockHook('test-hook', HookEventName.BeforeTool, true),
]);
await hooksCommand.action(mockContext, '');
const result = await hooksCommand.action(mockContext, '');
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({
type: MessageType.HOOKS_LIST,
}),
);
expect(result).toHaveProperty('type', 'custom_dialog');
expect(result).toHaveProperty('component');
});
});
@@ -161,7 +157,7 @@ describe('hooksCommand', () => {
});
});
it('should display panel even when hook system is not enabled', async () => {
it('should return custom_dialog even when hook system is not enabled', async () => {
mockConfig.getHookSystem.mockReturnValue(null);
const panelCmd = hooksCommand.subCommands!.find(
@@ -171,17 +167,13 @@ describe('hooksCommand', () => {
throw new Error('panel command must have an action');
}
await panelCmd.action(mockContext, '');
const result = await panelCmd.action(mockContext, '');
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({
type: MessageType.HOOKS_LIST,
hooks: [],
}),
);
expect(result).toHaveProperty('type', 'custom_dialog');
expect(result).toHaveProperty('component');
});
it('should display panel when no hooks are configured', async () => {
it('should return custom_dialog when no hooks are configured', async () => {
mockHookSystem.getAllHooks.mockReturnValue([]);
(mockContext.services.settings.merged as Record<string, unknown>)[
'hooksConfig'
@@ -194,17 +186,13 @@ describe('hooksCommand', () => {
throw new Error('panel command must have an action');
}
await panelCmd.action(mockContext, '');
const result = await panelCmd.action(mockContext, '');
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({
type: MessageType.HOOKS_LIST,
hooks: [],
}),
);
expect(result).toHaveProperty('type', 'custom_dialog');
expect(result).toHaveProperty('component');
});
it('should display hooks list when hooks are configured', async () => {
it('should return custom_dialog when hooks are configured', async () => {
const mockHooks: HookRegistryEntry[] = [
createMockHook('echo-test', HookEventName.BeforeTool, true),
createMockHook('notify', HookEventName.AfterAgent, false),
@@ -222,14 +210,10 @@ describe('hooksCommand', () => {
throw new Error('panel command must have an action');
}
await panelCmd.action(mockContext, '');
const result = await panelCmd.action(mockContext, '');
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({
type: MessageType.HOOKS_LIST,
hooks: mockHooks,
}),
);
expect(result).toHaveProperty('type', 'custom_dialog');
expect(result).toHaveProperty('component');
});
});