diff --git a/actions/setup/js/handle_noop_message.cjs b/actions/setup/js/handle_noop_message.cjs index 34df5bebe8..71f4fc6c39 100644 --- a/actions/setup/js/handle_noop_message.cjs +++ b/actions/setup/js/handle_noop_message.cjs @@ -37,7 +37,7 @@ async function ensureAgentRunsIssue() { }; } } catch (error) { - core.warning(`Error searching for no-op runs issue: ${getErrorMessage(error)}`); + throw new Error(`Failed to search for existing no-op runs issue: ${getErrorMessage(error)}`); } // Create no-op runs issue if it doesn't exist diff --git a/actions/setup/js/handle_noop_message.test.cjs b/actions/setup/js/handle_noop_message.test.cjs index d9c95d8026..a0dcd5c08e 100644 --- a/actions/setup/js/handle_noop_message.test.cjs +++ b/actions/setup/js/handle_noop_message.test.cjs @@ -480,6 +480,36 @@ This issue helps you: expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("Could not create no-op runs issue")); }); + it("should not create issue when search throws (prevents duplicate issues)", async () => { + process.env.GH_AW_WORKFLOW_NAME = "Test Workflow"; + process.env.GH_AW_RUN_URL = "https://github.com/test-owner/test-repo/actions/runs/789"; + process.env.GH_AW_NOOP_MESSAGE = "All checks passed"; + process.env.GH_AW_AGENT_CONCLUSION = "success"; + + // Create agent output file with only noop outputs + const outputFile = path.join(tempDir, "agent_output.json"); + fs.writeFileSync( + outputFile, + JSON.stringify({ + items: [{ type: "noop", message: "All checks passed" }], + }) + ); + process.env.GH_AW_AGENT_OUTPUT = outputFile; + + // Mock search failure (e.g. transient API error) + mockGithub.rest.search.issuesAndPullRequests.mockRejectedValue(new Error("API rate limit exceeded")); + + const { main } = await import("./handle_noop_message.cjs?t=" + Date.now()); + await main(); + + // Search error should be caught and logged as a warning (via ensureAgentRunsIssue throw → main catch) + expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("Could not create no-op runs issue")); + // Issue must NOT be created to prevent duplicates + expect(mockGithub.rest.issues.create).not.toHaveBeenCalled(); + // Comment must NOT be posted + expect(mockGithub.rest.issues.createComment).not.toHaveBeenCalled(); + }); + it("should extract run ID from URL correctly", async () => { process.env.GH_AW_WORKFLOW_NAME = "Test"; process.env.GH_AW_RUN_URL = "https://github.com/owner/repo/actions/runs/987654321";