@@ -114,6 +114,47 @@ describe("downloadFileToCacheDir", () => {
114114 expect ( output ) . toBe ( expectPointer ) ;
115115 } ) ;
116116
117+ test ( "existing symlinked and blob with default revision should not re-download it" , async ( ) => {
118+ // <cache>/<repo>/<revision>/snapshots/README.md
119+ const expectPointer = _getSnapshotFile ( {
120+ repo : DUMMY_REPO ,
121+ path : "/README.md" ,
122+ revision : "main" ,
123+ } ) ;
124+ // stat ensure a symlink and the pointed file exists
125+ vi . mocked ( stat ) . mockResolvedValue ( { } as Stats ) ; // prevent default mocked reject
126+ vi . mocked ( lstat ) . mockResolvedValue ( { } as Stats ) ;
127+ vi . mocked ( pathsInfo ) . mockResolvedValue ( [
128+ {
129+ oid : DUMMY_ETAG ,
130+ size : 55 ,
131+ path : "README.md" ,
132+ type : "file" ,
133+ lastCommit : {
134+ date : new Date ( ) ,
135+ id : "main" ,
136+ title : "Commit msg" ,
137+ } ,
138+ } ,
139+ ] ) ;
140+
141+ const output = await downloadFileToCacheDir ( {
142+ repo : DUMMY_REPO ,
143+ path : "/README.md" ,
144+ fetch : fetchMock ,
145+ } ) ;
146+
147+ expect ( stat ) . toHaveBeenCalledOnce ( ) ;
148+ expect ( symlink ) . not . toHaveBeenCalledOnce ( ) ;
149+ // Get call argument for stat
150+ const starArg = vi . mocked ( stat ) . mock . calls [ 0 ] [ 0 ] ;
151+
152+ expect ( starArg ) . toBe ( expectPointer ) ;
153+ expect ( fetchMock ) . not . toHaveBeenCalledWith ( ) ;
154+
155+ expect ( output ) . toBe ( expectPointer ) ;
156+ } ) ;
157+
117158 test ( "existing blob should only create the symlink" , async ( ) => {
118159 // <cache>/<repo>/<revision>/snapshots/README.md
119160 const expectPointer = _getSnapshotFile ( {
@@ -150,7 +191,6 @@ describe("downloadFileToCacheDir", () => {
150191 fetch : fetchMock ,
151192 } ) ;
152193
153- expect ( stat ) . not . toHaveBeenCalled ( ) ;
154194 // should have check for the blob
155195 expect ( lstat ) . toHaveBeenCalled ( ) ;
156196 expect ( vi . mocked ( lstat ) . mock . calls [ 0 ] [ 0 ] ) . toBe ( expectedBlob ) ;
0 commit comments