Skip to content

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

test(chat): cover snapshot polling stop on unmount

Steven Enamakel854882b72b00
diff --git a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
index 678647a15b..9a5121608d 100644
--- a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
+++ b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
@@ -115,6 +115,42 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
});
describe('dedupe', () => {
+ it('stops completed-turn snapshot polling when the provider unmounts', async () => {
+ vi.useFakeTimers();
+ let listeners: chatService.ChatEventListeners = {};
+ vi.mocked(chatService.subscribeChatEvents).mockImplementation(value => {
+ listeners = value;
+ return () => {};
+ });
+ store.dispatch(setStatusForUser({ userId: '__pending__', status: 'connected' }));
+ const view = render(
+ <Provider store={store}>
+ <ChatRuntimeProvider>
+ <div />
+ </ChatRuntimeProvider>
+ </Provider>
+ );
+ try {
+ await act(async () => {
+ listeners.onDone?.({
+ thread_id: 'unmounted-snapshot',
+ request_id: 'unmounted-request',
+ full_response: 'Delivered reply',
+ });
+ });
+ expect(threadApi.getTurnState).toHaveBeenCalledWith('unmounted-snapshot');
+ view.unmount();
+ const callsBeforeUnmount = vi.mocked(threadApi.getTurnState).mock.calls.length;
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(2_000);
+ });
+ expect(threadApi.getTurnState).toHaveBeenCalledTimes(callsBeforeUnmount);
+ } finally {
+ view.unmount();
+ vi.useRealTimers();
+ }
+ });
+
it('finds pending spawn and async delegation tool rows', () => {
const entries = [
{ id: 'ignored', name: 'search', round: 0, status: 'running' },