Skip to content

The agent that grows with you

test(desktop): cancel tests prove the refreshed history survives, row ids included

kshitijk4poorbb6ef0152e24
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.deep-cut.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.deep-cut.test.tsx
index 7fcae754ec1..9bb86be3a14 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.deep-cut.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.deep-cut.test.tsx
@@ -374,12 +374,14 @@ describe('usePromptActions deep-edit consent scope (#133716)', () => {
// As in the real session cache, the slice and the foreground mirror are separate arrays.
publishSessionState(RUNTIME_SESSION_ID, createClientSessionState('stored', [...fresh] as never))
setMessages(fresh as never)
+ handle!.replaceSessionMessages(fresh)
}}
seedMessages={seed}
storedSessionId="stored"
/>
)
+ const grown = [...fresh, { id: 'u4', parts: [textPart('newer')], role: 'user' as const, rowId: 27, timestamp: 4 }]
let confirms = 0
const stopConfirming = $confirmRequest.listen(request => {
if (request) {
@@ -391,9 +393,9 @@ describe('usePromptActions deep-edit consent scope (#133716)', () => {
if (confirms === 2 && answer === 'moved') {
// A newer user turn lands while the dialog is open: the plan no longer covers it.
- const grown = [...fresh, { id: 'u4', parts: [textPart('newer')], role: 'user', rowId: 27, timestamp: 4 }]
publishSessionState(RUNTIME_SESSION_ID, createClientSessionState('stored', grown as never))
setMessages(grown as never)
+ handle!.replaceSessionMessages(grown)
}
settleConfirm(confirms === 1 || answer !== 'decline')
@@ -417,9 +419,12 @@ describe('usePromptActions deep-edit consent scope (#133716)', () => {
expect(submits).toHaveLength(1)
// After a switch the foreground busy flag belongs to the session now on screen.
expect($busy.get()).toBe(answer === 'switch')
- // The refresh already replaced the optimistic edit; a cancel must not restore the stale seed.
+ // Nothing was cut: the session keeps the history it holds now (refreshed, or grown under the
+ // dialog), with the refreshed row ids, never the pre-refresh seed.
+ const kept = (lastState?.messages ?? []) as { id: string; rowId?: number }[]
+ const expected = answer === 'moved' ? grown : fresh
expect(lastState).toMatchObject({ busy: false })
- expect(lastState?.messages).not.toBe(seed)
+ expect(kept.map(m => [m.id, m.rowId])).toEqual(expected.map(m => [m.id, m.rowId]))
}
// Only a turn that moved under an accepted confirm is worth a notice; a decline is the user's choice.
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/prompt-actions-harness.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/prompt-actions-harness.tsx
index 46921367128..c94dd4a8536 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/prompt-actions-harness.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/prompt-actions-harness.tsx
@@ -1,7 +1,7 @@
// Shared usePromptActions test harness (index.test.tsx and the topical siblings).
import { act, render } from '@testing-library/react'
import type { MutableRefObject } from 'react'
-import { useEffect, useRef } from 'react'
+import { useCallback, useEffect, useRef } from 'react'
import type { SubmitTextOptions } from './utils'
@@ -29,6 +29,8 @@ export interface HarnessHandle {
reloadFromMessage: (parentId: null | string) => Promise<void>
restoreToMessage: (messageId: string, target?: { text?: string; userOrdinal?: number | null }) => Promise<void>
redirectPrompt: (text: string) => Promise<boolean>
+ /** What a real resume does to the session slice: replace its transcript (the hook reads it back). */
+ replaceSessionMessages: (messages: unknown[]) => void
/** @deprecated Use `redirectPrompt`. */
steerPrompt: (text: string) => Promise<boolean>
submitTextRaw: (text: string, options?: SubmitTextOptions) => Promise<boolean>
@@ -143,6 +145,10 @@ export function Harness({
}
})
+ const replaceSessionMessages = useCallback((messages: unknown[]) => {
+ stateRef.current = { ...(stateRef.current as object), messages } as never
+ }, [])
+
useEffect(() => {
onReady({
activeSessionIdRef,
@@ -156,6 +162,7 @@ export function Harness({
act(async () => actions.restoreToMessage(...args)) as Promise<void>,
redirectPrompt: (...args: Parameters<typeof actions.redirectPrompt>) =>
act(async () => actions.redirectPrompt(...args)) as Promise<boolean>,
+ replaceSessionMessages,
steerPrompt: (...args: Parameters<typeof actions.steerPrompt>) =>
act(async () => actions.steerPrompt(...args)) as Promise<boolean>,
submitTextRaw: actions.submitText,
@@ -171,7 +178,8 @@ export function Harness({
actions.steerPrompt,
actions.submitText,
activeSessionIdRef,
- onReady
+ onReady,
+ replaceSessionMessages
])
return null