@@ -3846,7 +3846,7 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
38463846 ) ;
38473847 } ) ;
38483848
3849- it ( "forces a new draft message on assistant boundaries in partial mode " , async ( ) => {
3849+ it ( "clears interrupted partial previews when the turn finishes silently " , async ( ) => {
38503850 const draftStream = createDraftStreamStub ( ) ;
38513851 createSlackDraftStreamMock . mockReturnValueOnce ( draftStream ) ;
38523852 mockedSlackStreamingMode = "partial" ;
@@ -3861,8 +3861,28 @@ describe("dispatchPreparedSlackMessage preview fallback", () => {
38613861 await dispatchPreparedSlackMessage ( createPreparedSlackMessage ( { } ) ) ;
38623862
38633863 expect ( draftStream . forceNewMessage ) . toHaveBeenCalledTimes ( 1 ) ;
3864- // Detached-message cleanup is card-only: a rotated partial preview still
3865- // holds streamed assistant text and must survive dispatch closeout.
3864+ expect ( draftStream . clear ) . toHaveBeenCalledOnce ( ) ;
3865+ expect ( draftStream . dropDetachedMessages ) . toHaveBeenCalledOnce ( ) ;
3866+ expect ( draftStream . dropDetachedMessages . mock . invocationCallOrder [ 0 ] ) . toBeGreaterThan (
3867+ draftStream . clear . mock . invocationCallOrder [ 0 ] ?? Number . POSITIVE_INFINITY ,
3868+ ) ;
3869+ } ) ;
3870+
3871+ it ( "preserves interrupted partial previews when a final reply is delivered" , async ( ) => {
3872+ const draftStream = createDraftStreamStub ( ) ;
3873+ createSlackDraftStreamMock . mockReturnValueOnce ( draftStream ) ;
3874+ mockedSlackStreamingMode = "partial" ;
3875+ mockedSlackDraftMode = "replace" ;
3876+ mockedReplyOptionEvents = [
3877+ { kind : "partial" , text : "first chunk" } ,
3878+ { kind : "assistant_start" } ,
3879+ { kind : "partial" , text : "second chunk" } ,
3880+ ] ;
3881+ mockedDispatchSequence = [ { kind : "final" , payload : { text : FINAL_REPLY_TEXT } } ] ;
3882+
3883+ await dispatchPreparedSlackMessage ( createPreparedSlackMessage ( { } ) ) ;
3884+
3885+ expect ( draftStream . forceNewMessage ) . toHaveBeenCalledTimes ( 1 ) ;
38663886 expect ( draftStream . dropDetachedMessages ) . not . toHaveBeenCalled ( ) ;
38673887 } ) ;
38683888
0 commit comments