Skip to content

Commit d9d3589

Browse files
committed
test(mothership): lock the queue upgrade path and tighten held waits
- rehydrate rows for the production shape (retryRequired: false, no hold) and for a queue already in the new shape - the offline-hold waits check hold === 'online' instead of any hold - the one-lookup comment names where the one-hop invariant is enforced
1 parent 8ea8621 commit d9d3589

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.dom.test.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,7 +3480,7 @@ describe('useChat remount send recovery', () => {
34803480

34813481
await waitFor(() => state.postBodies.length === 1)
34823482
await waitFor(
3483-
() => useMothershipQueueStore.getState().queues[history.id]?.[0]?.hold !== undefined
3483+
() => useMothershipQueueStore.getState().queues[history.id]?.[0]?.hold === 'online'
34843484
)
34853485

34863486
const queued = useMothershipQueueStore.getState().queues[history.id] ?? []
@@ -3575,7 +3575,7 @@ describe('useChat remount send recovery', () => {
35753575
await act(async () => {
35763576
await first.getResult().sendMessage('First message, sent offline')
35773577
})
3578-
await waitFor(() => allQueuedMessages().some((message) => message.hold !== undefined))
3578+
await waitFor(() => allQueuedMessages().some((message) => message.hold === 'online'))
35793579
first.unmount()
35803580

35813581
const second = renderUseChat()
@@ -4352,7 +4352,7 @@ describe('useChat remount send recovery', () => {
43524352
await first.getResult().sendMessage('Held while I was elsewhere')
43534353
})
43544354
await waitFor(
4355-
() => useMothershipQueueStore.getState().queues[history.id]?.[0]?.hold !== undefined
4355+
() => useMothershipQueueStore.getState().queues[history.id]?.[0]?.hold === 'online'
43564356
)
43574357
first.unmount()
43584358

‎apps/sim/stores/mothership-queue/store.dom.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ describe('useMothershipQueueStore rehydration', () => {
2121
{ id: 'for-network', content: 'b', retryRequired: true, heldUntilOnline: true },
2222
{ id: 'retrying', content: 'c', sendRetries: 2, notBefore: 1_000 },
2323
{ id: 'plain', content: 'd' },
24+
{ id: 'main-shape', content: 'e', retryRequired: false },
25+
{
26+
id: 'new-shape',
27+
content: 'f',
28+
hold: 'online',
29+
retry: { attempt: 1, notBefore: 5 },
30+
},
2431
],
2532
},
2633
},
@@ -35,6 +42,8 @@ describe('useMothershipQueueStore rehydration', () => {
3542
{ id: 'for-network', content: 'b', hold: 'online' },
3643
{ id: 'retrying', content: 'c', retry: { attempt: 2, notBefore: 1_000 } },
3744
{ id: 'plain', content: 'd' },
45+
{ id: 'main-shape', content: 'e' },
46+
{ id: 'new-shape', content: 'f', hold: 'online', retry: { attempt: 1, notBefore: 5 } },
3847
])
3948
})
4049

‎apps/sim/stores/mothership-queue/store.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ export function liveQueuePosition(
147147
aheadIds: readonly string[]
148148
): { chatKey: string; index: number } {
149149
const { migratedTo, queues } = useMothershipQueueStore.getState()
150-
/** One lookup: only a new-chat key moves, and only to its chat's key, which never does. */
150+
/* One lookup: only a new-chat key moves, and only to its chat's key, which never
151+
does. \`useChat\` migrates only from its pending sentinel key to the resolved chat
152+
id (the chat-resolution effect and the detached chat resolution), never from a
153+
chat key. */
151154
const migration = migratedTo[chatKey]
152155
const key = migration?.key ?? chatKey
153156
const ahead = new Set([...aheadIds, ...(migration?.ahead ?? [])])

0 commit comments

Comments
 (0)