@@ -228,10 +228,7 @@ describe("createLaneTextDeliverer", () => {
228228 expect ( answer . update ) . toHaveBeenCalledWith ( previousBlock ) ;
229229 expect ( answer . update ) . not . toHaveBeenCalledWith ( nextAssistantBlock ) ;
230230 expect ( harness . clearDraftLane ) . toHaveBeenCalledTimes ( 1 ) ;
231- expect ( harness . sendPayload ) . toHaveBeenCalledWith (
232- { text : previousBlock } ,
233- { durable : false } ,
234- ) ;
231+ expect ( harness . sendPayload ) . toHaveBeenCalledWith ( { text : previousBlock } , { durable : false } ) ;
235232 expect ( harness . sendPayload ) . not . toHaveBeenCalledWith (
236233 { text : nextAssistantBlock } ,
237234 expect . anything ( ) ,
@@ -924,7 +921,7 @@ describe("createLaneTextDeliverer", () => {
924921 expect ( harness . markDelivered ) . toHaveBeenCalledTimes ( 1 ) ;
925922 } ) ;
926923
927- it ( "does not resend chunks retained while stopping a long streamed final " , async ( ) => {
924+ it ( "sends chunks after the reported delivered text when stop advances the retained index " , async ( ) => {
928925 const answer = createTestDraftStream ( { messageId : 999 } ) ;
929926 const harness = createHarness ( {
930927 answerStream : answer ,
@@ -940,11 +937,35 @@ describe("createLaneTextDeliverer", () => {
940937
941938 const delivery = expectPreviewFinalized ( result ) ;
942939 expect ( delivery . content ) . toBe ( "Hello world again" ) ;
943- expect ( harness . sendPayload ) . toHaveBeenCalledTimes ( 1 ) ;
944- expect ( harness . sendPayload ) . toHaveBeenCalledWith ( { text : " again" } ) ;
940+ expect ( delivery . promptContextContent ) . toBe ( "Hello" ) ;
941+ expect ( harness . sendPayload ) . toHaveBeenCalledTimes ( 2 ) ;
942+ expect ( harness . sendPayload ) . toHaveBeenNthCalledWith ( 1 , { text : " world" } ) ;
943+ expect ( harness . sendPayload ) . toHaveBeenNthCalledWith ( 2 , { text : " again" } ) ;
945944 expect ( harness . markDelivered ) . toHaveBeenCalledTimes ( 1 ) ;
946945 } ) ;
947946
947+ it ( "does not skip middle chunks when stop advances past the reported delivered chunk" , async ( ) => {
948+ const answer = createTestDraftStream ( { messageId : 999 } ) ;
949+ const harness = createHarness ( {
950+ answerStream : answer ,
951+ draftMaxChars : 6 ,
952+ splitFinalTextForStream : ( ) => [ "chunk0" , "chunk1" , "chunk2" , "chunk3" ] ,
953+ } ) ;
954+ harness . lanes . answer . hasStreamedMessage = true ;
955+ answer . stop . mockImplementation ( async ( ) => {
956+ harness . lanes . answer . activeChunkIndex = 2 ;
957+ } ) ;
958+
959+ const result = await deliverFinalAnswer ( harness , "chunk0chunk1chunk2chunk3" ) ;
960+
961+ const delivery = expectPreviewFinalized ( result ) ;
962+ expect ( delivery . promptContextContent ) . toBe ( "chunk0" ) ;
963+ expect ( harness . sendPayload ) . toHaveBeenCalledTimes ( 3 ) ;
964+ expect ( harness . sendPayload ) . toHaveBeenNthCalledWith ( 1 , { text : "chunk1" } ) ;
965+ expect ( harness . sendPayload ) . toHaveBeenNthCalledWith ( 2 , { text : "chunk2" } ) ;
966+ expect ( harness . sendPayload ) . toHaveBeenNthCalledWith ( 3 , { text : "chunk3" } ) ;
967+ } ) ;
968+
948969 it ( "compares retained delivered prefixes against the full final text" , async ( ) => {
949970 let deliveredText = "Hello" ;
950971 const answer = createTestDraftStream ( { messageId : 999 } ) ;
@@ -995,11 +1016,15 @@ describe("createLaneTextDeliverer", () => {
9951016 expect ( harness . editStreamMessage ) . toHaveBeenCalledWith ( {
9961017 laneName : "answer" ,
9971018 messageId : 999 ,
998- text : " world " ,
1019+ text : "Hello " ,
9991020 buttons,
10001021 } ) ;
1001- expect ( harness . sendPayload ) . toHaveBeenCalledTimes ( 1 ) ;
1002- expect ( harness . sendPayload ) . toHaveBeenCalledWith ( {
1022+ expect ( harness . sendPayload ) . toHaveBeenCalledTimes ( 2 ) ;
1023+ expect ( harness . sendPayload ) . toHaveBeenNthCalledWith ( 1 , {
1024+ text : " world" ,
1025+ channelData : { telegram : { buttons } } ,
1026+ } ) ;
1027+ expect ( harness . sendPayload ) . toHaveBeenNthCalledWith ( 2 , {
10031028 text : " again" ,
10041029 channelData : { telegram : { buttons } } ,
10051030 } ) ;
0 commit comments