test(desktop): harden steer-order suite against fake-timer id collisions

Review follow-ups: steer ids now come from a monotonic counter instead of
Date.now() (frozen under fake timers — two steers without a clock advance
would have collided), and the settle-above assertion documents its
load-bearing sealed-bubble assumption.
This commit is contained in:
Brooklyn Nicholson
2026-08-16 18:06:05 -05:00
committed by brooklyn!
parent b2f345f540
commit f1f694aac1
@@ -75,6 +75,10 @@ const flushDeltas = async () => {
const emit = (event: RpcEvent) => act(() => handleEvent?.(event))
/** Monotonic id source — Date.now() is frozen under fake timers, so two steers
* without a clock advance between them would collide on a wall-clock id. */
let steerSeq = 0
/** The optimistic steer insert redirectPrompt performs (appendAfterActiveReply). */
const steer = (text: string) =>
act(() => {
@@ -83,7 +87,7 @@ const steer = (text: string) =>
states.set(
SID,
appendMidTurnUserMessage(current, {
id: `user-${Date.now()}-steer`,
id: `user-${(steerSeq += 1)}-steer`,
role: 'user',
parts: [{ type: 'text', text }]
})
@@ -178,7 +182,10 @@ describe('steer mid-turn keeps arrival order (user bubble never above prior outp
// The already-streamed reply settles onto its sealed bubble ABOVE the
// correction; the correction stays the tail, waiting for its own turn —
// no duplicate reply row appended below it.
// no duplicate reply row appended below it. Load-bearing assumption: a
// completion settles the sealed pre-steer bubble in place and never
// appends/merges below the correction — if the reducer ever changes that,
// this test is the tripwire.
expect(steerIndex).toBe(messages.length - 1)
expect(messages.filter(message => chatMessageText(message).includes('whole reply already streamed'))).toHaveLength(1)
expect(messages.every(message => message.pending !== true)).toBe(true)