Files
hapi/web/src/lib/voiceContextStream.test.ts
T
ae671c123b fix(web): deliver voice session bootstrap via contextual updates (#1344)
ElevenLabs only passed bootstrap context through dynamicVariables without
a matching {{initialConversationContext}} prompt placeholder, so Brief me
connected with no session history. Stream deferred chunks then push bootstrap
on all backends; add the placeholder for newly created ConvAI agents.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-03 18:01:32 +08:00

43 lines
1.3 KiB
TypeScript

import { describe, expect, test, vi } from 'vitest'
import { deliverVoiceSessionContextAfterConnect } from './voiceContextStream'
describe('deliverVoiceSessionContextAfterConnect', () => {
test('streams older chunks then bootstrap context', async () => {
const sent: string[] = []
const sendChunk = vi.fn((chunk: string) => {
sent.push(chunk)
})
await deliverVoiceSessionContextAfterConnect({
streamContextChunks: ['older-a', 'older-b'],
initialContext: 'bootstrap recent',
sendChunk
})
expect(sent).toEqual(['older-a', 'older-b', 'bootstrap recent'])
})
test('sends bootstrap even when there are no stream chunks', async () => {
const sent: string[] = []
await deliverVoiceSessionContextAfterConnect({
initialContext: ' session header only ',
sendChunk: (chunk) => sent.push(chunk)
})
expect(sent).toEqual(['session header only'])
})
test('skips empty bootstrap', async () => {
const sent: string[] = []
await deliverVoiceSessionContextAfterConnect({
streamContextChunks: ['chunk'],
initialContext: ' ',
sendChunk: (chunk) => sent.push(chunk)
})
expect(sent).toEqual(['chunk'])
})
})