The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(aui): add tests for plain text component and thread state
Steven Enamakele9c3fe4360f7
diff --git a/app/src/features/conversations/components/aui/AuiPlainText.test.tsx b/app/src/features/conversations/components/aui/AuiPlainText.test.tsxnew file mode 100644index 0000000000..5ad5e828eb--- /dev/null+++ b/app/src/features/conversations/components/aui/AuiPlainText.test.tsx@@ -0,0 +1,37 @@+/**+ * The headless message-part leaf must behave identically with and without an+ * assistant-ui runtime above it.+ *+ * That is not a nicety: `ChatThreadView` is mounted under a bare Redux+ * `Provider` by several unit tests (including the byte-frozen render-cost+ * benchmark), and assistant-ui's default client throws on a direct scope read.+ * `TextMessagePartProvider` synthesises its own `part` scope, which is why this+ * works — and this file is what stops that from silently regressing.+ */+import { render, screen } from '@testing-library/react';+import { describe, expect, it } from 'vitest';++import { AuiPlainText } from './AuiPlainText';++const CARET = <span data-testid="test-caret" />;++describe('AuiPlainText', () => {+ it('renders its text with no runtime mounted', () => {+ render(<AuiPlainText text="hello tail" />);+ expect(screen.getByText('hello tail')).toBeInTheDocument();+ });++ it('shows the in-progress affordance only while the part is running', () => {+ const { rerender } = render(<AuiPlainText text="partial" isRunning caret={CARET} />);+ expect(screen.getByTestId('test-caret')).toBeInTheDocument();++ rerender(<AuiPlainText text="partial" isRunning={false} caret={CARET} />);+ expect(screen.queryByTestId('test-caret')).not.toBeInTheDocument();+ });++ it('omits the in-progress slot entirely when no caret is supplied', () => {+ render(<AuiPlainText text="settled" isRunning />);+ expect(screen.queryByTestId('test-caret')).not.toBeInTheDocument();+ expect(screen.getByText('settled')).toBeInTheDocument();+ });+});diff --git a/app/src/features/conversations/components/aui/auiThreadState.test.tsx b/app/src/features/conversations/components/aui/auiThreadState.test.tsxnew file mode 100644index 0000000000..5162ee1555--- /dev/null+++ b/app/src/features/conversations/components/aui/auiThreadState.test.tsx@@ -0,0 +1,58 @@+/**+ * The runtime reads must degrade, not throw, when no runtime is mounted — and+ * must report the ADAPTER's real capabilities when one is.+ *+ * The capability half is the important one. `useOpenHumanExternalStore`+ * implements `onNew` / `onCancel` / `onReload` and neither `onEdit` nor+ * `setMessages`, so assistant-ui reports `edit` and `switchToBranch` as false.+ * The transcript renders no edit composer and no `BranchPickerPrimitive`+ * because of that, and this test is what would fail the day someone wires an+ * affordance to a capability the adapter cannot honour.+ */+import { combineReducers, configureStore } from '@reduxjs/toolkit';+import { renderHook } from '@testing-library/react';+import type { ReactNode } from 'react';+import { Provider } from 'react-redux';+import { describe, expect, it } from 'vitest';++import { AssistantUiRuntimeProvider } from '../../../../providers/AssistantUiRuntimeProvider';+import chatRuntimeReducer from '../../../../store/chatRuntimeSlice';+import threadReducer from '../../../../store/threadSlice';+import { useAuiEditCapabilities, useAuiThreadRunning } from './auiThreadState';++function withRuntime(threadId: string | null) {+ const store = configureStore({+ reducer: combineReducers({ thread: threadReducer, chatRuntime: chatRuntimeReducer }),+ });+ return ({ children }: { children: ReactNode }) => (+ <Provider store={store}>+ <AssistantUiRuntimeProvider threadId={threadId}>{children}</AssistantUiRuntimeProvider>+ </Provider>+ );+}++describe('auiThreadState', () => {+ it('reports undefined running state with no runtime mounted', () => {+ const { result } = renderHook(() => useAuiThreadRunning());+ expect(result.current).toBeUndefined();+ });++ it('reports no edit or branch capability with no runtime mounted', () => {+ const { result } = renderHook(() => useAuiEditCapabilities());+ expect(result.current).toEqual({ canEdit: false, canSwitchToBranch: false });+ });++ it('reports a concrete running state once a runtime is mounted', () => {+ const { result } = renderHook(() => useAuiThreadRunning(), {+ wrapper: withRuntime('t-caps'),+ });+ expect(result.current).toBe(false);+ });++ it('reports the external-store adapter as supporting neither edit nor branching', () => {+ const { result } = renderHook(() => useAuiEditCapabilities(), {+ wrapper: withRuntime('t-caps'),+ });+ expect(result.current).toEqual({ canEdit: false, canSwitchToBranch: false });+ });+});