@@ -204,17 +204,9 @@ describe('run() text emission', () => {
204204
205205 const handler = await waitForHandler ( )
206206
207+ await handler . options . onResponseChunk ( responseChunk ( handler , 'Hello ' ) )
207208 await handler . options . onResponseChunk (
208- responseChunk ( handler , {
209- type : 'text' ,
210- text : 'Hello ' ,
211- } ) ,
212- )
213- await handler . options . onResponseChunk (
214- responseChunk ( handler , {
215- type : 'text' ,
216- text : 'Hello world' ,
217- } ) ,
209+ responseChunk ( handler , 'Hello world' ) ,
218210 )
219211 await handler . options . onResponseChunk (
220212 responseChunk ( handler , {
@@ -237,7 +229,7 @@ describe('run() text emission', () => {
237229 ] )
238230 } )
239231
240- test ( 'emits combined text when raw string and structured chunks interleave ' , async ( ) => {
232+ test ( 'emits combined text when consecutive string chunks overlap ' , async ( ) => {
241233 const events : PrintModeEvent [ ] = [ ]
242234 const streamChunks : string [ ] = [ ]
243235 const runPromise = run ( {
@@ -256,10 +248,7 @@ describe('run() text emission', () => {
256248 responseChunk ( handler , 'Root string ' ) ,
257249 )
258250 await handler . options . onResponseChunk (
259- responseChunk ( handler , {
260- type : 'text' ,
261- text : 'section complete' ,
262- } ) ,
251+ responseChunk ( handler , 'Root string section complete' ) ,
263252 )
264253 await handler . options . onResponseChunk (
265254 responseChunk ( handler , {
@@ -298,22 +287,13 @@ describe('run() text emission', () => {
298287 const handler = await waitForHandler ( )
299288
300289 await handler . options . onResponseChunk (
301- responseChunk ( handler , {
302- type : 'text' ,
303- text : 'Intro line ' ,
304- } ) ,
290+ responseChunk ( handler , 'Intro line ' ) ,
305291 )
306292 await handler . options . onResponseChunk (
307- responseChunk ( handler , {
308- type : 'text' ,
309- text : 'continues' ,
310- } ) ,
293+ responseChunk ( handler , 'continues' ) ,
311294 )
312295 await handler . options . onResponseChunk (
313- responseChunk ( handler , {
314- type : 'text' ,
315- text : ' and ends.<codebuff_tool_call>' ,
316- } ) ,
296+ responseChunk ( handler , ' and ends.<codebuff_tool_call>' ) ,
317297 )
318298 await handler . options . onResponseChunk (
319299 responseChunk ( handler , {
@@ -409,16 +389,10 @@ describe('run() text emission', () => {
409389 const handler = await waitForHandler ( )
410390
411391 await handler . options . onResponseChunk (
412- responseChunk ( handler , {
413- type : 'text' ,
414- text : 'Before <codebuff_tool_call>{"x":1}' ,
415- } ) ,
392+ responseChunk ( handler , 'Before <codebuff_tool_call>{"x":1}' ) ,
416393 )
417394 await handler . options . onResponseChunk (
418- responseChunk ( handler , {
419- type : 'text' ,
420- text : '</codebuff_tool_call> after' ,
421- } ) ,
395+ responseChunk ( handler , '</codebuff_tool_call> after' ) ,
422396 )
423397 await handler . options . onResponseChunk (
424398 responseChunk ( handler , {
@@ -436,8 +410,7 @@ describe('run() text emission', () => {
436410 )
437411
438412 expect ( textEvents ) . toEqual ( [
439- expect . objectContaining ( { text : 'Before' } ) ,
440- expect . objectContaining ( { text : 'after' } ) ,
413+ expect . objectContaining ( { text : 'Before after' } ) ,
441414 ] )
442415 } )
443416
@@ -453,10 +426,7 @@ describe('run() text emission', () => {
453426 const handler = await waitForHandler ( )
454427
455428 await handler . options . onResponseChunk (
456- responseChunk ( handler , {
457- type : 'text' ,
458- text : '\nLine 1\nLine 2\n\n' ,
459- } ) ,
429+ responseChunk ( handler , '\nLine 1\nLine 2\n\n' ) ,
460430 )
461431 await handler . options . onResponseChunk (
462432 responseChunk ( handler , {
@@ -491,12 +461,7 @@ describe('run() text emission', () => {
491461
492462 const handler = await waitForHandler ( )
493463
494- await handler . options . onResponseChunk (
495- responseChunk ( handler , {
496- type : 'text' ,
497- text : '\n\n' ,
498- } ) ,
499- )
464+ await handler . options . onResponseChunk ( responseChunk ( handler , '\n\n' ) )
500465 await handler . options . onResponseChunk (
501466 responseChunk ( handler , {
502467 type : 'finish' ,
@@ -572,10 +537,7 @@ describe('run() text emission', () => {
572537 const handler = await waitForHandler ( )
573538
574539 await handler . options . onResponseChunk (
575- responseChunk ( handler , {
576- type : 'text' ,
577- text : 'First section' ,
578- } ) ,
540+ responseChunk ( handler , 'First section' ) ,
579541 )
580542 await handler . options . onResponseChunk (
581543 responseChunk ( handler , {
@@ -586,10 +548,7 @@ describe('run() text emission', () => {
586548 } ) ,
587549 )
588550 await handler . options . onResponseChunk (
589- responseChunk ( handler , {
590- type : 'text' ,
591- text : 'Second section' ,
592- } ) ,
551+ responseChunk ( handler , 'Second section' ) ,
593552 )
594553 await handler . options . onResponseChunk (
595554 responseChunk ( handler , {
@@ -674,22 +633,13 @@ describe('run() text emission', () => {
674633 const handler = await waitForHandler ( )
675634
676635 await handler . options . onResponseChunk (
677- responseChunk ( handler , {
678- type : 'text' ,
679- text : 'Before <codebuff_tool_call>{"a":1}' ,
680- } ) ,
636+ responseChunk ( handler , 'Before <codebuff_tool_call>{"a":1}' ) ,
681637 )
682638 await handler . options . onResponseChunk (
683- responseChunk ( handler , {
684- type : 'text' ,
685- text : '</codebuff_tool_call>' ,
686- } ) ,
639+ responseChunk ( handler , '</codebuff_tool_call>' ) ,
687640 )
688641 await handler . options . onResponseChunk (
689- responseChunk ( handler , {
690- type : 'text' ,
691- text : ' after' ,
692- } ) ,
642+ responseChunk ( handler , ' after' ) ,
693643 )
694644 await handler . options . onResponseChunk (
695645 responseChunk ( handler , {
@@ -706,6 +656,6 @@ describe('run() text emission', () => {
706656 event . type === 'text' ,
707657 )
708658
709- expect ( textEvents . map ( ( event ) => event . text ) ) . toEqual ( [ 'Before' , ' after'] )
659+ expect ( textEvents . map ( ( event ) => event . text ) ) . toEqual ( [ 'Before after' ] )
710660 } )
711661} )
0 commit comments