Skip to content

The agent that grows with you

test(desktop): guard the opening user turn across Show-earlier paging

Brooklyn Nicholson02d0b6f91ddd
diff --git a/apps/desktop/src/app/chat/transcript-window.test.ts b/apps/desktop/src/app/chat/transcript-window.test.ts
index 963b914a795..bbd7045ede2 100644
--- a/apps/desktop/src/app/chat/transcript-window.test.ts
+++ b/apps/desktop/src/app/chat/transcript-window.test.ts
@@ -313,3 +313,52 @@ describe('alignToBranchGroup', () => {
expect(alignToBranchGroup(messages, 99)).toBe(messages.length)
})
})
+
+// Regression guard for #90473 / #96606 / #96875: for a LIGHT transcript (the
+// reported shape — a long chat of short messages, e.g. 142 turns), the store
+// window must surface messages[0] (the opening user greeting) as the first
+// rendered message. The 30-message floor and the weight budget both keep a
+// light transcript uncut, so paging to the top can never drop the oldest user
+// turn through the window slice.
+describe('opening user message is the first rendered message (light transcript)', () => {
+ const light = (count: number): ChatMessage[] => transcript(count, 20)
+
+ it('selectTranscriptWindow keeps messages[0] first when the whole transcript is light', () => {
+ const messages = light(142)
+
+ const window = selectTranscriptWindow(messages)
+
+ expect(window.windowed).toBe(false)
+ expect(window.messages[0]).toBe(messages[0])
+ })
+
+ it('growing the window terminates at the full transcript with messages[0] still first', () => {
+ const messages = light(142)
+
+ let pages = 1
+ let window = selectTranscriptWindow(messages, pages)
+
+ while (window.windowed && pages < 100) {
+ window = selectTranscriptWindow(messages, ++pages)
+ }
+
+ expect(window.windowed).toBe(false)
+ expect(window.messages).toHaveLength(messages.length)
+ // The first user message is the head of the fully-rendered transcript.
+ expect(window.messages[0]).toBe(messages[0])
+ })
+
+ it('advanceTranscriptWindow also surfaces messages[0] once pages cover the transcript', () => {
+ const messages = light(142)
+
+ let pages = 1
+ let state = advanceTranscriptWindow(null, messages, pages)
+
+ while (state.window.windowed && pages < 100) {
+ state = advanceTranscriptWindow(state, messages, ++pages)
+ }
+
+ expect(state.window.windowed).toBe(false)
+ expect(state.window.messages[0]).toBe(messages[0])
+ })
+})
diff --git a/apps/desktop/src/components/assistant-ui/thread/list.test.ts b/apps/desktop/src/components/assistant-ui/thread/list.test.ts
index 21814ee6e7c..38944f13985 100644
--- a/apps/desktop/src/components/assistant-ui/thread/list.test.ts
+++ b/apps/desktop/src/components/assistant-ui/thread/list.test.ts
@@ -490,3 +490,51 @@ describe('resolveThreadScrollTarget while selecting', () => {
expect(resolveThreadScrollTarget(999, contextFor())).toBe(999)
})
})
+
+// Regression guard for #90473 / #96606 / #96875: after "Show earlier" has paged
+// a session to its very top, the opening user message must still be rendered
+// and head the visible set — it must never be swallowed by the hidden-slice
+// cut. The store window keeps at least TRANSCRIPT_WINDOW_MIN_MESSAGES (30) and
+// the DOM budget only hides a contiguous prefix, so for a light transcript that
+// fits the budget the first user message is the first visible group.
+describe('first user message is never swallowed (Show-earlier paging)', () => {
+ it('keeps the opening user greeting visible when the render budget covers the whole transcript', () => {
+ const groups = buildGroups(
+ signature([
+ ['u1', 'user', 1],
+ ['a1', 'assistant', 4],
+ ['a2', 'assistant', 2],
+ ['u2', 'user', 1],
+ ['a3', 'assistant', 3]
+ ])
+ )
+
+ // A render budget at or above the total weight hides nothing — the state
+ // after "Show earlier" has paged to the top of a light session.
+ const totalWeight = groups.reduce((sum, g) => sum + g.weight, 0)
+ const hidden = firstVisibleGroupIndex(groups, totalWeight)
+
+ expect(hidden).toBe(0)
+ // The first user message is the head of the visible set, not dropped.
+ expect(groups[0]?.id).toBe('u1')
+ })
+
+ it('a leading assistant message (tool-only opening turn) does not hide the first user message', () => {
+ const groups = buildGroups(
+ signature([
+ ['a0', 'assistant', 2],
+ ['u1', 'user', 1],
+ ['a1', 'assistant', 4],
+ ['u2', 'user', 1],
+ ['a2', 'assistant', 3]
+ ])
+ )
+
+ const totalWeight = groups.reduce((sum, g) => sum + g.weight, 0)
+ const hidden = firstVisibleGroupIndex(groups, totalWeight)
+
+ expect(hidden).toBe(0)
+ // The first user message survives as a distinct visible group.
+ expect(groups.some(g => g.id === 'u1')).toBe(true)
+ })
+})