@@ -3,7 +3,7 @@ import os from 'node:os';
33import path from 'node:path' ;
44import util from 'node:util' ;
55
6- import { afterEach , beforeEach , describe , expect , it } from 'vitest' ;
6+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
77
88import { Cache } from '../src/Cache' ;
99
@@ -88,5 +88,25 @@ describe('Cache', () => {
8888 expect ( cachePath . startsWith ( cacheDir ) ) . toEqual ( true ) ;
8989 expect ( await util . promisify ( fs . readFile ) ( cachePath , 'utf8' ) ) . toEqual ( 'example content' ) ;
9090 } ) ;
91+
92+ it ( 'can handle cross-device cache paths' , async ( ) => {
93+ const error : NodeJS . ErrnoException = new Error ( 'EXDEV: cross-device link not permitted' ) ;
94+ error . code = 'EXDEV' ;
95+
96+ const spy = vi . spyOn ( fs . promises , 'rename' ) . mockRejectedValueOnce ( error ) ;
97+
98+ try {
99+ const originalFolder = path . resolve ( cacheDir , sanitizedDummyUrl ) ;
100+ await fs . promises . mkdir ( originalFolder , { recursive : true } ) ;
101+ const originalPath = path . resolve ( originalFolder , 'original.txt' ) ;
102+ await util . promisify ( fs . writeFile ) ( originalPath , 'example content' ) ;
103+ const cachePath = await cache . putFileInCache ( dummyUrl , originalPath , 'test.txt' ) ;
104+ expect ( cachePath . startsWith ( cacheDir ) ) . toEqual ( true ) ;
105+ expect ( await util . promisify ( fs . readFile ) ( cachePath , 'utf8' ) ) . toEqual ( 'example content' ) ;
106+ expect ( spy ) . toHaveBeenCalled ( ) ;
107+ } finally {
108+ spy . mockRestore ( ) ;
109+ }
110+ } ) ;
91111 } ) ;
92112} ) ;
0 commit comments