feat(gateway): wire safe-point runtime cancellation for agent.cancel

This commit is contained in:
William Valentin
2026-02-13 08:51:14 -08:00
parent 9f81c01603
commit 46099664f0
7 changed files with 182 additions and 26 deletions
+14 -1
View File
@@ -251,6 +251,7 @@ describe('agent handlers', () => {
getAgent: vi.fn(() => mockAgent),
getSessionId: vi.fn(() => 'ws:conn-1'),
isBusy: vi.fn(() => false),
cancel: vi.fn(() => false),
setBusy: vi.fn(),
setOnToolUse: vi.fn(),
};
@@ -265,6 +266,7 @@ describe('agent handlers', () => {
beforeEach(() => {
vi.clearAllMocks();
mockBridge.isBusy.mockReturnValue(false);
mockBridge.cancel.mockReturnValue(false);
mockBridge.getAgent.mockReturnValue(mockAgent);
mockAgent.process.mockResolvedValue('response text');
});
@@ -399,11 +401,22 @@ describe('agent handlers', () => {
});
it('agent.cancel returns cancelled state', async () => {
mockBridge.isBusy.mockReturnValue(true);
mockBridge.cancel.mockReturnValue(true);
const req: GatewayRequest = { id: 7, method: 'agent.cancel', params: { connectionId: 'conn-1' } };
const result = await handlers['agent.cancel'](req) as GatewayResponse;
expect((result.result as any).cancelled).toBe(true);
expect((result.result as any).message).toContain('Cancellation requested');
expect(mockBridge.cancel).toHaveBeenCalledWith('conn-1');
});
it('agent.cancel returns not-cancelled when no active operation exists', async () => {
mockBridge.cancel.mockReturnValue(false);
const req: GatewayRequest = { id: 8, method: 'agent.cancel', params: { connectionId: 'conn-1' } };
const result = await handlers['agent.cancel'](req) as GatewayResponse;
expect((result.result as any).cancelled).toBe(false);
expect((result.result as any).message).toContain('No active operation');
});
});