@@ -350,10 +350,11 @@ describe("CliManager", () => {
350350 it ( "cleans up old files before download" , async ( ) => {
351351 // Create old temporary files and signature files
352352 vol . mkdirSync ( BINARY_DIR , { recursive : true } ) ;
353- memfs . writeFileSync ( path . join ( BINARY_DIR , "coder.old-xyz" ) , "old" ) ;
354- memfs . writeFileSync ( path . join ( BINARY_DIR , "coder.temp-abc" ) , "temp" ) ;
353+ writeOldFile ( path . join ( BINARY_DIR , "coder.old-xyz" ) , "old" ) ;
354+ writeOldFile ( path . join ( BINARY_DIR , "coder.temp-abc" ) , "temp" ) ;
355+ writeOldFile ( path . join ( BINARY_DIR , "keeper.txt" ) , "keep" ) ;
356+ // New files won't be deleted
355357 memfs . writeFileSync ( path . join ( BINARY_DIR , "coder.asc" ) , "signature" ) ;
356- memfs . writeFileSync ( path . join ( BINARY_DIR , "keeper.txt" ) , "keep" ) ;
357358
358359 withSuccessfulDownload ( ) ;
359360 await manager . fetchBinary ( mockApi , "test" ) ;
@@ -365,7 +366,7 @@ describe("CliManager", () => {
365366 expect ( memfs . existsSync ( path . join ( BINARY_DIR , "coder.temp-abc" ) ) ) . toBe (
366367 false ,
367368 ) ;
368- expect ( memfs . existsSync ( path . join ( BINARY_DIR , "coder.asc" ) ) ) . toBe ( false ) ;
369+ expect ( memfs . existsSync ( path . join ( BINARY_DIR , "coder.asc" ) ) ) . toBe ( true ) ;
369370 expect ( memfs . existsSync ( path . join ( BINARY_DIR , "keeper.txt" ) ) ) . toBe ( true ) ;
370371 } ) ;
371372
@@ -783,17 +784,23 @@ describe("CliManager", () => {
783784 vi . mocked ( error . summary ) . mockReturnValue ( "Signature does not match" ) ;
784785 return error ;
785786 }
787+ } ) ;
786788
787- function mockBinaryContent ( version : string ) : string {
788- return `mock-binary-v${ version } ` ;
789- }
789+ function mockBinaryContent ( version : string ) : string {
790+ return `mock-binary-v${ version } ` ;
791+ }
790792
791- function expectFileInDir ( dir : string , pattern : string ) : string | undefined {
792- const files = readdir ( dir ) ;
793- return files . find ( ( f ) => f . includes ( pattern ) ) ;
794- }
793+ function expectFileInDir ( dir : string , pattern : string ) : string | undefined {
794+ const files = readdir ( dir ) ;
795+ return files . find ( ( f ) => f . includes ( pattern ) ) ;
796+ }
795797
796- function readdir ( dir : string ) : string [ ] {
797- return memfs . readdirSync ( dir ) as string [ ] ;
798- }
799- } ) ;
798+ function readdir ( dir : string ) : string [ ] {
799+ return memfs . readdirSync ( dir ) as string [ ] ;
800+ }
801+
802+ function writeOldFile ( filePath : string , content : string ) : void {
803+ const oldTime = Date . now ( ) - 60 * 60 * 1000 ; // 60 minutes ago
804+ memfs . writeFileSync ( filePath , content ) ;
805+ memfs . utimesSync ( filePath , oldTime / 1000 , oldTime / 1000 ) ;
806+ }
0 commit comments