diff --git a/src/renderer/src/components/native-chat/NativeChatStructuredSessionDelivery.test.tsx b/src/renderer/src/components/native-chat/NativeChatStructuredSessionDelivery.test.tsx index 9e3385f68ea..062cc0bc517 100644 --- a/src/renderer/src/components/native-chat/NativeChatStructuredSessionDelivery.test.tsx +++ b/src/renderer/src/components/native-chat/NativeChatStructuredSessionDelivery.test.tsx @@ -183,6 +183,24 @@ vi.mock('./NativeChatQuestionCard', () => ({ import { NativeChatStructuredSession } from './NativeChatStructuredSession' import { getStructuredAgentSessionOutbox } from './structured-agent-session-outbox-storage' +/** The first text block a send request carried, read without trusting its shape. */ +function sentText(params: unknown): string | undefined { + if (typeof params !== 'object' || params === null || !('body' in params)) { + return undefined + } + const { body } = params + if (typeof body !== 'object' || body === null || !('blocks' in body)) { + return undefined + } + const [first] = Array.isArray(body.blocks) ? body.blocks : [] + return typeof first === 'object' && + first !== null && + 'text' in first && + typeof first.text === 'string' + ? first.text + : undefined +} + describe('NativeChatStructuredSession delivery', () => { afterEach(() => { cleanup() @@ -480,9 +498,7 @@ describe('NativeChatStructuredSession delivery', () => { send?.('second', []) }) await waitFor(() => expect(mocks.call).toHaveBeenCalledTimes(2), { timeout: 5000 }) - const texts = mocks.call.mock.calls.map( - (call) => (call[2] as { body: { blocks: { text: string }[] } }).body.blocks[0]?.text - ) + const texts = mocks.call.mock.calls.map((call) => sentText(call[2])) expect(texts).toEqual(['first', 'second']) expect(screen.queryByText('Message delivery is unconfirmed.')).toBeNull() expect(screen.queryByRole('button', { name: /Retry/ })).toBeNull() diff --git a/src/renderer/src/components/native-chat/use-structured-agent-session-outbox.test.tsx b/src/renderer/src/components/native-chat/use-structured-agent-session-outbox.test.tsx index 5c7c72f56f5..fca111c9fb5 100644 --- a/src/renderer/src/components/native-chat/use-structured-agent-session-outbox.test.tsx +++ b/src/renderer/src/components/native-chat/use-structured-agent-session-outbox.test.tsx @@ -132,6 +132,20 @@ function refusedResult(code: AgentSessionWireRefusalCode) { return { ok: false, refusal: { code, message: code } } } +/** The operation id a request carried, read without trusting its shape. */ +function sentOperationId(params: unknown): string | undefined { + if (typeof params !== 'object' || params === null || !('envelope' in params)) { + return undefined + } + const { envelope } = params + return typeof envelope === 'object' && + envelope !== null && + 'clientOperationId' in envelope && + typeof envelope.clientOperationId === 'string' + ? envelope.clientOperationId + : undefined +} + describe('useStructuredAgentSessionOutbox', () => { let randomUuidSequence = 0 @@ -592,9 +606,7 @@ describe('useStructuredAgentSessionOutbox', () => { }) await waitFor(() => expect(result.current.outbox).toHaveLength(0)) - const ids = mocks.call.mock.calls.map( - (call) => (call[2] as { envelope: { clientOperationId: string } }).envelope.clientOperationId - ) + const ids = mocks.call.mock.calls.map((call) => sentOperationId(call[2])) // The first went once; its row says it was not sent, and its text is not handed back. expect(ids.filter((id) => id === firstId)).toHaveLength(1) expect(ids).toHaveLength(2)