@@ -3435,6 +3435,36 @@ describe("dispatchTelegramMessage draft streaming", () => {
34353435 expect ( updates . join ( "\n" ) ) . not . toContain ( "CheckingReading" ) ;
34363436 } ) ;
34373437
3438+ it ( "clears the prior reasoning preview before splitting into a new reasoning message" , async ( ) => {
3439+ const answerDraftStream = createDraftStream ( 2001 ) ;
3440+ const reasoningDraftStream = createTestDraftStream ( {
3441+ messageId : 3001 ,
3442+ clearMessageIdOnForceNew : true ,
3443+ } ) ;
3444+ createTelegramDraftStream
3445+ . mockImplementationOnce ( ( ) => answerDraftStream )
3446+ . mockImplementationOnce ( ( ) => reasoningDraftStream ) ;
3447+ dispatchReplyWithBufferedBlockDispatcher . mockImplementation ( async ( { replyOptions } ) => {
3448+ await replyOptions ?. onReasoningStream ?.( { text : "<think>First thought</think>" } ) ;
3449+ await replyOptions ?. onReasoningEnd ?.( ) ;
3450+ await replyOptions ?. onReasoningStream ?.( { text : "<think>Second thought</think>" } ) ;
3451+ return { queuedFinal : false } ;
3452+ } ) ;
3453+
3454+ await dispatchWithContext ( { context : createReasoningStreamContext ( ) } ) ;
3455+
3456+ expect ( reasoningDraftStream . update ) . toHaveBeenCalledWith ( "Thinking\n\n_First thought_" ) ;
3457+ expect ( reasoningDraftStream . update ) . toHaveBeenCalledWith ( "Thinking\n\n_Second thought_" ) ;
3458+ expect ( reasoningDraftStream . forceNewMessage ) . toHaveBeenCalledTimes ( 1 ) ;
3459+ expect ( reasoningDraftStream . clear ) . toHaveBeenCalledTimes ( 2 ) ;
3460+ expect ( reasoningDraftStream . clear . mock . invocationCallOrder [ 0 ] ) . toBeLessThan (
3461+ reasoningDraftStream . forceNewMessage . mock . invocationCallOrder [ 0 ] ,
3462+ ) ;
3463+ expect ( reasoningDraftStream . clear . mock . invocationCallOrder [ 0 ] ) . toBeLessThan (
3464+ reasoningDraftStream . update . mock . invocationCallOrder [ 1 ] ,
3465+ ) ;
3466+ } ) ;
3467+
34383468 it ( "streams reasoning from configured defaults" , async ( ) => {
34393469 const { answerDraftStream, reasoningDraftStream } = setupDraftStreams ( {
34403470 answerMessageId : 2001 ,
0 commit comments