@@ -26,6 +26,7 @@ describe("webviewMessageHandler - checkpoint operations", () => {
2626 // Setup mock Cline instance
2727 mockCline = {
2828 taskId : "test-task-123" ,
29+ isInitialized : true ,
2930 clineMessages : [
3031 { ts : 1 , type : "user" , say : "user" , text : "First message" } ,
3132 { ts : 2 , type : "assistant" , say : "checkpoint_saved" , text : "abc123" } ,
@@ -37,6 +38,7 @@ describe("webviewMessageHandler - checkpoint operations", () => {
3738 { ts : 3 , role : "user" , content : [ { type : "text" , text : "Message to delete" } ] } ,
3839 { ts : 4 , role : "assistant" , content : [ { type : "text" , text : "After message" } ] } ,
3940 ] ,
41+ checkpointDiff : vi . fn ( ) ,
4042 checkpointRestore : vi . fn ( ) ,
4143 overwriteClineMessages : vi . fn ( ) ,
4244 overwriteApiConversationHistory : vi . fn ( ) ,
@@ -52,6 +54,7 @@ describe("webviewMessageHandler - checkpoint operations", () => {
5254 } ) ) ,
5355 createTaskWithHistoryItem : vi . fn ( ) ,
5456 setPendingEditOperation : vi . fn ( ) ,
57+ cancelTask : vi . fn ( ) ,
5558 contextProxy : {
5659 globalStorageUri : { fsPath : "/test/storage" } ,
5760 } ,
@@ -134,4 +137,53 @@ describe("webviewMessageHandler - checkpoint operations", () => {
134137 } )
135138 } )
136139 } )
140+
141+ describe ( "completion checkpoint actions" , ( ) => {
142+ beforeEach ( ( ) => {
143+ mockCline . clineMessages = [
144+ { ts : 1 , type : "say" , say : "text" , text : "Initial task" } ,
145+ { ts : 2 , type : "say" , say : "checkpoint_saved" , text : "initial-checkpoint" } ,
146+ { ts : 3 , type : "say" , say : "user_feedback" , text : "Latest prompt" } ,
147+ { ts : 4 , type : "say" , say : "checkpoint_saved" , text : "latest-prompt-checkpoint" } ,
148+ { ts : 5 , type : "say" , say : "completion_result" , text : "Task complete" } ,
149+ { ts : 6 , type : "ask" , ask : "completion_result" , text : "" , partial : false } ,
150+ ]
151+ } )
152+
153+ it ( "diffs changes from the checkpoint created after the latest prompt" , async ( ) => {
154+ await webviewMessageHandler ( mockProvider , { type : "completionCheckpointDiff" } )
155+
156+ expect ( mockCline . checkpointDiff ) . toHaveBeenCalledWith ( {
157+ ts : 4 ,
158+ commitHash : "latest-prompt-checkpoint" ,
159+ mode : "to-current" ,
160+ } )
161+ } )
162+
163+ it ( "restores files and task state to the checkpoint created after the latest prompt" , async ( ) => {
164+ await webviewMessageHandler ( mockProvider , { type : "completionCheckpointRestore" } )
165+
166+ expect ( mockProvider . cancelTask ) . toHaveBeenCalled ( )
167+ expect ( mockCline . checkpointRestore ) . toHaveBeenCalledWith ( {
168+ ts : 4 ,
169+ commitHash : "latest-prompt-checkpoint" ,
170+ mode : "restore" ,
171+ } )
172+ } )
173+
174+ it ( "does not diff or restore when no latest-prompt checkpoint exists" , async ( ) => {
175+ mockCline . clineMessages = [
176+ { ts : 1 , type : "say" , say : "text" , text : "Initial task" } ,
177+ { ts : 2 , type : "say" , say : "user_feedback" , text : "Latest prompt" } ,
178+ { ts : 3 , type : "ask" , ask : "completion_result" , text : "" , partial : false } ,
179+ ]
180+
181+ await webviewMessageHandler ( mockProvider , { type : "completionCheckpointDiff" } )
182+ await webviewMessageHandler ( mockProvider , { type : "completionCheckpointRestore" } )
183+
184+ expect ( mockCline . checkpointDiff ) . not . toHaveBeenCalled ( )
185+ expect ( mockCline . checkpointRestore ) . not . toHaveBeenCalled ( )
186+ expect ( mockProvider . cancelTask ) . not . toHaveBeenCalled ( )
187+ } )
188+ } )
137189} )
0 commit comments