@@ -4,21 +4,24 @@ import path from "path";
44const mockCore = { debug : vi . fn ( ) , info : vi . fn ( ) , notice : vi . fn ( ) , warning : vi . fn ( ) , error : vi . fn ( ) , setFailed : vi . fn ( ) , setOutput : vi . fn ( ) , summary : { addRaw : vi . fn ( ) . mockReturnThis ( ) , write : vi . fn ( ) . mockResolvedValue ( void 0 ) } } ;
55( ( global . core = mockCore ) ,
66 describe ( "upload_assets.cjs" , ( ) => {
7- let uploadAssetsScript , mockExec , tempFilePath ;
7+ let uploadAssetsScript , mockExec , tempFilePath , tempBase ;
88 const setAgentOutput = data => {
9- tempFilePath = path . join ( "/tmp" , `test_agent_output_ ${ Date . now ( ) } _ ${ Math . random ( ) . toString ( 36 ) . slice ( 2 ) } . json` ) ;
9+ tempFilePath = path . join ( tempBase , "agent_output. json" ) ;
1010 const content = "string" == typeof data ? data : JSON . stringify ( data ) ;
1111 ( fs . writeFileSync ( tempFilePath , content ) , ( process . env . GH_AW_AGENT_OUTPUT = tempFilePath ) ) ;
1212 } ,
13- getAssetsDir = ( ) => path . join ( process . env . RUNNER_TEMP || "/tmp" , "gh-aw" , "safeoutputs" , "assets" ) ,
13+ getAssetsDir = ( ) => path . join ( tempBase , "safeoutputs" , "assets" ) ,
1414 executeScript = async ( ) => ( ( global . core = mockCore ) , ( global . exec = mockExec ) , await eval ( `(async () => { ${ uploadAssetsScript } ; await main(); })()` ) ) ;
1515 ( beforeEach ( ( ) => {
1616 ( vi . clearAllMocks ( ) , delete process . env . GH_AW_ASSETS_BRANCH , delete process . env . GH_AW_AGENT_OUTPUT , delete process . env . GH_AW_SAFE_OUTPUTS_STAGED ) ;
17+ tempBase = fs . mkdtempSync ( path . join ( "/tmp" , "test-gh-aw-" ) ) ;
1718 const scriptPath = path . join ( __dirname , "upload_assets.cjs" ) ;
1819 ( ( uploadAssetsScript = fs . readFileSync ( scriptPath , "utf8" ) ) , ( mockExec = { exec : vi . fn ( ) . mockResolvedValue ( 0 ) } ) ) ;
1920 } ) ,
2021 afterEach ( ( ) => {
21- tempFilePath && fs . existsSync ( tempFilePath ) && fs . unlinkSync ( tempFilePath ) ;
22+ tempBase && fs . existsSync ( tempBase ) && fs . rmSync ( tempBase , { recursive : ! 0 , force : ! 0 } ) ;
23+ tempBase = void 0 ;
24+ tempFilePath = void 0 ;
2225 } ) ,
2326 describe ( "git commit command - vulnerability fix" , ( ) => {
2427 it ( "should not wrap commit message in extra quotes to prevent command injection" , async ( ) => {
@@ -138,13 +141,11 @@ const mockCore = { debug: vi.fn(), info: vi.fn(), notice: vi.fn(), warning: vi.f
138141 fs . existsSync ( "test.png" ) && fs . unlinkSync ( "test.png" ) ) ;
139142 } ) ) ;
140143 describe ( "missing asset handling" , ( ) => {
141- it ( "should skip missing assets while uploading present assets from RUNNER_TEMP " , async ( ) => {
144+ it ( "should skip missing assets while uploading present assets" , async ( ) => {
142145 process . env . GH_AW_ASSETS_BRANCH = "assets/test-workflow" ;
143146 process . env . GH_AW_SAFE_OUTPUTS_STAGED = "false" ;
144- const runnerTempDir = fs . mkdtempSync ( path . join ( "/tmp" , "upload-assets-runner-temp-" ) ) ;
145- process . env . RUNNER_TEMP = runnerTempDir ;
146- const assetDir = path . join ( runnerTempDir , "gh-aw" , "safeoutputs" , "assets" ) ;
147- fs . mkdirSync ( assetDir , { recursive : ! 0 } ) ;
147+ const assetDir = getAssetsDir ( ) ;
148+ fs . existsSync ( assetDir ) || fs . mkdirSync ( assetDir , { recursive : ! 0 } ) ;
148149 const presentAssetSourcePath = path . join ( assetDir , "present.png" ) ;
149150 fs . writeFileSync ( presentAssetSourcePath , "present content" ) ;
150151 const crypto = require ( "crypto" ) ,
@@ -172,8 +173,6 @@ const mockCore = { debug: vi.fn(), info: vi.fn(), notice: vi.fn(), warning: vi.f
172173 uploadCountCall && expect ( uploadCountCall [ 1 ] ) . toBe ( "1" ) ;
173174 fs . existsSync ( presentAssetSourcePath ) && fs . unlinkSync ( presentAssetSourcePath ) ;
174175 fs . existsSync ( path . join ( process . cwd ( ) , presentTargetFile ) ) && fs . unlinkSync ( path . join ( process . cwd ( ) , presentTargetFile ) ) ;
175- fs . rmSync ( runnerTempDir , { recursive : ! 0 , force : ! 0 } ) ;
176- delete process . env . RUNNER_TEMP ;
177176 } ) ;
178177 } ) ;
179178 } ) ) ;
0 commit comments