mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 20:14:44 -07:00
feat(hooks): reduce log verbosity and improve error reporting in UI (#15297)
This commit is contained in:
@@ -27,10 +27,19 @@ const mockDebugLogger = vi.hoisted(() => ({
|
||||
debug: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock coreEvents
|
||||
const mockCoreEvents = vi.hoisted(() => ({
|
||||
emitFeedback: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../utils/debugLogger.js', () => ({
|
||||
debugLogger: mockDebugLogger,
|
||||
}));
|
||||
|
||||
vi.mock('../utils/events.js', () => ({
|
||||
coreEvents: mockCoreEvents,
|
||||
}));
|
||||
|
||||
describe('HookEventHandler', () => {
|
||||
let hookEventHandler: HookEventHandler;
|
||||
let mockConfig: Config;
|
||||
@@ -167,6 +176,53 @@ describe('HookEventHandler', () => {
|
||||
expect(result.errors[0].message).toBe('Planning failed');
|
||||
expect(mockDebugLogger.error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit feedback when some hooks fail', async () => {
|
||||
const mockPlan = [
|
||||
{
|
||||
type: HookType.Command,
|
||||
command: './fail.sh',
|
||||
} as HookConfig,
|
||||
];
|
||||
const mockResults: HookExecutionResult[] = [
|
||||
{
|
||||
success: false,
|
||||
duration: 50,
|
||||
hookConfig: mockPlan[0],
|
||||
eventName: HookEventName.BeforeTool,
|
||||
error: new Error('Failed to execute'),
|
||||
},
|
||||
];
|
||||
const mockAggregated = {
|
||||
success: false,
|
||||
allOutputs: [],
|
||||
errors: [new Error('Failed to execute')],
|
||||
totalDuration: 50,
|
||||
};
|
||||
|
||||
vi.mocked(mockHookPlanner.createExecutionPlan).mockReturnValue({
|
||||
eventName: HookEventName.BeforeTool,
|
||||
hookConfigs: mockPlan,
|
||||
sequential: false,
|
||||
});
|
||||
vi.mocked(mockHookRunner.executeHooksParallel).mockResolvedValue(
|
||||
mockResults,
|
||||
);
|
||||
vi.mocked(mockHookAggregator.aggregateResults).mockReturnValue(
|
||||
mockAggregated,
|
||||
);
|
||||
|
||||
await hookEventHandler.fireBeforeToolEvent('EditTool', {});
|
||||
|
||||
expect(mockCoreEvents.emitFeedback).toHaveBeenCalledWith(
|
||||
'warning',
|
||||
expect.stringContaining('./fail.sh'),
|
||||
);
|
||||
expect(mockCoreEvents.emitFeedback).toHaveBeenCalledWith(
|
||||
'warning',
|
||||
expect.stringContaining('F12'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fireAfterToolEvent', () => {
|
||||
|
||||
Reference in New Issue
Block a user