@@ -496,8 +496,9 @@ describe("AcpRuntimeModel", () => {
496496 expect ( finalDetail ?. endsWith ( `frame 999: ${ "#" . repeat ( 50 ) } ` ) ) . toBe ( true ) ;
497497 } ) ;
498498
499- it ( "keeps non-text tool call content entries when bounding an oversized text entry" , ( ) => {
500- const hugeText = "y" . repeat ( 50_000 ) ;
499+ it ( "keeps non-text tool call content entries in order when bounding oversized text" , ( ) => {
500+ const hugePrefix = "x" . repeat ( 25_000 ) ;
501+ const hugeTail = "y" . repeat ( 25_000 ) ;
501502 const { events } = parseSessionUpdateEvent ( {
502503 sessionId : "session-1" ,
503504 update : {
@@ -506,8 +507,11 @@ describe("AcpRuntimeModel", () => {
506507 kind : "edit" ,
507508 status : "in_progress" ,
508509 content : [
509- { type : "content" , content : { type : "text" , text : hugeText } } ,
510+ { type : "content" , content : { type : "text" , text : hugePrefix } } ,
510511 { type : "diff" , path : "/repo/file.ts" , oldText : "before" , newText : "after" } ,
512+ { type : "content" , content : { type : "text" , text : hugeTail } } ,
513+ { type : "diff" , path : "/repo/other.ts" , oldText : "old" , newText : "new" } ,
514+ { type : "content" , content : { type : "text" , text : " " } } ,
511515 ] ,
512516 } ,
513517 } satisfies EffectAcpSchema . SessionNotification ) ;
@@ -517,18 +521,25 @@ describe("AcpRuntimeModel", () => {
517521 throw new Error ( "expected a ToolCallUpdated event" ) ;
518522 }
519523 const content = event . toolCall . data . content as ReadonlyArray < EffectAcpSchema . ToolCallContent > ;
520- expect ( content ) . toHaveLength ( 2 ) ;
521- expect ( content [ 1 ] ) . toEqual ( {
524+ expect ( content ) . toHaveLength ( 3 ) ;
525+ expect ( content [ 0 ] ) . toEqual ( {
522526 type : "diff" ,
523527 path : "/repo/file.ts" ,
524528 oldText : "before" ,
525529 newText : "after" ,
526530 } ) ;
527- const firstEntry = content [ 0 ] ;
528- if ( firstEntry ?. type !== "content" || firstEntry . content . type !== "text" ) {
531+ const lastEntry = content [ 1 ] ;
532+ if ( lastEntry ?. type !== "content" || lastEntry . content . type !== "text" ) {
529533 throw new Error ( "expected a bounded text entry" ) ;
530534 }
531- expect ( firstEntry . content . text . length ) . toBeLessThan ( 8_100 ) ;
535+ expect ( lastEntry . content . text . length ) . toBeLessThan ( 8_100 ) ;
536+ expect ( lastEntry . content . text . endsWith ( hugeTail . slice ( - 100 ) ) ) . toBe ( true ) ;
537+ expect ( content [ 2 ] ) . toEqual ( {
538+ type : "diff" ,
539+ path : "/repo/other.ts" ,
540+ oldText : "old" ,
541+ newText : "new" ,
542+ } ) ;
532543 } ) ;
533544
534545 describe ( "decideToolCallUpdateEmission" , ( ) => {
@@ -611,5 +622,35 @@ describe("AcpRuntimeModel", () => {
611622 const emittedIndices = emissions . flatMap ( ( emitted , index ) => ( emitted ? [ index + 1 ] : [ ] ) ) ;
612623 expect ( emittedIndices ) . toEqual ( [ 1 , 11 ] ) ;
613624 } ) ;
625+
626+ it ( "retains the latest replacement snapshot when equal-length updates are coalesced" , ( ) => {
627+ let previous : AcpToolCallState = toolCall ( "frame-a" , "inProgress" ) ;
628+ const lastEmittedDetailLength = previous . detail ?. length ;
629+ let skippedSinceEmit = 0 ;
630+
631+ for ( const detail of [ "frame-b" , "frame-c" ] ) {
632+ const next = mergeToolCallState ( previous , toolCall ( detail , "inProgress" ) ) ;
633+ const decision = decideToolCallUpdateEmission ( {
634+ previous,
635+ next,
636+ lastEmittedDetailLength,
637+ skippedSinceEmit,
638+ } ) ;
639+ expect ( decision . emit ) . toBe ( false ) ;
640+ skippedSinceEmit = decision . skippedSinceEmit ;
641+ previous = next ;
642+ }
643+
644+ const completed = mergeToolCallState ( previous , toolCall ( undefined , "completed" ) ) ;
645+ expect ( completed . detail ) . toBe ( "frame-c" ) ;
646+ expect (
647+ decideToolCallUpdateEmission ( {
648+ previous,
649+ next : completed ,
650+ lastEmittedDetailLength,
651+ skippedSinceEmit,
652+ } ) ,
653+ ) . toEqual ( { emit : true , skippedSinceEmit : 0 } ) ;
654+ } ) ;
614655 } ) ;
615656} ) ;
0 commit comments