Skip to content

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

test(providers): add identity tests for useOpenHumanExternalStore

Steven Enamakel55c87579636a
diff --git a/app/src/providers/__tests__/useOpenHumanExternalStore.identity.test.tsx b/app/src/providers/__tests__/useOpenHumanExternalStore.identity.test.tsx
new file mode 100644
index 0000000000..d66cfba1e7
--- /dev/null
+++ b/app/src/providers/__tests__/useOpenHumanExternalStore.identity.test.tsx
@@ -0,0 +1,29 @@
+import { configureStore } from '@reduxjs/toolkit';
+import { renderHook } from '@testing-library/react';
+import type { ReactNode } from 'react';
+import { Provider } from 'react-redux';
+import { describe, expect, it, vi } from 'vitest';
+
+import chatRuntimeReducer from '../../store/chatRuntimeSlice';
+import threadReducer from '../../store/threadSlice';
+import { useOpenHumanExternalStore } from '../useOpenHumanExternalStore';
+
+vi.mock('../../services/api/threadApi', () => ({
+ threadApi: { getDerivedTranscript: vi.fn().mockResolvedValue({ items: [], nextCursor: null }) },
+}));
+
+describe('assistant-ui thread identity', () => {
+ it('projects the real thread id so native thread switching can reset the viewport', () => {
+ const store = configureStore({ reducer: { thread: threadReducer, chatRuntime: chatRuntimeReducer } });
+ const wrapper = ({ children }: { children: ReactNode }) => <Provider store={store}>{children}</Provider>;
+ const { result, rerender } = renderHook(
+ ({ threadId }: { threadId: string | null }) => useOpenHumanExternalStore(threadId),
+ { wrapper, initialProps: { threadId: 'first' as string | null } }
+ );
+ expect(result.current.adapters).toMatchObject({ threadList: { threadId: 'first' } });
+ rerender({ threadId: 'second' });
+ expect(result.current.adapters).toMatchObject({ threadList: { threadId: 'second' } });
+ rerender({ threadId: null });
+ expect(result.current.adapters).toMatchObject({ threadList: { threadId: undefined } });
+ });
+});