@@ -99,6 +99,7 @@ describe("Checkpoint functionality", () => {
9999 apiConversationHistory : [ ] ,
100100 pendingUserMessageCheckpoint : undefined ,
101101 say : vi . fn ( ) . mockResolvedValue ( undefined ) ,
102+ abortTask : vi . fn ( ) . mockResolvedValue ( undefined ) ,
102103 ensureApiConversationHistoryStored : vi . fn ( ) . mockResolvedValue ( true ) ,
103104 overwriteClineMessages : vi . fn ( ) ,
104105 overwriteApiConversationHistory : vi . fn ( ) ,
@@ -619,6 +620,47 @@ describe("Checkpoint functionality", () => {
619620 )
620621 // Not started again from two sides that are not the same conversation.
621622 expect ( mockProvider . cancelTask ) . not . toHaveBeenCalled ( )
623+ expect ( mockTask . abortTask ) . toHaveBeenCalledTimes ( 1 ) // and the task that is there does not go on
624+ } )
625+
626+ it . each ( [ "delete" , "edit" ] as const ) (
627+ "stops the task that is still running after a partly rewound conversation, for %s, and says so when it cannot" ,
628+ async ( operation ) => {
629+ keepWhatIsWritten ( )
630+ mockTask . ensureApiConversationHistoryStored . mockResolvedValueOnce ( false )
631+ mockTask . overwriteClineMessages
632+ . mockImplementationOnce ( async ( messages : unknown [ ] ) => {
633+ mockTask . clineMessages = messages
634+ } )
635+ . mockRejectedValueOnce ( new Error ( "disk full" ) )
636+ mockTask . abortTask . mockRejectedValueOnce ( new Error ( "cannot stop" ) )
637+
638+ await expect (
639+ checkpointRestore ( mockTask , { ts : 2 , commitHash : RESTORE_HASH , mode : "restore" , operation } ) ,
640+ ) . rejects . toMatchObject ( { name : "ConversationRewindError" , restarted : false } )
641+
642+ expect ( mockTask . abortTask ) . toHaveBeenCalledTimes ( 1 )
643+ expect ( mockProvider . log ) . toHaveBeenCalledWith (
644+ expect . stringContaining ( "the task could not be stopped: cannot stop" ) ,
645+ )
646+ expect ( mockProvider . cancelTask ) . not . toHaveBeenCalled ( )
647+ } ,
648+ )
649+
650+ it ( "does not stop the task when the messages were put back, since it is restarted from a consistent conversation" , async ( ) => {
651+ keepWhatIsWritten ( )
652+ mockTask . ensureApiConversationHistoryStored . mockResolvedValueOnce ( false )
653+
654+ await expect (
655+ checkpointRestore ( mockTask , {
656+ ts : 2 ,
657+ commitHash : RESTORE_HASH ,
658+ mode : "restore" ,
659+ operation : "edit" ,
660+ } ) ,
661+ ) . rejects . toMatchObject ( { restarted : true } )
662+
663+ expect ( mockTask . abortTask ) . not . toHaveBeenCalled ( )
622664 } )
623665
624666 it ( "tells a failure that is not an Error as text, in the message about a conversation that is only partly rewound" , async ( ) => {
0 commit comments