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
chore: files changed app/src/components/assistant-ui/thread.followBottom.test.tsx,app/src/components
Steven Enamakela36cda8738e5
diff --git a/app/src/components/assistant-ui/thread.followBottom.test.tsx b/app/src/components/assistant-ui/thread.followBottom.test.tsxindex 6176784c83..f86f42615b 100644--- a/app/src/components/assistant-ui/thread.followBottom.test.tsx+++ b/app/src/components/assistant-ui/thread.followBottom.test.tsx@@ -1,17 +1,5 @@-/**- * `useFollowBottom` — the contract, at unit level.- *- * The e2e specs cover the integrated behaviour but they missed a real defect:- * the turn-start alignment (`scrollIntoView({ block: 'start' })`) scrolls UP,- * which the follow listener read as the reader leaving the bottom. E2E did not- * catch it because the listener checks proximity first, and after a SHORT user- * message the viewport is still within the 80px threshold — so the bug only- * appears for a user message tall enough to push past it. A browser test would- * need a fixture sized to that boundary; here the geometry is set directly.- *- * jsdom performs no layout, so every metric is assigned explicitly and the- * observable is the imperative `scrollTo` call, not a resulting `scrollTop` —- * the same approach as `thread.openScroll.test.tsx`.+/** Behaviour tests for assistant-ui's native viewport over the OpenHuman adapter.+ * jsdom has no layout, so scroll geometry and resize notifications are supplied.*/import { AssistantUiRuntimeProvider } from '@/providers/AssistantUiRuntimeProvider';import chatRuntimeReducer from '@/store/chatRuntimeSlice';@@ -130,7 +118,7 @@ function renderThread() {return { container, store, viewport: viewportOf(container) };}-describe('useFollowBottom', () => {+describe('assistant-ui native scroll anchoring', () => {it('offers a labelled scroll anchor away from the bottom and jumps instantly', () => {const { viewport } = renderThread();setGeometry(viewport, 500, 1000);@@ -215,114 +203,28 @@ describe('useFollowBottom', () => {expect(followedBottom(viewport)).toBe(true);});- it('keeps following after the turn-start alignment scrolls the viewport UP', () => {- // `ThreadBottomFollower` aligns a new user message with- // `scrollIntoView({ block: 'start' })`. For a reader at the bottom that- // LOWERS `scrollTop` — the message sits above the trailing margin and the- // status slot — which is indistinguishable from the reader moving into- // history unless the follower claims its own scroll.- //- // Ordering is the whole point: the alignment is synchronous, its `scroll`- // event is not. Setting the follow flag inside the effect is not enough,- // because the later event sees a drop against a stale baseline and clears- // it again. `claimScroll` re-baselines while `scrollTop` already holds the- // post-alignment value, so that event becomes a no-op.- //- // The e2e suite cannot reach this without a fixture sized to the 80px- // boundary: with a short user message the viewport stays within the- // threshold and the proximity branch masks it.- const { store, viewport } = renderThread();- setGeometry(viewport, 500, 1000);- act(() => viewport.dispatchEvent(new Event('scroll')));-- // Make the alignment behave like the real one: `scrollIntoView` on a- // message above the trailing margin LOWERS `scrollTop`, synchronously,- // inside the effect. A no-op mock cannot reproduce the ordering this test- // exists to check — `claimScroll` would capture the pre-alignment value- // and the test would pass for the wrong reason.- vi.spyOn(Element.prototype, 'scrollIntoView').mockImplementation(() => {- viewport.scrollTop = 150;- });-- act(() => {- store.dispatch({- type: loadThreadMessages.fulfilled.type,- payload: {- threadId: 't1',- messages: [- msg('1', 'user', 'hi'),- msg('2', 'agent', 'hello'),- msg('3', 'user', 'a tall follow-up question'),- ],- },- });- });-- // The alignment's own scroll event arrives now.- act(() => viewport.dispatchEvent(new Event('scroll')));- scrollToSpy.mockClear();-- // The reply streams.- setGeometry(viewport, 150, 1600);- growContent();-- expect(followedBottom(viewport)).toBe(true);- });-- it('ignores the growth that prompted a claim, so the alignment survives', () => {- // The user message grows the content box, which queues a resize- // notification; the alignment then claims the scroll. Following that queued- // callback would scroll to the bottom and erase the alignment before it is- // painted — making it pointless rather than short-lived.+ it('follows new user-message growth at the bottom without a custom top alignment', () => {const { store, viewport } = renderThread();setGeometry(viewport, 500, 1000);act(() => viewport.dispatchEvent(new Event('scroll')));-- vi.spyOn(Element.prototype, 'scrollIntoView').mockImplementation(() => {- viewport.scrollTop = 150;- });-- // The new user message has already grown the box to 1400 when the alignment- // runs and claims at that height. `scrollTop` must put the reader AT the- // bottom (1400 - 500 clientHeight = 900), or `ThreadBottomFollower` returns- // early on its own proximity guard and never aligns or claims at all —- // which would make this test pass for the wrong reason.- setGeometry(viewport, 900, 1400);- act(() => {- store.dispatch({- type: loadThreadMessages.fulfilled.type,- payload: {- threadId: 't1',- messages: [- msg('1', 'user', 'hi'),- msg('2', 'agent', 'hello'),- msg('3', 'user', 'a tall follow-up question'),- ],- },- });- });scrollToSpy.mockClear();-- // The queued notification for THAT growth must not move the viewport.- growContent();- expect(followedBottom(viewport)).toBe(false);-- // The reply arriving is growth beyond the claim, and is followed.- setGeometry(viewport, 150, 1900);+ const alignment = vi.spyOn(Element.prototype, 'scrollIntoView');+ setGeometry(viewport, 500, 1400);+ act(() => store.dispatch({+ type: loadThreadMessages.fulfilled.type,+ payload: { threadId: 't1', messages: [msg('1', 'user', 'hi'), msg('2', 'agent', 'hello'), msg('3', 'user', 'follow-up')] },+ }));growContent();expect(followedBottom(viewport)).toBe(true);+ expect(alignment).not.toHaveBeenCalled();});- it('keeps following when scrollTop drops with no reader input behind it', () => {- // A disclosure collapsing, content shrinking as parts are swapped, and- // assistant-ui's `useScrollLock` writing an old `scrollTop` back all lower- // `scrollTop` past the threshold with nobody touching anything. Each used- // to read as the reader leaving and stop following mid-turn.+ it('keeps following when collapsing content changes the scroll geometry', () => {const { viewport } = renderThread();setGeometry(viewport, 500, 1000);act(() => viewport.dispatchEvent(new Event('scroll')));- setGeometry(viewport, 100, 1000);+ setGeometry(viewport, 100, 600);act(() => viewport.dispatchEvent(new Event('scroll')));scrollToSpy.mockClear();diff --git a/app/src/components/assistant-ui/thread.openScroll.test.tsx b/app/src/components/assistant-ui/thread.openScroll.test.tsxindex 58d501be59..16d0e1f4ea 100644--- a/app/src/components/assistant-ui/thread.openScroll.test.tsx+++ b/app/src/components/assistant-ui/thread.openScroll.test.tsx@@ -1,26 +1,10 @@-/**- * Opening a thread must land on the newest message.- *- * This is driven through the REAL Redux cache rather than a hand-fed message- * array, because the cache is the whole reason the defect is intermittent.- * `useOpenHumanExternalStore` reads- * `state.thread.messagesByThreadId[threadId]`, so a thread visited earlier in- * the session hands its messages over on the very render the id changes — it- * never passes through the empty state that re-arms assistant-ui's- * `scrollToBottomOnInitialize` latch. A thread NOT yet cached does briefly- * empty, so it scrolls correctly even unfixed. A fix checked only against a- * fresh thread therefore looks right and fixes nothing, which is why the- * cached switch below is the load-bearing case.- *- * jsdom performs no layout and stubs `scrollTo` to a no-op, so the observable- * here is the imperative call and its argument, not a resulting `scrollTop`.- */+/** Native assistant-ui initialization and cached-thread switching over Redux. */import { AssistantUiRuntimeProvider } from '@/providers/AssistantUiRuntimeProvider';import chatRuntimeReducer from '@/store/chatRuntimeSlice';import threadReducer, { loadThreadMessages } from '@/store/threadSlice';import type { ThreadMessage } from '@/types/thread';import { configureStore } from '@reduxjs/toolkit';-import { render } from '@testing-library/react';+import { render, waitFor } from '@testing-library/react';import { act } from 'react';import { Provider } from 'react-redux';import { afterEach, beforeEach, describe, expect, it, type MockInstance, vi } from 'vitest';@@ -94,7 +78,7 @@ function scrolledToBottom(viewport: HTMLElement): boolean {}describe('opening a thread scrolls to the newest message', () => {- it('scrolls to the bottom when the last message is from the assistant', () => {+ it('scrolls to the bottom when the last message is from the assistant', async () => {const store = makeStore();cacheThread(store, 't-assistant', [msg('1', 'user', 'question'),@@ -109,10 +93,10 @@ describe('opening a thread scrolls to the newest message', () => {</Provider>);- expect(scrolledToBottom(viewportOf(container))).toBe(true);+ await waitFor(() => expect(scrolledToBottom(viewportOf(container))).toBe(true));});- it('scrolls when switching to an ALREADY-CACHED thread, which never empties', () => {+ it('scrolls when switching to an ALREADY-CACHED thread, which never empties', async () => {const store = makeStore();cacheThread(store, 't-a', [msg('1', 'user', 'first thread')]);cacheThread(store, 't-b', [msg('2', 'user', 'hi'), msg('3', 'agent', 'second thread')]);@@ -126,6 +110,7 @@ describe('opening a thread scrolls to the newest message', () => {);const viewport = viewportOf(container);+ await waitFor(() => expect(scrolledToBottom(viewport)).toBe(true));// The opening scroll for t-a is not what this test is about.scrollToSpy.mockClear();@@ -140,12 +125,11 @@ describe('opening a thread scrolls to the newest message', () => {// Same viewport element across the switch — no remount laundered the state.expect(viewportOf(container)).toBe(viewport);// Both threads are cached, so t-b's messages were present on the render the- // id flipped: assistant-ui's latch never re-armed and only our own- // thread-keyed scroll can have fired.- expect(scrolledToBottom(viewport)).toBe(true);+ // id flipped: the adapter supplies it to the native thread-switch event.+ await waitFor(() => expect(scrolledToBottom(viewport)).toBe(true));});- it('does not yank a reader who has scrolled up when a new turn arrives', () => {+ it('does not yank a reader who has scrolled up when a new turn arrives', async () => {const store = makeStore();cacheThread(store, 't-reader', [msg('1', 'user', 'q'), msg('2', 'agent', 'a')]);@@ -161,9 +145,13 @@ describe('opening a thread scrolls to the newest message', () => {// viewport, parked at the top — 800px from the bottom, well past the 80px// follow threshold.const viewport = viewportOf(container);+ await waitFor(() => expect(scrolledToBottom(viewport)).toBe(true));Object.defineProperty(viewport, 'scrollHeight', { value: 1000, configurable: true });Object.defineProperty(viewport, 'clientHeight', { value: 200, configurable: true });+ viewport.scrollTop = 800;+ act(() => viewport.dispatchEvent(new Event('scroll')));viewport.scrollTop = 0;+ act(() => viewport.dispatchEvent(new Event('scroll')));scrollToSpy.mockClear();scrollIntoViewSpy.mockClear();@@ -178,7 +166,7 @@ describe('opening a thread scrolls to the newest message', () => {expect(scrolledToBottom(viewport)).toBe(false);});- it('still aligns a new turn for a reader who is already at the bottom', () => {+ it('follows a new turn at the bottom without a custom top alignment', async () => {const store = makeStore();cacheThread(store, 't-bottom', [msg('1', 'user', 'q'), msg('2', 'agent', 'a')]);@@ -191,9 +179,12 @@ describe('opening a thread scrolls to the newest message', () => {);const viewport = viewportOf(container);+ await waitFor(() => expect(scrolledToBottom(viewport)).toBe(true));Object.defineProperty(viewport, 'scrollHeight', { value: 1000, configurable: true });Object.defineProperty(viewport, 'clientHeight', { value: 200, configurable: true });viewport.scrollTop = 800; // pinned to the bottom+ act(() => viewport.dispatchEvent(new Event('scroll')));+ scrollToSpy.mockClear();scrollIntoViewSpy.mockClear();cacheThread(store, 't-bottom', [@@ -202,6 +193,8 @@ describe('opening a thread scrolls to the newest message', () => {msg('4', 'user', 'follow-up'),]);- expect(scrollIntoViewSpy).toHaveBeenCalled();+ Object.defineProperty(viewport, 'scrollHeight', { value: 1200, configurable: true });+ await waitFor(() => expect(scrolledToBottom(viewport)).toBe(true));+ expect(scrollIntoViewSpy).not.toHaveBeenCalled();});});