@@ -2061,6 +2061,37 @@ describe("processDiscordMessage draft streaming", () => {
20612061 expect ( deliverDiscordReply ) . toHaveBeenCalledTimes ( 1 ) ;
20622062 } ) ;
20632063
2064+ it ( "keeps finalized previews when later tool warning finals are delivered" , async ( ) => {
2065+ const draftStream = createMockDraftStreamForTest ( ) ;
2066+ dispatchInboundMessage . mockImplementationOnce ( async ( params ?: DispatchInboundParams ) => {
2067+ await params ?. dispatcher . sendFinalReply ( { text : "delivery survived" } ) ;
2068+ await params ?. dispatcher . sendFinalReply ( {
2069+ text : "⚠️ 🛠️ `run openclaw definitely-not-a-real-subcommand (agent)` failed" ,
2070+ isError : true ,
2071+ } as never ) ;
2072+ return { queuedFinal : true , counts : { final : 2 , tool : 0 , block : 0 } } ;
2073+ } ) ;
2074+
2075+ const ctx = await createAutomaticSourceDeliveryContext ( {
2076+ discordConfig : { streamMode : "partial" , maxLinesPerMessage : 5 } ,
2077+ } ) ;
2078+
2079+ await runProcessDiscordMessage ( ctx ) ;
2080+
2081+ expectPreviewEditContent ( "delivery survived" ) ;
2082+ expect ( draftStream . clear ) . not . toHaveBeenCalled ( ) ;
2083+ expect ( draftStream . messageId ( ) ) . toBe ( "preview-1" ) ;
2084+ expect ( deliverDiscordReply ) . toHaveBeenCalledTimes ( 1 ) ;
2085+ expect ( firstMockArg ( deliverDiscordReply , "deliverDiscordReply" ) ) . toMatchObject ( {
2086+ replies : [
2087+ {
2088+ text : "⚠️ 🛠️ `run openclaw definitely-not-a-real-subcommand (agent)` failed" ,
2089+ isError : true ,
2090+ } ,
2091+ ] ,
2092+ } ) ;
2093+ } ) ;
2094+
20642095 it ( "suppresses reasoning payload delivery to Discord" , async ( ) => {
20652096 mockDispatchSingleBlockReply ( { text : "thinking..." , isReasoning : true } ) ;
20662097 await processStreamOffDiscordMessage ( ) ;
0 commit comments