@@ -331,6 +331,144 @@ describe("createChannelProgressDraftCompositor", () => {
331331 expect ( rendered ) . toContain ( "Shelling\n\n💬 _Checking the workspace_" ) ;
332332 } ) ;
333333
334+ it ( "collapses cumulative id-less commentary snapshots onto one line" , async ( ) => {
335+ const update = vi . fn ( ) ;
336+ const progress = createChannelProgressDraftCompositor ( {
337+ entry : { streaming : { mode : "progress" , progress : { label : "Shelling" , commentary : true } } } ,
338+ mode : "progress" ,
339+ active : true ,
340+ seed : "test" ,
341+ commentaryLinePrefix : "💬 " ,
342+ update,
343+ } ) ;
344+
345+ expect ( await progress . pushCommentaryProgress ( "Checking" ) ) . toBe ( true ) ;
346+ expect ( await progress . pushCommentaryProgress ( "Checking the workspace" ) ) . toBe ( true ) ;
347+ expect ( await progress . pushCommentaryProgress ( "Checking the workspace before answering." ) ) . toBe (
348+ true ,
349+ ) ;
350+
351+ expect ( update ) . toHaveBeenLastCalledWith (
352+ "Shelling\n\n💬 _Checking the workspace before answering._" ,
353+ {
354+ lines : [
355+ expect . objectContaining ( {
356+ text : "💬 _Checking the workspace before answering._" ,
357+ kind : "item" ,
358+ label : "Commentary" ,
359+ } ) ,
360+ ] ,
361+ } ,
362+ ) ;
363+ expect ( progress . getSnapshot ( ) . lines ) . toHaveLength ( 1 ) ;
364+ } ) ;
365+
366+ it ( "appends genuinely distinct id-less commentary as separate lines" , async ( ) => {
367+ const update = vi . fn ( ) ;
368+ const progress = createChannelProgressDraftCompositor ( {
369+ entry : { streaming : { mode : "progress" , progress : { label : "Shelling" , commentary : true } } } ,
370+ mode : "progress" ,
371+ active : true ,
372+ seed : "test" ,
373+ commentaryLinePrefix : "💬 " ,
374+ update,
375+ } ) ;
376+
377+ expect ( await progress . pushCommentaryProgress ( "Checking the workspace" ) ) . toBe ( true ) ;
378+ expect ( await progress . pushCommentaryProgress ( "Writing the patch next" ) ) . toBe ( true ) ;
379+
380+ expect ( update ) . toHaveBeenLastCalledWith (
381+ "Shelling\n\n💬 _Checking the workspace_\n💬 _Writing the patch next_" ,
382+ {
383+ lines : [
384+ expect . objectContaining ( { text : "💬 _Checking the workspace_" } ) ,
385+ expect . objectContaining ( { text : "💬 _Writing the patch next_" } ) ,
386+ ] ,
387+ } ,
388+ ) ;
389+ } ) ;
390+
391+ it ( "updates an id-less commentary line in place after a later tool line" , async ( ) => {
392+ const update = vi . fn ( ) ;
393+ const progress = createChannelProgressDraftCompositor ( {
394+ entry : { streaming : { mode : "progress" , progress : { label : "Shelling" , commentary : true } } } ,
395+ mode : "progress" ,
396+ active : true ,
397+ seed : "test" ,
398+ commentaryLinePrefix : "💬 " ,
399+ update,
400+ } ) ;
401+
402+ await progress . pushCommentaryProgress ( "Checking" ) ;
403+ await progress . pushToolProgress ( "🛠️ Exec" , { startImmediately : true } ) ;
404+ await progress . pushCommentaryProgress ( "Checking the workspace" ) ;
405+
406+ expect ( update ) . toHaveBeenLastCalledWith ( "Shelling\n\n💬 _Checking the workspace_\n🛠️ Exec" , {
407+ lines : [ expect . objectContaining ( { text : "💬 _Checking the workspace_" } ) , "🛠️ Exec" ] ,
408+ } ) ;
409+ } ) ;
410+
411+ it ( "keeps id-less commentary when a later snapshot sanitizes to empty" , async ( ) => {
412+ const update = vi . fn ( ) ;
413+ const progress = createChannelProgressDraftCompositor ( {
414+ entry : { streaming : { mode : "progress" , progress : { label : "Shelling" , commentary : true } } } ,
415+ mode : "progress" ,
416+ active : true ,
417+ seed : "test" ,
418+ commentaryLinePrefix : "💬 " ,
419+ update,
420+ } ) ;
421+
422+ expect ( await progress . pushCommentaryProgress ( "Checking the workspace" ) ) . toBe ( true ) ;
423+ const callsAfterValid = update . mock . calls . length ;
424+ expect (
425+ await progress . pushCommentaryProgress ( "[[reply_to_current]] _NO_REPLY_ [[audio_as_voice]]" ) ,
426+ ) . toBe ( false ) ;
427+
428+ expect ( update ) . toHaveBeenCalledTimes ( callsAfterValid ) ;
429+ expect ( update ) . toHaveBeenLastCalledWith (
430+ "Shelling\n\n💬 _Checking the workspace_" ,
431+ expect . objectContaining ( {
432+ lines : [ expect . objectContaining ( { text : "💬 _Checking the workspace_" } ) ] ,
433+ } ) ,
434+ ) ;
435+ expect ( progress . getSnapshot ( ) . lines ) . toHaveLength ( 1 ) ;
436+ } ) ;
437+
438+ it ( "replaces and retracts commentary by itemId" , async ( ) => {
439+ const update = vi . fn ( ) ;
440+ const progress = createChannelProgressDraftCompositor ( {
441+ entry : { streaming : { mode : "progress" , progress : { label : "Shelling" , commentary : true } } } ,
442+ mode : "progress" ,
443+ active : true ,
444+ seed : "test" ,
445+ commentaryLinePrefix : "💬 " ,
446+ update,
447+ } ) ;
448+
449+ expect ( await progress . pushCommentaryProgress ( "First note" , { itemId : "c1" } ) ) . toBe ( true ) ;
450+ expect ( await progress . pushCommentaryProgress ( "Updated note" , { itemId : "c1" } ) ) . toBe ( true ) ;
451+ expect ( await progress . pushCommentaryProgress ( "Other note" , { itemId : "c2" } ) ) . toBe ( true ) ;
452+ expect ( progress . getSnapshot ( ) . lines ) . toHaveLength ( 2 ) ;
453+ expect ( update ) . toHaveBeenLastCalledWith (
454+ "Shelling\n\n💬 _Updated note_\n💬 _Other note_" ,
455+ expect . objectContaining ( {
456+ lines : [
457+ expect . objectContaining ( { id : "commentary:c1" , text : "💬 _Updated note_" } ) ,
458+ expect . objectContaining ( { id : "commentary:c2" , text : "💬 _Other note_" } ) ,
459+ ] ,
460+ } ) ,
461+ ) ;
462+
463+ expect ( await progress . pushCommentaryProgress ( "" , { itemId : "c1" } ) ) . toBe ( false ) ;
464+ expect ( update ) . toHaveBeenLastCalledWith (
465+ "Shelling\n\n💬 _Other note_" ,
466+ expect . objectContaining ( {
467+ lines : [ expect . objectContaining ( { id : "commentary:c2" , text : "💬 _Other note_" } ) ] ,
468+ } ) ,
469+ ) ;
470+ } ) ;
471+
334472 it ( "interleaves reasoning bursts with tool calls in arrival order" , async ( ) => {
335473 const update = vi . fn ( ) ;
336474 const progress = createChannelProgressDraftCompositor ( {
0 commit comments