@@ -4,25 +4,18 @@ import * as os from "node:os";
44import * as path from "node:path" ;
55import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
66
7- async function probeFileSymlinkCapability ( ) : Promise < boolean > {
8- const probeDir = await fs . promises . mkdtemp (
9- path . join ( os . tmpdir ( ) , "openclaw-qqbot-symlink-probe-" ) ,
10- ) ;
11- const targetFile = path . join ( probeDir , "target.txt" ) ;
12- const linkFile = path . join ( probeDir , "link.txt" ) ;
7+ async function createSymlinkedFile ( targetPath : string , linkPath : string ) : Promise < boolean > {
138 try {
14- await fs . promises . writeFile ( targetFile , "content " ) ;
15- await fs . promises . symlink ( targetFile , linkFile ) ;
9+ await fs . promises . writeFile ( targetPath , "image-bytes " ) ;
10+ await fs . promises . symlink ( targetPath , linkPath , "file" ) ;
1611 return true ;
1712 } catch {
13+ await fs . promises . rm ( linkPath , { force : true } ) ;
14+ await fs . promises . rm ( targetPath , { force : true } ) ;
1815 return false ;
19- } finally {
20- await fs . promises . rm ( probeDir , { recursive : true , force : true } ) ;
2116 }
2217}
2318
24- const canCreateFileSymlinks = await probeFileSymlinkCapability ( ) ;
25-
2619const adapterMocks = vi . hoisted ( ( ) => ( {
2720 fetchMedia : vi . fn ( ) ,
2821} ) ) ;
@@ -116,11 +109,12 @@ describe("qqbot file-utils downloadFile", () => {
116109 expect ( adapterMocks . fetchMedia ) . not . toHaveBeenCalled ( ) ;
117110 } ) ;
118111
119- it . skipIf ( ! canCreateFileSymlinks ) ( "rejects symlinked local media helpers" , async ( ) => {
112+ it ( "rejects symlinked local media helpers" , async ( { skip } ) => {
120113 const targetPath = path . join ( tempDir , "target.png" ) ;
121114 const linkPath = path . join ( tempDir , "link.png" ) ;
122- await fs . promises . writeFile ( targetPath , "image-bytes" ) ;
123- await fs . promises . symlink ( targetPath , linkPath ) ;
115+ if ( ! ( await createSymlinkedFile ( targetPath , linkPath ) ) ) {
116+ skip ( "file symlinks are unavailable on this host" ) ;
117+ }
124118
125119 expect ( checkFileSize ( linkPath ) . ok ) . toBe ( false ) ;
126120 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