Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/repository-quality-improver.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion actions/setup/js/assign_agent_helpers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,13 @@ async function assignAgentToIssue(issueId, agentId, currentAssignees, agentName)
core.error(`Fallback addAssigneesToAssignable failed: ${fallbackErrMsg}`);
}
logPermissionError(agentName);
// Re-throw the original error to preserve the error message for permission error detection in summary
throw error;
} else {
core.error(`Failed to assign ${agentName}: ${errorMessage}`);
}
return false;
// Re-throw the original error to preserve the error message
throw error;
}
}

Expand Down
24 changes: 20 additions & 4 deletions actions/setup/js/assign_to_agent.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,11 @@ describe("assign_to_agent", () => {
expect(mockCore.setFailed).toHaveBeenCalledWith(expect.stringContaining("Invalid max value: invalid"));
});

it.skip("should generate permission error summary when appropriate", async () => {
// TODO: This test needs to be fixed - the mock setup doesn't work correctly with eval()
// The error from getIssueDetails is not being propagated properly in the test environment
it("should generate permission error summary when appropriate", async () => {
// Explicitly reset mocks to ensure clean state
vi.clearAllMocks();
mockGithub.graphql.mockReset();

setAgentOutput({
items: [
{
Expand All @@ -481,10 +483,23 @@ describe("assign_to_agent", () => {
errors: [],
});

// Clear module cache for all dependencies AND re-read the script file
// This ensures we have the latest code when eval executes
const modulesToClear = ["./assign_agent_helpers.cjs", "./load_agent_output.cjs", "./staged_preview.cjs", "./error_helpers.cjs"];
for (const mod of modulesToClear) {
const modPath = require.resolve(mod);
delete require.cache[modPath];
}

// Re-read the script file to ensure we have the latest version
const scriptPath = path.join(process.cwd(), "assign_to_agent.cjs");
const freshScript = fs.readFileSync(scriptPath, "utf8");

// Simulate permission error during agent assignment mutation (not during getIssueDetails)
// First call: findAgent succeeds
// Second call: getIssueDetails succeeds
// Third call: assignAgentToIssue fails with permission error
// Fourth call: fallback mutation also fails with permission error
const permissionError = new Error("Resource not accessible by integration");
mockGithub.graphql
.mockResolvedValueOnce({
Expand All @@ -504,9 +519,10 @@ describe("assign_to_agent", () => {
},
},
})
.mockRejectedValueOnce(permissionError)
.mockRejectedValueOnce(permissionError);

await eval(`(async () => { ${assignToAgentScript}; await main(); })()`);
await eval(`(async () => { ${freshScript}; await main(); })()`);

expect(mockCore.summary.addRaw).toHaveBeenCalled();
const summaryCall = mockCore.summary.addRaw.mock.calls[0][0];
Expand Down
Loading