From 9a78e752b1bb725013e67e4d4470fa0cf564754f Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Mon, 12 Oct 2026 23:05:25 +0800 Subject: [PATCH] test(ui-chat): pin the input position order and a later-anchored Turn control The position-order case includes `input`. A Turn without opening input whose control anchors after a position-less row still renders the control before the group that holds that row. --- .../tests/group-tree-segments.client.spec.ts | 11 ++++++----- .../tests/process-groups.client.spec.ts | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/client/ui-chat/tests/group-tree-segments.client.spec.ts b/packages/client/ui-chat/tests/group-tree-segments.client.spec.ts index 377ca9c7d2..d1d948c7b4 100644 --- a/packages/client/ui-chat/tests/group-tree-segments.client.spec.ts +++ b/packages/client/ui-chat/tests/group-tree-segments.client.spec.ts @@ -25,12 +25,13 @@ function members(segments: GroupTreeSegments, turns: readonly number[]): number[ describe('Chat group tree', () => { it('orders positions from the outermost exchange inward', () => { - const at = (groupTree?: ChatGroupTree) => (['exchange', 'turn', 'process'] as const) + const at = (groupTree?: ChatGroupTree) => (['exchange', 'input', 'turn', 'process'] as const) .map(position => isAtOrOutside({ groupTree }, position)) - expect(at('exchange')).toEqual([true, true, true]) - expect(at('turn')).toEqual([false, true, true]) - expect(at('process')).toEqual([false, false, true]) - expect(at(undefined)).toEqual([false, false, false]) + expect(at('exchange')).toEqual([true, true, true, true]) + expect(at('input')).toEqual([false, true, true, true]) + expect(at('turn')).toEqual([false, false, true, true]) + expect(at('process')).toEqual([false, false, false, true]) + expect(at(undefined)).toEqual([false, false, false, false]) }) it('starts the latest segment at the last opening Turn and reports only the Turns that moved', () => { diff --git a/packages/client/ui-chat/tests/process-groups.client.spec.ts b/packages/client/ui-chat/tests/process-groups.client.spec.ts index 919793a672..f3d2ba643d 100644 --- a/packages/client/ui-chat/tests/process-groups.client.spec.ts +++ b/packages/client/ui-chat/tests/process-groups.client.spec.ts @@ -261,6 +261,25 @@ describe('Definition-owned Chat process groups', () => { expect(h.store.entries[0]).toEqual({ kind: 'node', key: control.key }) }) + it('sorts a later-anchored Turn control before the process of a Turn without opening input', () => { + // A Turn opened by a reply that declares no position: the control's own anchor follows the reply. + const control: ChatNode<'turn-process'> = { + key: 'control', id: '1', kind: 'turn-process', target: 'chat', anchorSeq: 6.9, + location: { kind: 'turn', turn }, visibility: 'visible', groupTree: 'turn', + data: { + turn: 1, controlAnchorSeq: 6, processStartSeq: 1, answerAnchorSeq: null, + answerStep: null, inlineReasoning: false, messageCount: 0, toolCallCount: 1, subagentCount: 0, + }, + } + const h = harness([tool('reply', 6), control, tool('after', 8)]) + expect(h.snapshot.order).toEqual(['control', 'reply', 'after']) + expect(h.store.entries.map(entry => entry.kind)).toEqual(['node', 'group']) + expect(h.store.entries[0]).toEqual({ kind: 'node', key: control.key }) + const group = h.store.entries[1]! + if (group.kind !== 'group') throw new Error('expected group') + expect(h.store.groupSource(group.key).getSnapshot()?.members.map(member => member.key)).toEqual(['reply', 'after']) + }) + it('retains a group through repeated prepends and a later append', () => { const b = tool('b', 4) const c = tool('c', 6)