Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(test): correct test assertion for chat service response

Steven Enamakelc6c957b0a619
diff --git a/app/src/services/__tests__/chatService.test.ts b/app/src/services/__tests__/chatService.test.ts
index 62f1e3c7cc..cfc2f27465 100644
--- a/app/src/services/__tests__/chatService.test.ts
+++ b/app/src/services/__tests__/chatService.test.ts
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
-import { chatClearQueue, chatSend, subscribeChatEvents } from '../chatService';
+import { chatCancel, chatClearQueue, chatSend, subscribeChatEvents } from '../chatService';
import { socketService } from '../socketService';
const mockCallCoreRpc = vi.fn();
@@ -458,3 +458,36 @@ describe('chatService.chatClearQueue', () => {
expect(await chatClearQueue('thread-9')).toBeNull();
});
});
+
+describe('chatService.chatCancel', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ bindMockSocket(createMockSocket());
+ });
+
+ it('reports a torn-down turn when the core returns its request id', async () => {
+ mockCallCoreRpc.mockResolvedValue({ cancelled: true, request_id: 'req-1' });
+
+ expect(await chatCancel('thread-9')).toEqual({ accepted: true, turnCancelled: true });
+ expect(mockCallCoreRpc).toHaveBeenCalledWith({
+ method: 'openhuman.channel_web_cancel',
+ params: { client_id: 'socket-1', thread_id: 'thread-9' },
+ });
+ });
+
+ it('reports no turn when the core had nothing in flight', async () => {
+ mockCallCoreRpc.mockResolvedValue({ cancelled: true, request_id: null, subagents_cancelled: 2 });
+ expect(await chatCancel('thread-9')).toEqual({ accepted: true, turnCancelled: false });
+ });
+
+ it('is not accepted when the RPC throws', async () => {
+ mockCallCoreRpc.mockRejectedValue(new Error('rpc down'));
+ expect(await chatCancel('thread-9')).toEqual({ accepted: false, turnCancelled: false });
+ });
+
+ it('is not accepted without a socket id', async () => {
+ vi.mocked(socketService.getSocket).mockReturnValue(null as never);
+ expect(await chatCancel('thread-9')).toEqual({ accepted: false, turnCancelled: false });
+ expect(mockCallCoreRpc).not.toHaveBeenCalled();
+ });
+});