11// @ts -check
22
33import { describe , it , expect , beforeEach , afterEach , vi } from "vitest" ;
4-
5- // Mock load_agent_output at the module level
6- vi . mock ( "./load_agent_output.cjs" , ( ) => ( {
7- loadAgentOutput : vi . fn ( ) ,
8- } ) ) ;
4+ import fs from "fs" ;
5+ import path from "path" ;
6+ import os from "os" ;
97
108describe ( "handle_noop_message" , ( ) => {
119 let mockCore ;
1210 let mockGithub ;
1311 let mockContext ;
1412 let originalEnv ;
15- let mockLoadAgentOutput ;
13+ let tempDir ;
1614
1715 beforeEach ( async ( ) => {
1816 // Save original environment
1917 originalEnv = { ...process . env } ;
2018
21- // Get the mocked loadAgentOutput
22- const loadModule = await import ( "./load_agent_output.cjs" ) ;
23- mockLoadAgentOutput = loadModule . loadAgentOutput ;
19+ // Create temp directory for test files
20+ tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "handle-noop-test-" ) ) ;
2421
2522 // Mock core
2623 mockCore = {
@@ -59,6 +56,12 @@ describe("handle_noop_message", () => {
5956 afterEach ( ( ) => {
6057 // Restore environment
6158 process . env = originalEnv ;
59+
60+ // Clean up temp directory
61+ if ( tempDir && fs . existsSync ( tempDir ) ) {
62+ fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
63+ }
64+
6265 vi . clearAllMocks ( ) ;
6366 } ) ;
6467
@@ -94,14 +97,18 @@ describe("handle_noop_message", () => {
9497 process . env . GH_AW_NOOP_MESSAGE = "Some message" ;
9598 process . env . GH_AW_AGENT_CONCLUSION = "success" ;
9699
97- // Mock loadAgentOutput to return noop + other outputs
98- mockLoadAgentOutput . mockReturnValue ( {
99- success : true ,
100- items : [
101- { type : "noop" , message : "No action needed" } ,
102- { type : "create_issue" , title : "Some issue" } ,
103- ] ,
104- } ) ;
100+ // Create agent output file with noop + other outputs
101+ const outputFile = path . join ( tempDir , "agent_output.json" ) ;
102+ fs . writeFileSync (
103+ outputFile ,
104+ JSON . stringify ( {
105+ items : [
106+ { type : "noop" , message : "No action needed" } ,
107+ { type : "create_issue" , title : "Some issue" } ,
108+ ] ,
109+ } )
110+ ) ;
111+ process . env . GH_AW_AGENT_OUTPUT = outputFile ;
105112
106113 const { main } = await import ( "./handle_noop_message.cjs?t=" + Date . now ( ) ) ;
107114 await main ( ) ;
@@ -116,11 +123,15 @@ describe("handle_noop_message", () => {
116123 process . env . GH_AW_NOOP_MESSAGE = "No updates needed" ;
117124 process . env . GH_AW_AGENT_CONCLUSION = "success" ;
118125
119- // Mock loadAgentOutput to return only noop outputs
120- mockLoadAgentOutput . mockReturnValue ( {
121- success : true ,
122- items : [ { type : "noop" , message : "No updates needed" } ] ,
123- } ) ;
126+ // Create agent output file with only noop outputs
127+ const outputFile = path . join ( tempDir , "agent_output.json" ) ;
128+ fs . writeFileSync (
129+ outputFile ,
130+ JSON . stringify ( {
131+ items : [ { type : "noop" , message : "No updates needed" } ] ,
132+ } )
133+ ) ;
134+ process . env . GH_AW_AGENT_OUTPUT = outputFile ;
124135
125136 // Mock search to return no results
126137 mockGithub . rest . search . issuesAndPullRequests . mockResolvedValue ( {
@@ -176,11 +187,15 @@ describe("handle_noop_message", () => {
176187 process . env . GH_AW_NOOP_MESSAGE = "Everything is up to date" ;
177188 process . env . GH_AW_AGENT_CONCLUSION = "success" ;
178189
179- // Mock loadAgentOutput to return only noop outputs
180- mockLoadAgentOutput . mockReturnValue ( {
181- success : true ,
182- items : [ { type : "noop" , message : "Everything is up to date" } ] ,
183- } ) ;
190+ // Create agent output file with only noop outputs
191+ const outputFile = path . join ( tempDir , "agent_output.json" ) ;
192+ fs . writeFileSync (
193+ outputFile ,
194+ JSON . stringify ( {
195+ items : [ { type : "noop" , message : "Everything is up to date" } ] ,
196+ } )
197+ ) ;
198+ process . env . GH_AW_AGENT_OUTPUT = outputFile ;
184199
185200 // Mock search to return existing issue
186201 mockGithub . rest . search . issuesAndPullRequests . mockResolvedValue ( {
@@ -223,11 +238,15 @@ describe("handle_noop_message", () => {
223238 process . env . GH_AW_NOOP_MESSAGE = "No action required" ;
224239 process . env . GH_AW_AGENT_CONCLUSION = "success" ;
225240
226- // Mock loadAgentOutput to return only noop outputs
227- mockLoadAgentOutput . mockReturnValue ( {
228- success : true ,
229- items : [ { type : "noop" , message : "No action required" } ] ,
230- } ) ;
241+ // Create agent output file with only noop outputs
242+ const outputFile = path . join ( tempDir , "agent_output.json" ) ;
243+ fs . writeFileSync (
244+ outputFile ,
245+ JSON . stringify ( {
246+ items : [ { type : "noop" , message : "No action required" } ] ,
247+ } )
248+ ) ;
249+ process . env . GH_AW_AGENT_OUTPUT = outputFile ;
231250
232251 // Mock existing issue
233252 mockGithub . rest . search . issuesAndPullRequests . mockResolvedValue ( {
@@ -253,11 +272,15 @@ describe("handle_noop_message", () => {
253272 process . env . GH_AW_NOOP_MESSAGE = "All checks passed" ;
254273 process . env . GH_AW_AGENT_CONCLUSION = "success" ;
255274
256- // Mock loadAgentOutput to return only noop outputs
257- mockLoadAgentOutput . mockReturnValue ( {
258- success : true ,
259- items : [ { type : "noop" , message : "All checks passed" } ] ,
260- } ) ;
275+ // Create agent output file with only noop outputs
276+ const outputFile = path . join ( tempDir , "agent_output.json" ) ;
277+ fs . writeFileSync (
278+ outputFile ,
279+ JSON . stringify ( {
280+ items : [ { type : "noop" , message : "All checks passed" } ] ,
281+ } )
282+ ) ;
283+ process . env . GH_AW_AGENT_OUTPUT = outputFile ;
261284
262285 // Mock no existing issue
263286 mockGithub . rest . search . issuesAndPullRequests . mockResolvedValue ( {
@@ -280,11 +303,15 @@ describe("handle_noop_message", () => {
280303 process . env . GH_AW_NOOP_MESSAGE = "Done" ;
281304 process . env . GH_AW_AGENT_CONCLUSION = "success" ;
282305
283- // Mock loadAgentOutput to return only noop outputs
284- mockLoadAgentOutput . mockReturnValue ( {
285- success : true ,
286- items : [ { type : "noop" , message : "Done" } ] ,
287- } ) ;
306+ // Create agent output file with only noop outputs
307+ const outputFile = path . join ( tempDir , "agent_output.json" ) ;
308+ fs . writeFileSync (
309+ outputFile ,
310+ JSON . stringify ( {
311+ items : [ { type : "noop" , message : "Done" } ] ,
312+ } )
313+ ) ;
314+ process . env . GH_AW_AGENT_OUTPUT = outputFile ;
288315
289316 mockGithub . rest . search . issuesAndPullRequests . mockResolvedValue ( {
290317 data : { total_count : 1 , items : [ { number : 1 , node_id : "ID" , html_url : "url" } ] } ,
@@ -305,11 +332,15 @@ describe("handle_noop_message", () => {
305332 process . env . GH_AW_NOOP_MESSAGE = "Clean" ;
306333 process . env . GH_AW_AGENT_CONCLUSION = "success" ;
307334
308- // Mock loadAgentOutput to return only noop outputs
309- mockLoadAgentOutput . mockReturnValue ( {
310- success : true ,
311- items : [ { type : "noop" , message : "Clean" } ] ,
312- } ) ;
335+ // Create agent output file with only noop outputs
336+ const outputFile = path . join ( tempDir , "agent_output.json" ) ;
337+ fs . writeFileSync (
338+ outputFile ,
339+ JSON . stringify ( {
340+ items : [ { type : "noop" , message : "Clean" } ] ,
341+ } )
342+ ) ;
343+ process . env . GH_AW_AGENT_OUTPUT = outputFile ;
313344
314345 mockGithub . rest . search . issuesAndPullRequests . mockResolvedValue ( {
315346 data : { total_count : 1 , items : [ { number : 1 , node_id : "ID" , html_url : "url" } ] } ,
0 commit comments