From f1f694aac13dfab0d5cd8a07494956acdd5739ca Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Sun, 16 Aug 2026 18:06:05 -0500 Subject: [PATCH] test(desktop): harden steer-order suite against fake-timer id collisions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../use-message-stream/steer-arrival-order.test.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/steer-arrival-order.test.tsx b/apps/desktop/src/app/session/hooks/use-message-stream/steer-arrival-order.test.tsx index be8fd2edcc..3b7c3dd890 100644 --- a/apps/desktop/src/app/session/hooks/use-message-stream/steer-arrival-order.test.tsx +++ b/apps/desktop/src/app/session/hooks/use-message-stream/steer-arrival-order.test.tsx @@ -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)