@@ -25,27 +25,35 @@ vi.mock("@roo-code/telemetry", () => ({
2525 * (journal dir + setting state), and say. Structural cast at the boundary,
2626 * matching the documented test-double style of the tool specs.
2727 */
28- function makeTask ( options : { saveCheckpoint ?: unknown ; state ?: Record < string , unknown > ; enableCheckpoints ?: boolean } ) {
28+ function makeTask ( options : {
29+ saveCheckpoint ?: unknown
30+ state ?: Record < string , unknown >
31+ enableCheckpoints ?: boolean
32+ storageDir ?: string | null
33+ } ) {
2934 const say = vi . fn ( ) . mockResolvedValue ( undefined )
3035 // An explicit `saveCheckpoint: undefined` (a checkpoint that produced no
3136 // commit) must be preserved as-is; only an omitted option falls back to
3237 // the default commit result.
3338 const saveCheckpoint = vi
3439 . fn ( )
3540 . mockResolvedValue ( "saveCheckpoint" in options ? options . saveCheckpoint : { commit : "sha-card-1" } )
41+ // `storageDir: null` simulates a checkpoint-service init failure: the
42+ // service lookup dereferences globalStorageUri, throws, and resolves to
43+ // no service while the task still expects checkpoints (enableCheckpoints
44+ // stays true until the failed lookup flips it).
3645 const providerDeref = {
37- context : { globalStorageUri : { fsPath : globalStorageDir } } ,
46+ context : { globalStorageUri : options . storageDir === null ? undefined : { fsPath : globalStorageDir } } ,
3847 getState : vi . fn ( ) . mockResolvedValue ( options . state ?? { } ) ,
3948 }
4049
4150 const task = {
4251 taskId : "task-card" ,
4352 cwd : "/workspace" ,
4453 enableCheckpoints : options . enableCheckpoints ?? true ,
45- checkpointService : {
46- saveCheckpoint,
47- isInitialized : true ,
48- } ,
54+ // With `storageDir: null` there is no preset service either, so the
55+ // lookup runs for real and fails on the missing storage dir.
56+ checkpointService : options . storageDir === null ? undefined : { saveCheckpoint, isInitialized : true } ,
4957 providerRef : { deref : vi . fn ( ) . mockReturnValue ( providerDeref ) } ,
5058 say,
5159 } as unknown as Task
@@ -208,8 +216,25 @@ describe("checkpointSave change-card emission (B3a)", () => {
208216 expect ( cardCalls ) . toHaveLength ( 0 )
209217 } )
210218
211- it ( "fails a write-metadata save when checkpoints are disabled for the task and emits no card" , async ( ) => {
212- const { task, say } = makeTask ( { enableCheckpoints : false } )
219+ it ( "resolves a write-metadata save when checkpoints are disabled for the task and emits no card" , async ( ) => {
220+ // Documented contract: user-disabled checkpoints means the absence of
221+ // rollback metadata is the user's choice, so the save must not fail the
222+ // write tool.
223+ const { task, say, saveCheckpoint } = makeTask ( { enableCheckpoints : false } )
224+
225+ await expect (
226+ checkpointSave ( task , false , true , { path : "src/a.ts" , operation : "create" , diff : "+x" } ) ,
227+ ) . resolves . toBeUndefined ( )
228+
229+ expect ( saveCheckpoint ) . not . toHaveBeenCalled ( )
230+ expect ( say ) . not . toHaveBeenCalled ( )
231+ } )
232+
233+ it ( "fails a write-metadata save when the checkpoint-service lookup fails and emits no card" , async ( ) => {
234+ // Documented contract: with checkpoints requested (enableCheckpoints
235+ // true) a failed service lookup is a genuine init-failure - the write
236+ // would be orphaned, so the save must surface it.
237+ const { task, say } = makeTask ( { storageDir : null } )
213238
214239 await expect (
215240 checkpointSave ( task , false , true , { path : "src/a.ts" , operation : "create" , diff : "+x" } ) ,
0 commit comments