fix(confirmations): guarded-action handling across webchat and tui

This commit is contained in:
William Valentin
2026-02-18 17:43:57 -08:00
parent 7e00cb6b04
commit cdba111831
9 changed files with 199 additions and 52 deletions
+32
View File
@@ -235,6 +235,38 @@ describe('createAgentHandlers command fast-path', () => {
expect(((sent[0] as GatewayEvent).data as { content: string }).content).toBe('agent response');
});
it('handles /approvals command via fast-path when hook engine is available', async () => {
const sent: OutboundMessage[] = [];
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));
const hookEngine = {
getPendingConfirmations: vi.fn(() => []),
resolveConfirmation: vi.fn(() => false),
};
const handlersWithHooks = createAgentHandlers({
sessionBridge: sessionBridge as unknown as AgentHandlerDeps['sessionBridge'],
laneQueue: new LaneQueue(),
sessionManager: sessionManager as unknown as AgentHandlerDeps['sessionManager'],
commandRegistry,
hookEngine: hookEngine as unknown as AgentHandlerDeps['hookEngine'],
});
const req: GatewayRequest = {
id: 11,
method: 'agent.send',
params: {
message: '/approvals',
connectionId: 'conn-1',
metadata: { isCommand: true, command: 'approvals' },
},
};
await handlersWithHooks['agent.send'](req, send);
expect(mockAgent.process).not.toHaveBeenCalled();
expect(hookEngine.getPendingConfirmations).toHaveBeenCalledWith({ sessionId: 'ws:conn-1' });
expect(((sent[0] as GatewayEvent).data as { content: string }).content).toContain('No pending approvals');
});
it('emits user.action audit events for gateway requests', async () => {
const sent: OutboundMessage[] = [];
const send = vi.fn((msg: OutboundMessage) => sent.push(msg));