@@ -65,37 +65,65 @@ describe("Google Live browser transcript finality", () => {
6565 transport . stop ( ) ;
6666 } ) ;
6767
68- it ( "finalizes interrupted output on its original Talk turn without merging the next response" , async ( ) => {
69- const onTranscript = vi . fn ( ) ;
70- const onTalkEvent = vi . fn ( ) ;
71- const transport = createTransport ( { onTranscript, onTalkEvent } ) ;
72- const ws = await startTransport ( transport ) ;
73- onTalkEvent . mockClear ( ) ;
74- for ( const serverContent of [
75- { outputTranscription : { text : "Interrupted " } } ,
76- { outputTranscription : { text : "response" } } ,
77- { interrupted : true } ,
78- { outputTranscription : { text : "Next response" , finished : true } } ,
79- { turnComplete : true } ,
80- ] ) {
81- ws . emitMessage ( encodeJsonFrame ( { serverContent } ) ) ;
82- await flushMicrotasks ( ) ;
83- }
84- expect (
85- onTranscript . mock . calls . filter ( ( [ entry ] ) => entry . final ) . map ( ( [ entry ] ) => entry . text ) ,
86- ) . toEqual ( [ "Interrupted response" , "Next response" ] ) ;
87- expect ( onTalkEvent . mock . calls . map ( ( [ event ] ) => [ event . type , event . turnId ] ) ) . toEqual ( [
88- [ "output.text.delta" , "turn-1" ] ,
89- [ "output.text.delta" , "turn-1" ] ,
90- [ "output.text.done" , "turn-1" ] ,
91- [ "turn.cancelled" , "turn-1" ] ,
92- [ "output.text.delta" , "turn-2" ] ,
93- [ "output.text.done" , "turn-2" ] ,
94- [ "turn.ended" , "turn-2" ] ,
95- ] ) ;
96- transport . stop ( ) ;
97- expect ( onTranscript . mock . calls . filter ( ( [ entry ] ) => entry . final ) ) . toHaveLength ( 2 ) ;
98- } ) ;
68+ it . each ( [
69+ {
70+ name : "before the next input transcript" ,
71+ boundary : [
72+ { interrupted : true } ,
73+ { turnComplete : true } ,
74+ { inputTranscription : { text : "New question" } } ,
75+ ] ,
76+ } ,
77+ {
78+ name : "after an independently ordered input transcript" ,
79+ boundary : [
80+ { interrupted : true } ,
81+ { inputTranscription : { text : "New question" } } ,
82+ { turnComplete : true } ,
83+ ] ,
84+ } ,
85+ {
86+ name : "in the interruption frame" ,
87+ boundary : [
88+ { interrupted : true , turnComplete : true } ,
89+ { inputTranscription : { text : "New question" } } ,
90+ ] ,
91+ } ,
92+ ] ) (
93+ "does not end another Talk turn when interrupted completion arrives $name" ,
94+ async ( { boundary } ) => {
95+ const onTranscript = vi . fn ( ) ;
96+ const onTalkEvent = vi . fn ( ) ;
97+ const transport = createTransport ( { onTranscript, onTalkEvent } ) ;
98+ const ws = await startTransport ( transport ) ;
99+ onTalkEvent . mockClear ( ) ;
100+ for ( const serverContent of [
101+ { outputTranscription : { text : "Interrupted " } } ,
102+ { outputTranscription : { text : "response" } } ,
103+ ...boundary ,
104+ { outputTranscription : { text : "Next response" , finished : true } } ,
105+ { turnComplete : true } ,
106+ ] ) {
107+ ws . emitMessage ( encodeJsonFrame ( { serverContent } ) ) ;
108+ await flushMicrotasks ( ) ;
109+ }
110+ expect (
111+ onTranscript . mock . calls . filter ( ( [ entry ] ) => entry . final ) . map ( ( [ entry ] ) => entry . text ) ,
112+ ) . toEqual ( [ "Interrupted response" , "New question" , "Next response" ] ) ;
113+ expect ( onTalkEvent . mock . calls . map ( ( [ event ] ) => [ event . type , event . turnId ] ) ) . toEqual ( [
114+ [ "output.text.delta" , "turn-1" ] ,
115+ [ "output.text.delta" , "turn-1" ] ,
116+ [ "output.text.done" , "turn-1" ] ,
117+ [ "turn.cancelled" , "turn-1" ] ,
118+ [ "transcript.done" , "turn-2" ] ,
119+ [ "output.text.delta" , "turn-2" ] ,
120+ [ "output.text.done" , "turn-2" ] ,
121+ [ "turn.ended" , "turn-2" ] ,
122+ ] ) ;
123+ transport . stop ( ) ;
124+ expect ( onTranscript . mock . calls . filter ( ( [ entry ] ) => entry . final ) ) . toHaveLength ( 3 ) ;
125+ } ,
126+ ) ;
99127
100128 it ( "releases the UTF-8 transcript budget on finality and closes on overflow without persisting a partial" , async ( ) => {
101129 const onTranscript = vi . fn ( ) ;
0 commit comments