@@ -53,6 +53,7 @@ vi.mock('../../src/OutgoingConnection', () => ({
5353 this . addTranscriptContext = vi . fn ( ) ;
5454 this . updateInputFormat = vi . fn ( ) ;
5555 this . getInputFormat = vi . fn ( ( ) => inputFormat ?? { encoding : 'opus' } ) ;
56+ this . resetChunkTracking = vi . fn ( ) ;
5657 this . close = vi . fn ( ) ;
5758 this . onInterimTranscription = undefined ;
5859 this . onCompleteTranscription = undefined ;
@@ -599,7 +600,7 @@ describe('TranscriberProxy', () => {
599600 const msg = sniffCalls [ 0 ] [ 0 ] as string ;
600601 expect ( msg ) . toContain ( 'tag=tag1' ) ;
601602 expect ( msg ) . toContain ( 'urlEncoding=opus' ) ;
602- expect ( msg ) . toContain ( ' startFormat={"encoding":"opus"}') ;
603+ expect ( msg ) . toContain ( ` startFormat=' {"encoding":"opus"}'` ) ;
603604 expect ( msg ) . toContain ( '4f676753' ) ; // 'OggS' in hex
604605 expect ( msg ) . toContain ( `<b64:${ OGG_PAYLOAD . length } chars, first 4 decoded bytes=4f676753>` ) ;
605606 } ) ;
@@ -647,6 +648,21 @@ describe('TranscriberProxy', () => {
647648 expect ( endCall ?. [ 0 ] ) . toContain ( 'audioPackets=1' ) ;
648649 } ) ;
649650
651+ it ( 'fires the first-frame sniff again after a WebSocket reattach' , ( ) => {
652+ const proxy = new TranscriberProxy ( mockWebSocket , options ) ;
653+ proxy . handleStartEvent ( { event : 'start' , start : { tag : 'tag1' , mediaFormat : { encoding : 'opus' } } } ) ;
654+
655+ proxy . handleMediaEvent ( { event : 'media' , media : { tag : 'tag1' , payload : OGG_PAYLOAD , chunk : 0 , timestamp : 0 } } ) ;
656+ proxy . handleMediaEvent ( { event : 'media' , media : { tag : 'tag1' , payload : OGG_PAYLOAD , chunk : 1 , timestamp : 0 } } ) ;
657+
658+ vi . mocked ( logger . info ) . mockClear ( ) ;
659+ proxy . reattachWebSocket ( { addEventListener : vi . fn ( ) , send : vi . fn ( ) , close : vi . fn ( ) } as any ) ;
660+
661+ proxy . handleMediaEvent ( { event : 'media' , media : { tag : 'tag1' , payload : OGG_PAYLOAD , chunk : 0 , timestamp : 0 } } ) ;
662+ const sniffCalls = vi . mocked ( logger . info ) . mock . calls . filter ( ( [ msg ] ) => typeof msg === 'string' && msg . startsWith ( 'First client frame sniff:' ) ) ;
663+ expect ( sniffCalls ) . toHaveLength ( 1 ) ;
664+ } ) ;
665+
650666 it ( 'emits a session-end summary with audioPackets, interims, finals, and provider' , ( ) => {
651667 const proxy = new TranscriberProxy ( mockWebSocket , { ...options , provider : 'deepgram' } ) ;
652668 proxy . handleStartEvent ( { event : 'start' , start : { tag : 'tag1' , mediaFormat : { encoding : 'opus' } } } ) ;
0 commit comments