@@ -650,6 +650,86 @@ describe("followup queue collect routing", () => {
650650 expect ( calls [ 1 ] ?. originatingTo ) . toBe ( "channel:B" ) ;
651651 } ) ;
652652
653+ it . each ( [
654+ { disposition : "deliver" , elided : false } ,
655+ { disposition : "drop" , elided : false } ,
656+ { disposition : "deliver" , elided : true } ,
657+ { disposition : "drop" , elided : true } ,
658+ ] as const ) (
659+ "keeps the WebChat $disposition owner on overflow summaries (elided: $elided)" ,
660+ async ( { disposition, elided } ) => {
661+ const key = `test-webchat-overflow-delivery-${ disposition } -${ elided } -${ Date . now ( ) } ` ;
662+ const settings = createQueueSettings ( { cap : 1 } ) ;
663+ const delivered : string [ ] = [ ] ;
664+ const sourceDisposition =
665+ disposition === "deliver"
666+ ? {
667+ kind : "deliver" as const ,
668+ deliver : async ( batch : { payloads : Array < { text ?: string } > } ) => {
669+ delivered . push ( batch . payloads [ 0 ] ?. text ?? "" ) ;
670+ } ,
671+ }
672+ : { kind : "drop" as const , reason : "source-unavailable" as const } ;
673+ const dropped = createRun ( {
674+ prompt : "overflowed WebChat message" ,
675+ originatingChannel : "webchat" ,
676+ originatingChatType : "direct" ,
677+ } ) ;
678+ dropped . queuedFollowupReplyDisposition = sourceDisposition ;
679+ enqueueFollowupRun ( key , dropped , settings ) ;
680+ if ( elided ) {
681+ enqueueTestRun (
682+ key ,
683+ {
684+ prompt : "separate overflow route" ,
685+ originatingChannel : "webchat" ,
686+ originatingChatType : "group" ,
687+ } ,
688+ settings ,
689+ ) ;
690+ }
691+ enqueueTestRun (
692+ key ,
693+ {
694+ prompt : "live WebChat message" ,
695+ originatingChannel : "webchat" ,
696+ originatingChatType : elided ? "group" : "direct" ,
697+ } ,
698+ settings ,
699+ ) ;
700+
701+ const expectedCalls = elided ? 3 : 2 ;
702+ const { calls, done } = createDrainRecorder ( expectedCalls ) ;
703+ const unrelatedDispatcher = vi . fn ( ) ;
704+ scheduleFollowupDrain ( key , async ( run ) => {
705+ calls . push ( run ) ;
706+ if ( run . prompt . includes ( "overflowed WebChat message" ) ) {
707+ const owner = run . queuedFollowupReplyDisposition ;
708+ if ( owner ?. kind === "deliver" ) {
709+ await owner . deliver ( {
710+ kind : "queued-followup" ,
711+ runId : "overflow-summary-run" ,
712+ originatingChannel : "webchat" ,
713+ payloads : [ { text : "overflow summary reached its owner" } ] ,
714+ } ) ;
715+ } else if ( owner ?. kind !== "drop" ) {
716+ unrelatedDispatcher ( ) ;
717+ }
718+ }
719+ if ( calls . length >= expectedCalls ) {
720+ done . resolve ( ) ;
721+ }
722+ } ) ;
723+ await done . promise ;
724+
725+ expect ( calls [ 0 ] ?. queuedFollowupReplyDisposition ) . toBe ( sourceDisposition ) ;
726+ expect ( unrelatedDispatcher ) . not . toHaveBeenCalled ( ) ;
727+ expect ( delivered ) . toEqual (
728+ disposition === "deliver" ? [ "overflow summary reached its owner" ] : [ ] ,
729+ ) ;
730+ } ,
731+ ) ;
732+
653733 it ( "does not attribute elided private drops to a public summary" , async ( ) => {
654734 const { key, calls, done, runFollowup, settings } = createQueueCase (
655735 `test-collect-overflow-elided-context-${ Date . now ( ) } ` ,
0 commit comments