Skip to content

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

test(providers): cover message converter stability across turns

Steven Enamakelc20f0d3e5033
diff --git a/app/src/providers/__tests__/nextTurnRuntime.test.tsx b/app/src/providers/__tests__/nextTurnRuntime.test.tsx
new file mode 100644
index 0000000000..f4f237fb20
--- /dev/null
+++ b/app/src/providers/__tests__/nextTurnRuntime.test.tsx
@@ -0,0 +1,36 @@
+import { AssistantRuntimeProvider, useAuiState, useExternalStoreRuntime, ThreadPrimitive } from '@assistant-ui/react';
+import { render, screen } from '@testing-library/react';
+import { describe, expect, it } from 'vitest';
+import type { ThreadMessage } from '../../types/thread';
+import { buildRuntimeMessages } from '../assistantUiMessages';
+
+const convertMessage = (message: ReturnType<typeof buildRuntimeMessages>[number]) => message;
+const onNew = async () => {};
+const row = (id: string, sender: 'user' | 'agent', content: string, requestId?: string): ThreadMessage => ({id, sender, content, type: 'text', createdAt: '2026-10-10T00:00:00Z', extraMetadata: requestId ? {requestId} : {}});
+function Message() {
+ const state = useAuiState(s => ({id: s.message.id, branches: s.message.branchCount}));
+ return <span data-testid={state.id}>{state.branches}</span>;
+}
+function State() {
+ const ids = useAuiState(s => s.thread.messages.map(message => message.id).join(','));
+ return <><output data-testid="order">{ids}</output><ThreadPrimitive.Messages>{() => <Message />}</ThreadPrimitive.Messages></>;
+}
+function Harness({history, requestId}: {history: ThreadMessage[]; requestId?: string}) {
+ const messages = buildRuntimeMessages(history, requestId ? {requestId, content: 'Streaming reply', thinking: ''} : null, {isRunning: Boolean(requestId), liveRequestId: requestId});
+ const runtime = useExternalStoreRuntime({messages, convertMessage, onNew, isRunning: Boolean(requestId)});
+ return <AssistantRuntimeProvider runtime={runtime}><State /></AssistantRuntimeProvider>;
+}
+describe('assistant-ui next-turn repository', () => {
+ it('keeps the reply identity on settlement and cannot reparent a previous tail into the next turn', () => {
+ const history = [row('user-1', 'user', 'first')];
+ const {rerender} = render(<Harness history={history} requestId="r1" />);
+ expect(screen.getByTestId('order')).toHaveTextContent('user-1,agent:r1');
+ const settled = [...history, row('agent:r1', 'agent', 'First final reply', 'r1')];
+ rerender(<Harness history={settled} />);
+ expect(screen.getByTestId('agent:r1')).toHaveTextContent('1');
+ rerender(<Harness history={[...settled, row('user-2', 'user', 'try now')]} requestId="r2" />);
+ expect(screen.getByTestId('order')).toHaveTextContent('user-1,agent:r1,user-2,agent:r2');
+ expect(screen.getByTestId('agent:r1')).toHaveTextContent('1');
+ expect(screen.getByTestId('agent:r2')).toHaveTextContent('1');
+ });
+});
diff --git a/app/src/providers/__tests__/useOpenHumanExternalStore.identity.test.tsx b/app/src/providers/__tests__/useOpenHumanExternalStore.identity.test.tsx
index 3e719b67f2..4e832ee3ae 100644
--- a/app/src/providers/__tests__/useOpenHumanExternalStore.identity.test.tsx
+++ b/app/src/providers/__tests__/useOpenHumanExternalStore.identity.test.tsx
@@ -1,11 +1,11 @@
import { configureStore } from '@reduxjs/toolkit';
-import { renderHook } from '@testing-library/react';
+import { act, 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 threadReducer, {addMessageLocal} from '../../store/threadSlice';
import { useOpenHumanExternalStore } from '../useOpenHumanExternalStore';
vi.mock('../../services/api/threadApi', () => ({
@@ -31,3 +31,13 @@ describe('assistant-ui thread identity', () => {
expect(result.current.adapters).toMatchObject({ threadList: { threadId: undefined } });
});
});
+
+
+it('keeps the native message converter stable when the next turn changes the adapter', async () => {
+ const store = configureStore({reducer: {thread: threadReducer, chatRuntime: chatRuntimeReducer}});
+ const wrapper = ({children}: {children: ReactNode}) => <Provider store={store}>{children}</Provider>;
+ const {result} = renderHook(() => useOpenHumanExternalStore('test'), {wrapper});
+ const convert = result.current.convertMessage;
+ await act(async () => store.dispatch({type: addMessageLocal.fulfilled.type, payload: {threadId: 'test', message: {id: 'try-now', sender: 'user', type: 'text', content: 'try now', createdAt: '2026-10-10T00:00:00Z', extraMetadata: {}}}}));
+ expect(result.current.convertMessage).toBe(convert);
+});