11// pnpm --filter @roo-code/types test src/__tests__/message.test.ts
22
3- import { clineAsks , isIdleAsk , isInteractiveAsk , isResumableAsk , isNonBlockingAsk } from "../message.js"
3+ import {
4+ clineAsks ,
5+ getCompletionCheckpoint ,
6+ isIdleAsk ,
7+ isInteractiveAsk ,
8+ isResumableAsk ,
9+ isNonBlockingAsk ,
10+ type ClineMessage ,
11+ } from "../message.js"
412
513describe ( "ask messages" , ( ) => {
614 test ( "all ask messages are classified" , ( ) => {
@@ -12,3 +20,46 @@ describe("ask messages", () => {
1220 }
1321 } )
1422} )
23+
24+ describe ( "getCompletionCheckpoint" , ( ) => {
25+ it ( "returns the first checkpoint after the latest user prompt before completion" , ( ) => {
26+ const messages : ClineMessage [ ] = [
27+ { type : "say" , say : "text" , ts : 1 , text : "Initial task" } ,
28+ { type : "say" , say : "checkpoint_saved" , ts : 2 , text : "initial-checkpoint" } ,
29+ { type : "say" , say : "completion_result" , ts : 3 , text : "First completion" } ,
30+ { type : "say" , say : "user_feedback" , ts : 4 , text : "Change it" } ,
31+ { type : "say" , say : "checkpoint_saved" , ts : 5 , text : "latest-prompt-checkpoint" } ,
32+ { type : "say" , say : "checkpoint_saved" , ts : 6 , text : "later-edit-checkpoint" } ,
33+ { type : "ask" , ask : "completion_result" , ts : 7 , text : "" , partial : false } ,
34+ ]
35+
36+ expect ( getCompletionCheckpoint ( messages ) ) . toEqual ( {
37+ ts : 5 ,
38+ commitHash : "latest-prompt-checkpoint" ,
39+ } )
40+ } )
41+
42+ it ( "returns the first checkpoint after an initial task row before completion" , ( ) => {
43+ const messages : ClineMessage [ ] = [
44+ { type : "say" , say : "task" , ts : 1 , text : "Initial task" } ,
45+ { type : "say" , say : "checkpoint_saved" , ts : 2 , text : "checkpoint-after-initial-task" } ,
46+ { type : "ask" , ask : "completion_result" , ts : 3 , text : "Task complete" , partial : false } ,
47+ ]
48+
49+ expect ( getCompletionCheckpoint ( messages ) ) . toEqual ( {
50+ ts : 2 ,
51+ commitHash : "checkpoint-after-initial-task" ,
52+ } )
53+ } )
54+
55+ it ( "returns undefined when completion has no checkpoint after the latest user prompt" , ( ) => {
56+ const messages : ClineMessage [ ] = [
57+ { type : "say" , say : "text" , ts : 1 , text : "Initial task" } ,
58+ { type : "say" , say : "checkpoint_saved" , ts : 2 , text : "initial-checkpoint" } ,
59+ { type : "say" , say : "user_feedback" , ts : 3 , text : "Change it" } ,
60+ { type : "ask" , ask : "completion_result" , ts : 4 , text : "" , partial : false } ,
61+ ]
62+
63+ expect ( getCompletionCheckpoint ( messages ) ) . toBeUndefined ( )
64+ } )
65+ } )
0 commit comments