From 36a6f967a2ef0640650ad228994609ac87fb93fc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 06:05:44 +0000 Subject: [PATCH 1/3] Initial plan From 4a44ddd754d6eea21c8f686568401a1fd496cef7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 06:16:58 +0000 Subject: [PATCH 2/3] Export main, remove automatic invocation in JavaScript files Fixed 10 JavaScript files to export main function instead of automatically invoking it: - actions/setup/js: checkout_pr_branch.cjs, add_copilot_reviewer.cjs, assign_issue.cjs, create_agent_task.cjs, push_repo_memory.cjs - pkg/workflow/js: checkout_pr_branch.cjs, add_copilot_reviewer.cjs, assign_issue.cjs, check_workflow_timestamp.cjs, create_agent_task.cjs, push_repo_memory.cjs Changed pattern from: main().catch(error => { core.setFailed(...); }); To: module.exports = { main }; This allows GitHub Actions workflows to import and call main() explicitly. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- actions/setup/js/add_copilot_reviewer.cjs | 4 +--- actions/setup/js/assign_issue.cjs | 4 +--- actions/setup/js/checkout_pr_branch.cjs | 4 +--- actions/setup/js/create_agent_task.cjs | 4 +--- actions/setup/js/push_repo_memory.cjs | 4 +--- pkg/workflow/js/add_copilot_reviewer.cjs | 4 +--- pkg/workflow/js/assign_issue.cjs | 4 +--- pkg/workflow/js/check_workflow_timestamp.cjs | 4 +--- pkg/workflow/js/create_agent_task.cjs | 4 +--- pkg/workflow/js/push_repo_memory.cjs | 4 +--- 10 files changed, 10 insertions(+), 30 deletions(-) diff --git a/actions/setup/js/add_copilot_reviewer.cjs b/actions/setup/js/add_copilot_reviewer.cjs index 40281e4bd8d..4da23077c20 100644 --- a/actions/setup/js/add_copilot_reviewer.cjs +++ b/actions/setup/js/add_copilot_reviewer.cjs @@ -58,6 +58,4 @@ Successfully added Copilot as a reviewer to PR #${prNumber}. } } -main().catch(error => { - core.setFailed(error instanceof Error ? error.message : String(error)); -}); +module.exports = { main }; diff --git a/actions/setup/js/assign_issue.cjs b/actions/setup/js/assign_issue.cjs index c94ef2a670e..0e5c0236fde 100644 --- a/actions/setup/js/assign_issue.cjs +++ b/actions/setup/js/assign_issue.cjs @@ -102,6 +102,4 @@ Successfully assigned issue #${trimmedIssueNumber} to \`${trimmedAssignee}\`. } } -main().catch(error => { - core.setFailed(error instanceof Error ? error.message : String(error)); -}); +module.exports = { main }; diff --git a/actions/setup/js/checkout_pr_branch.cjs b/actions/setup/js/checkout_pr_branch.cjs index 871162519b0..86f65dda234 100644 --- a/actions/setup/js/checkout_pr_branch.cjs +++ b/actions/setup/js/checkout_pr_branch.cjs @@ -42,6 +42,4 @@ async function main() { } } -main().catch(error => { - core.setFailed(error instanceof Error ? error.message : String(error)); -}); +module.exports = { main }; diff --git a/actions/setup/js/create_agent_task.cjs b/actions/setup/js/create_agent_task.cjs index 2ee0a659e11..f6f50f08c8f 100644 --- a/actions/setup/js/create_agent_task.cjs +++ b/actions/setup/js/create_agent_task.cjs @@ -174,6 +174,4 @@ async function main() { await core.summary.write(); } -main().catch(error => { - core.setFailed(error instanceof Error ? error.message : String(error)); -}); +module.exports = { main }; diff --git a/actions/setup/js/push_repo_memory.cjs b/actions/setup/js/push_repo_memory.cjs index 0d738404fc6..7aa19378caa 100644 --- a/actions/setup/js/push_repo_memory.cjs +++ b/actions/setup/js/push_repo_memory.cjs @@ -209,6 +209,4 @@ async function main() { } } -main().catch(error => { - core.setFailed(`Unexpected error: ${error instanceof Error ? error.message : String(error)}`); -}); +module.exports = { main }; diff --git a/pkg/workflow/js/add_copilot_reviewer.cjs b/pkg/workflow/js/add_copilot_reviewer.cjs index 40281e4bd8d..4da23077c20 100644 --- a/pkg/workflow/js/add_copilot_reviewer.cjs +++ b/pkg/workflow/js/add_copilot_reviewer.cjs @@ -58,6 +58,4 @@ Successfully added Copilot as a reviewer to PR #${prNumber}. } } -main().catch(error => { - core.setFailed(error instanceof Error ? error.message : String(error)); -}); +module.exports = { main }; diff --git a/pkg/workflow/js/assign_issue.cjs b/pkg/workflow/js/assign_issue.cjs index c94ef2a670e..0e5c0236fde 100644 --- a/pkg/workflow/js/assign_issue.cjs +++ b/pkg/workflow/js/assign_issue.cjs @@ -102,6 +102,4 @@ Successfully assigned issue #${trimmedIssueNumber} to \`${trimmedAssignee}\`. } } -main().catch(error => { - core.setFailed(error instanceof Error ? error.message : String(error)); -}); +module.exports = { main }; diff --git a/pkg/workflow/js/check_workflow_timestamp.cjs b/pkg/workflow/js/check_workflow_timestamp.cjs index a20f92cd758..7778299c0e9 100644 --- a/pkg/workflow/js/check_workflow_timestamp.cjs +++ b/pkg/workflow/js/check_workflow_timestamp.cjs @@ -99,6 +99,4 @@ async function main() { } } -main().catch(error => { - core.setFailed(error instanceof Error ? error.message : String(error)); -}); +module.exports = { main }; diff --git a/pkg/workflow/js/create_agent_task.cjs b/pkg/workflow/js/create_agent_task.cjs index 2ee0a659e11..f6f50f08c8f 100644 --- a/pkg/workflow/js/create_agent_task.cjs +++ b/pkg/workflow/js/create_agent_task.cjs @@ -174,6 +174,4 @@ async function main() { await core.summary.write(); } -main().catch(error => { - core.setFailed(error instanceof Error ? error.message : String(error)); -}); +module.exports = { main }; diff --git a/pkg/workflow/js/push_repo_memory.cjs b/pkg/workflow/js/push_repo_memory.cjs index 0d738404fc6..7aa19378caa 100644 --- a/pkg/workflow/js/push_repo_memory.cjs +++ b/pkg/workflow/js/push_repo_memory.cjs @@ -209,6 +209,4 @@ async function main() { } } -main().catch(error => { - core.setFailed(`Unexpected error: ${error instanceof Error ? error.message : String(error)}`); -}); +module.exports = { main }; From 2050dd20834ae8cca63937e6f05743171e27424a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 06:22:34 +0000 Subject: [PATCH 3/3] Fix tests for JavaScript files that now export main Updated tests to explicitly call main() for files that now export instead of auto-execute: - create_agent_task.test.cjs: Updated runScript to call main() - add_copilot_reviewer.test.cjs: Added runScript helper and updated all tests Tests for assign_issue and check_workflow_timestamp already used eval with explicit main() calls, so they work correctly. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- pkg/workflow/js/add_copilot_reviewer.test.cjs | 22 ++++++++++++------- pkg/workflow/js/create_agent_task.test.cjs | 3 ++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/workflow/js/add_copilot_reviewer.test.cjs b/pkg/workflow/js/add_copilot_reviewer.test.cjs index d2ef7af9288..03ad132413d 100644 --- a/pkg/workflow/js/add_copilot_reviewer.test.cjs +++ b/pkg/workflow/js/add_copilot_reviewer.test.cjs @@ -65,10 +65,16 @@ describe("add_copilot_reviewer", () => { }; }); + // Helper function to run the script with main() call + async function runScript() { + const { main } = await import("./add_copilot_reviewer.cjs?" + Date.now()); + await main(); + } + it("should fail when PR_NUMBER is not set", async () => { delete process.env.PR_NUMBER; - await import("./add_copilot_reviewer.cjs"); + await runScript(); expect(mockCore.setFailed).toHaveBeenCalledWith("PR_NUMBER environment variable is required but not set"); expect(mockGithub.rest.pulls.requestReviewers).not.toHaveBeenCalled(); @@ -77,7 +83,7 @@ describe("add_copilot_reviewer", () => { it("should fail when PR_NUMBER is empty", async () => { process.env.PR_NUMBER = " "; - await import("./add_copilot_reviewer.cjs"); + await runScript(); expect(mockCore.setFailed).toHaveBeenCalledWith("PR_NUMBER environment variable is required but not set"); expect(mockGithub.rest.pulls.requestReviewers).not.toHaveBeenCalled(); @@ -86,7 +92,7 @@ describe("add_copilot_reviewer", () => { it("should fail when PR_NUMBER is not a valid number", async () => { process.env.PR_NUMBER = "not-a-number"; - await import("./add_copilot_reviewer.cjs"); + await runScript(); expect(mockCore.setFailed).toHaveBeenCalledWith(expect.stringContaining("Invalid PR_NUMBER")); expect(mockGithub.rest.pulls.requestReviewers).not.toHaveBeenCalled(); @@ -95,7 +101,7 @@ describe("add_copilot_reviewer", () => { it("should fail when PR_NUMBER is zero", async () => { process.env.PR_NUMBER = "0"; - await import("./add_copilot_reviewer.cjs"); + await runScript(); expect(mockCore.setFailed).toHaveBeenCalledWith(expect.stringContaining("Invalid PR_NUMBER")); expect(mockGithub.rest.pulls.requestReviewers).not.toHaveBeenCalled(); @@ -104,7 +110,7 @@ describe("add_copilot_reviewer", () => { it("should fail when PR_NUMBER is negative", async () => { process.env.PR_NUMBER = "-1"; - await import("./add_copilot_reviewer.cjs"); + await runScript(); expect(mockCore.setFailed).toHaveBeenCalledWith(expect.stringContaining("Invalid PR_NUMBER")); expect(mockGithub.rest.pulls.requestReviewers).not.toHaveBeenCalled(); @@ -113,7 +119,7 @@ describe("add_copilot_reviewer", () => { it("should add copilot as reviewer when PR_NUMBER is valid", async () => { process.env.PR_NUMBER = "456"; - await import("./add_copilot_reviewer.cjs"); + await runScript(); expect(mockGithub.rest.pulls.requestReviewers).toHaveBeenCalledWith({ owner: "testowner", @@ -130,7 +136,7 @@ describe("add_copilot_reviewer", () => { process.env.PR_NUMBER = "123"; mockGithub.rest.pulls.requestReviewers.mockRejectedValueOnce(new Error("API Error")); - await import("./add_copilot_reviewer.cjs"); + await runScript(); expect(mockCore.error).toHaveBeenCalledWith(expect.stringContaining("Failed to add Copilot as reviewer")); expect(mockCore.setFailed).toHaveBeenCalledWith(expect.stringContaining("Failed to add Copilot as reviewer")); @@ -139,7 +145,7 @@ describe("add_copilot_reviewer", () => { it("should trim whitespace from PR_NUMBER", async () => { process.env.PR_NUMBER = " 789 "; - await import("./add_copilot_reviewer.cjs"); + await runScript(); expect(mockGithub.rest.pulls.requestReviewers).toHaveBeenCalledWith({ owner: "testowner", diff --git a/pkg/workflow/js/create_agent_task.test.cjs b/pkg/workflow/js/create_agent_task.test.cjs index 30585c3fbba..2956a0f80e5 100644 --- a/pkg/workflow/js/create_agent_task.test.cjs +++ b/pkg/workflow/js/create_agent_task.test.cjs @@ -28,7 +28,8 @@ describe("create_agent_task.cjs", () => { const scriptPath = require("path").join(process.cwd(), "create_agent_task.cjs"); delete require.cache[require.resolve(scriptPath)]; try { - (require(scriptPath), await new Promise(resolve => setTimeout(resolve, 50))); + const { main } = require(scriptPath); + await main(); } catch (error) {} }; (describe("basic functionality", () => {