@@ -17,6 +17,7 @@ import {
1717} from "./backup-shared.js" ;
1818import {
1919 backupVerifyCommandMock ,
20+ createMockTarStream ,
2021 createBackupTestRuntime ,
2122 mockStateOnlyBackupPlan ,
2223 resetBackupTempHome ,
@@ -78,9 +79,7 @@ describe("backup commands", () => {
7879 beforeEach ( async ( ) => {
7980 await resetBackupTempHome ( tempHome ) ;
8081 tarCreateMock . mockReset ( ) ;
81- tarCreateMock . mockImplementation ( async ( { file } : { file : string } ) => {
82- await fs . writeFile ( file , "archive-bytes" , "utf8" ) ;
83- } ) ;
82+ tarCreateMock . mockImplementation ( ( ) => createMockTarStream ( ) ) ;
8483 backupVerifyCommandMock . mockReset ( ) ;
8584 backupVerifyCommandMock . mockResolvedValue ( {
8685 ok : true ,
@@ -268,17 +267,16 @@ describe("backup commands", () => {
268267 } ) ,
269268 ) ;
270269 tarCreateMock . mockImplementationOnce (
271- async (
272- options : { file : string ; onWriteEntry ?: ( entry : { path : string } ) => void } ,
273- entryPaths : string [ ] ,
274- ) => {
275- capturedManifest = JSON . parse (
276- await fs . readFile ( entryPaths [ 0 ] , "utf8" ) ,
277- ) as CapturedBackupManifest ;
278- capturedEntryPaths = entryPaths ;
279- capturedOnWriteEntry = options . onWriteEntry ?? null ;
280- await fs . writeFile ( options . file , "archive-bytes" , "utf8" ) ;
281- } ,
270+ ( options : { onWriteEntry ?: ( entry : { path : string } ) => void } , entryPaths : string [ ] ) =>
271+ createMockTarStream ( {
272+ beforeRead : async ( ) => {
273+ capturedManifest = JSON . parse (
274+ await fs . readFile ( entryPaths [ 0 ] , "utf8" ) ,
275+ ) as CapturedBackupManifest ;
276+ capturedEntryPaths = entryPaths ;
277+ capturedOnWriteEntry = options . onWriteEntry ?? null ;
278+ } ,
279+ } ) ,
282280 ) ;
283281 const result = await backupCreateCommand ( runtime , {
284282 output : backupDir ,
@@ -367,21 +365,20 @@ describe("backup commands", () => {
367365 const runtime = createBackupTestRuntime ( ) ;
368366 await mockStateOnlyBackupPlan ( stateDir ) ;
369367 tarCreateMock . mockImplementationOnce (
370- async (
371- options : { file : string ; filter ?: ( entryPath : string ) => boolean } ,
372- entryPaths : string [ ] ,
373- ) => {
374- const manifestPath = entryPaths [ 0 ] ;
375- const stateRoot = entryPaths [ 1 ] ;
376- if ( ! manifestPath || ! stateRoot ) {
377- throw new Error ( "backup test expected manifest and state entries" ) ;
378- }
379- expect ( options . filter ?.( manifestPath ) ) . toBe ( true ) ;
380- expect (
381- options . filter ?.( path . join ( stateRoot , "agents" , "main" , "sessions" , "s.jsonl" ) ) ,
382- ) . toBe ( false ) ;
383- await fs . writeFile ( options . file , "archive-bytes" , "utf8" ) ;
384- } ,
368+ ( options : { filter ?: ( entryPath : string ) => boolean } , entryPaths : string [ ] ) =>
369+ createMockTarStream ( {
370+ beforeRead : ( ) => {
371+ const manifestPath = entryPaths [ 0 ] ;
372+ const stateRoot = entryPaths [ 1 ] ;
373+ if ( ! manifestPath || ! stateRoot ) {
374+ throw new Error ( "backup test expected manifest and state entries" ) ;
375+ }
376+ expect ( options . filter ?.( manifestPath ) ) . toBe ( true ) ;
377+ expect (
378+ options . filter ?.( path . join ( stateRoot , "agents" , "main" , "sessions" , "s.jsonl" ) ) ,
379+ ) . toBe ( false ) ;
380+ } ,
381+ } ) ,
385382 ) ;
386383
387384 const result = await backupCreateCommand ( runtime , {
0 commit comments