@@ -2436,6 +2436,34 @@ describe("dispatchTelegramMessage draft streaming", () => {
24362436 ) ;
24372437 } ) ;
24382438
2439+ it ( "clears progress drafts before visible tool artifacts" , async ( ) => {
2440+ const { answerDraftStream } = setupDraftStreams ( { answerMessageId : 2001 } ) ;
2441+ dispatchReplyWithBufferedBlockDispatcher . mockImplementation (
2442+ async ( { dispatcherOptions, replyOptions } ) => {
2443+ await replyOptions ?. onToolStart ?.( { name : "exec" , phase : "start" } ) ;
2444+ await dispatcherOptions . deliver (
2445+ { mediaUrl : "https://example.com/validation.txt" } ,
2446+ { kind : "tool" } ,
2447+ ) ;
2448+ await dispatcherOptions . deliver ( { text : "Final answer" } , { kind : "final" } ) ;
2449+ return { queuedFinal : true } ;
2450+ } ,
2451+ ) ;
2452+
2453+ await dispatchWithContext ( {
2454+ context : createContext ( ) ,
2455+ streamMode : "progress" ,
2456+ telegramCfg : { streaming : { mode : "progress" , progress : { label : "Shelling" } } } ,
2457+ } ) ;
2458+
2459+ expect ( answerDraftStream . update ) . toHaveBeenCalledWith ( "Shelling\n\n`🛠️ Exec`" ) ;
2460+ expectDeliveredReply ( 0 , { mediaUrl : "https://example.com/validation.txt" } ) ;
2461+ expectDeliveredReply ( 0 , { text : "Final answer" } , 1 ) ;
2462+ expect ( answerDraftStream . clear . mock . invocationCallOrder [ 0 ] ) . toBeLessThan (
2463+ deliverReplies . mock . invocationCallOrder [ 0 ] ,
2464+ ) ;
2465+ } ) ;
2466+
24392467 it ( "does not stream text-only tool results into progress drafts" , async ( ) => {
24402468 const { answerDraftStream } = setupDraftStreams ( { answerMessageId : 2001 } ) ;
24412469 dispatchReplyWithBufferedBlockDispatcher . mockImplementation (
0 commit comments