@@ -12,17 +12,12 @@ import {
1212 resolveBackupPlanFromDisk ,
1313} from "./backup-shared.js" ;
1414import { backupCreateCommand } from "./backup.js" ;
15-
16- const tarCreateMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
17- const backupVerifyCommandMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
18-
19- vi . mock ( "tar" , ( ) => ( {
20- c : tarCreateMock ,
21- } ) ) ;
22-
23- vi . mock ( "./backup-verify.js" , ( ) => ( {
24- backupVerifyCommand : backupVerifyCommandMock ,
25- } ) ) ;
15+ import {
16+ backupVerifyCommandMock ,
17+ createBackupTestRuntime ,
18+ mockStateOnlyBackupPlan ,
19+ tarCreateMock ,
20+ } from "./backup.test-support.js" ;
2621
2722describe ( "backup commands" , ( ) => {
2823 let tempHome : TempHomeEnv ;
@@ -63,21 +58,13 @@ describe("backup commands", () => {
6358 await tempHome . restore ( ) ;
6459 } ) ;
6560
66- function createRuntime ( ) : RuntimeEnv {
67- return {
68- log : vi . fn ( ) ,
69- error : vi . fn ( ) ,
70- exit : vi . fn ( ) ,
71- } satisfies RuntimeEnv ;
72- }
73-
7461 async function withInvalidWorkspaceBackupConfig < T > ( fn : ( runtime : RuntimeEnv ) => Promise < T > ) {
7562 const stateDir = path . join ( tempHome . home , ".openclaw" ) ;
7663 const configPath = path . join ( tempHome . home , "custom-config.json" ) ;
7764 process . env . OPENCLAW_CONFIG_PATH = configPath ;
7865 await fs . writeFile ( path . join ( stateDir , "openclaw.json" ) , JSON . stringify ( { } ) , "utf8" ) ;
7966 await fs . writeFile ( configPath , '{"agents": { defaults: { workspace: ' , "utf8" ) ;
80- const runtime = createRuntime ( ) ;
67+ const runtime = createBackupTestRuntime ( ) ;
8168
8269 try {
8370 return await fn ( runtime ) ;
@@ -175,7 +162,7 @@ describe("backup commands", () => {
175162 await fs . writeFile ( path . join ( stateDir , "state.txt" ) , "state\n" , "utf8" ) ;
176163 await fs . writeFile ( path . join ( externalWorkspace , "SOUL.md" ) , "# external\n" , "utf8" ) ;
177164
178- const runtime = createRuntime ( ) ;
165+ const runtime = createBackupTestRuntime ( ) ;
179166
180167 const nowMs = Date . UTC ( 2026 , 2 , 9 , 0 , 0 , 0 ) ;
181168 vi . spyOn ( backupShared , "resolveBackupPlanFromDisk" ) . mockResolvedValue (
@@ -269,18 +256,8 @@ describe("backup commands", () => {
269256 const stateDir = path . join ( tempHome . home , ".openclaw" ) ;
270257 await fs . writeFile ( path . join ( stateDir , "openclaw.json" ) , JSON . stringify ( { } ) , "utf8" ) ;
271258
272- const runtime = createRuntime ( ) ;
273- vi . spyOn ( backupShared , "resolveBackupPlanFromDisk" ) . mockResolvedValue (
274- await resolveBackupPlanFromPaths ( {
275- stateDir,
276- configPath : path . join ( stateDir , "openclaw.json" ) ,
277- oauthDir : path . join ( stateDir , "credentials" ) ,
278- includeWorkspace : false ,
279- configInsideState : true ,
280- oauthInsideState : true ,
281- nowMs : 123 ,
282- } ) ,
283- ) ;
259+ const runtime = createBackupTestRuntime ( ) ;
260+ await mockStateOnlyBackupPlan ( stateDir ) ;
284261
285262 await expect (
286263 backupCreateCommand ( runtime , {
@@ -301,18 +278,8 @@ describe("backup commands", () => {
301278 await fs . writeFile ( path . join ( stateDir , "openclaw.json" ) , JSON . stringify ( { } ) , "utf8" ) ;
302279 await fs . symlink ( stateDir , symlinkPath ) ;
303280
304- const runtime = createRuntime ( ) ;
305- vi . spyOn ( backupShared , "resolveBackupPlanFromDisk" ) . mockResolvedValue (
306- await resolveBackupPlanFromPaths ( {
307- stateDir,
308- configPath : path . join ( stateDir , "openclaw.json" ) ,
309- oauthDir : path . join ( stateDir , "credentials" ) ,
310- includeWorkspace : false ,
311- configInsideState : true ,
312- oauthInsideState : true ,
313- nowMs : 123 ,
314- } ) ,
315- ) ;
281+ const runtime = createBackupTestRuntime ( ) ;
282+ await mockStateOnlyBackupPlan ( stateDir ) ;
316283
317284 await expect (
318285 backupCreateCommand ( runtime , {
@@ -344,7 +311,7 @@ describe("backup commands", () => {
344311 } ) ,
345312 ) ;
346313
347- const runtime = createRuntime ( ) ;
314+ const runtime = createBackupTestRuntime ( ) ;
348315
349316 const nowMs = Date . UTC ( 2026 , 2 , 9 , 1 , 2 , 3 ) ;
350317 const result = await backupCreateCommand ( runtime , { nowMs } ) ;
@@ -383,7 +350,7 @@ describe("backup commands", () => {
383350 } ) ,
384351 ) ;
385352
386- const runtime = createRuntime ( ) ;
353+ const runtime = createBackupTestRuntime ( ) ;
387354
388355 const nowMs = Date . UTC ( 2026 , 2 , 9 , 1 , 3 , 4 ) ;
389356 const result = await backupCreateCommand ( runtime , { nowMs } ) ;
@@ -414,7 +381,7 @@ describe("backup commands", () => {
414381 } ) ,
415382 ) ;
416383
417- const runtime = createRuntime ( ) ;
384+ const runtime = createBackupTestRuntime ( ) ;
418385
419386 const result = await backupCreateCommand ( runtime , {
420387 output : existingArchive ,
@@ -467,7 +434,7 @@ describe("backup commands", () => {
467434 } ) ,
468435 ) ;
469436
470- const runtime = createRuntime ( ) ;
437+ const runtime = createBackupTestRuntime ( ) ;
471438
472439 const result = await backupCreateCommand ( runtime , {
473440 dryRun : true ,
@@ -485,7 +452,7 @@ describe("backup commands", () => {
485452 process . env . OPENCLAW_CONFIG_PATH = configPath ;
486453 await fs . writeFile ( configPath , '{"agents": { defaults: { workspace: ' , "utf8" ) ;
487454
488- const runtime = createRuntime ( ) ;
455+ const runtime = createBackupTestRuntime ( ) ;
489456
490457 try {
491458 const result = await backupCreateCommand ( runtime , {
0 commit comments