feat(hooks): reduce log verbosity and improve error reporting in UI (#15297)

This commit is contained in:
Abhi
2025-12-18 19:30:45 -05:00
committed by GitHub
parent 70696e364b
commit 402148dbc4
7 changed files with 84 additions and 17 deletions
@@ -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', () => {