@@ -40,18 +40,15 @@ describe("qqbot file-utils MIME helpers", () => {
4040 } ) ;
4141} ) ;
4242
43- async function canCreateFileSymlink ( ) : Promise < boolean > {
44- const probeDir = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , "qqbot-symlink-probe-" ) ) ;
45- const targetPath = path . join ( probeDir , "target.txt" ) ;
46- const linkPath = path . join ( probeDir , "link.txt" ) ;
43+ async function createSymlinkedFile ( targetPath : string , linkPath : string ) : Promise < boolean > {
4744 try {
48- await fs . promises . writeFile ( targetPath , "probe " ) ;
45+ await fs . promises . writeFile ( targetPath , "image-bytes " ) ;
4946 await fs . promises . symlink ( targetPath , linkPath , "file" ) ;
5047 return true ;
5148 } catch {
49+ await fs . promises . rm ( linkPath , { force : true } ) ;
50+ await fs . promises . rm ( targetPath , { force : true } ) ;
5251 return false ;
53- } finally {
54- await fs . promises . rm ( probeDir , { recursive : true , force : true } ) ;
5552 }
5653}
5754
@@ -115,14 +112,11 @@ describe("qqbot file-utils downloadFile", () => {
115112 // Keep the local skipIf shape while probing inside the test, avoiding
116113 // import-time filesystem side effects on hosts that cannot create links.
117114 it . skipIf ( false ) ( "rejects symlinked local media helpers" , async ( { skip } ) => {
118- if ( ! ( await canCreateFileSymlink ( ) ) ) {
119- skip ( "file symlinks are unavailable on this host" ) ;
120- }
121-
122115 const targetPath = path . join ( tempDir , "target.png" ) ;
123116 const linkPath = path . join ( tempDir , "link.png" ) ;
124- await fs . promises . writeFile ( targetPath , "image-bytes" ) ;
125- await fs . promises . symlink ( targetPath , linkPath , "file" ) ;
117+ if ( ! ( await createSymlinkedFile ( targetPath , linkPath ) ) ) {
118+ skip ( "file symlinks are unavailable on this host" ) ;
119+ }
126120
127121 expect ( checkFileSize ( linkPath ) . ok ) . toBe ( false ) ;
128122 await expect ( readFileAsync ( linkPath ) ) . rejects . toThrow ( / s y m b o l i c l i n k | s y m l i n k | r e g u l a r f i l e / i) ;
0 commit comments