mirror of
https://github.com/stablyai/orca.git
synced 2026-10-08 00:02:38 +00:00
test(native-chat): read sent requests through checked helpers instead of casts
This commit is contained in:
+19
-3
@@ -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()
|
||||
|
||||
+15
-3
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user