Repository navigation
Retry transient slash-command provenance checks #59313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; | ||
| import { createRequire } from "module"; | ||
|
|
||
| const realRequire = createRequire(import.meta.url); | ||
|
|
||
| describe("check_membership.cjs", () => { | ||
| let mockCore; | ||
|
|
@@ -96,6 +99,9 @@ describe("check_membership.cjs", () => { | |
| }, | ||
| }; | ||
| } | ||
| if (modulePath === "./error_recovery.cjs") { | ||
| return realRequire(modulePath); | ||
| } | ||
| throw new Error(`Module not found: ${modulePath}`); | ||
| }; | ||
|
|
||
|
|
@@ -241,6 +247,99 @@ describe("check_membership.cjs", () => { | |
| expect(mockGithub.rest.repos.getCollaboratorPermissionLevel).not.toHaveBeenCalled(); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("result", "fork_pull_request"); | ||
| }); | ||
|
|
||
| it("should retry a transient pull request provenance failure", async () => { | ||
| vi.useFakeTimers(); | ||
| try { | ||
| mockContext.eventName = "workflow_dispatch"; | ||
| mockContext.actor = "github-actions[bot]"; | ||
| mockContext.payload = { | ||
| inputs: { | ||
| aw_context: JSON.stringify({ | ||
| command_name: "triage", | ||
| actor: "octocat", | ||
| item_type: "pull_request", | ||
| item_number: "42", | ||
| }), | ||
| }, | ||
| }; | ||
| process.env.GH_AW_REQUIRED_ROLES = "write"; | ||
| const apiError = Object.assign(new Error("Internal Server Error"), { status: 500 }); | ||
| mockGithub.rest.pulls.get.mockRejectedValueOnce(apiError).mockResolvedValue({ | ||
| data: { | ||
| head: { repo: { full_name: "testorg/testrepo" } }, | ||
| base: { repo: { full_name: "testorg/testrepo" } }, | ||
| }, | ||
| }); | ||
| mockGithub.rest.repos.getCollaboratorPermissionLevel.mockResolvedValue({ | ||
| data: { permission: "write" }, | ||
| }); | ||
|
|
||
| const runPromise = runScript(); | ||
| await vi.runAllTimersAsync(); | ||
| await runPromise; | ||
|
|
||
| expect(mockGithub.rest.pulls.get).toHaveBeenCalledTimes(2); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("result", "authorized"); | ||
| } finally { | ||
| vi.useRealTimers(); | ||
| } | ||
| }); | ||
|
|
||
| it("should not retry a permanent pull request provenance failure", async () => { | ||
| mockContext.eventName = "workflow_dispatch"; | ||
| mockContext.actor = "github-actions[bot]"; | ||
| mockContext.payload = { | ||
| inputs: { | ||
| aw_context: JSON.stringify({ | ||
| command_name: "triage", | ||
| actor: "octocat", | ||
| item_type: "pull_request", | ||
| item_number: "42", | ||
| }), | ||
| }, | ||
| }; | ||
| process.env.GH_AW_REQUIRED_ROLES = "write"; | ||
| const apiError = Object.assign(new Error("Not Found"), { status: 404 }); | ||
| mockGithub.rest.pulls.get.mockRejectedValue(apiError); | ||
|
|
||
| await runScript(); | ||
|
|
||
| expect(mockGithub.rest.pulls.get).toHaveBeenCalledTimes(1); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("is_team_member", "false"); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("result", "api_error"); | ||
| }); | ||
|
|
||
| it("should fail closed after exhausting transient provenance retries", async () => { | ||
| vi.useFakeTimers(); | ||
| try { | ||
| mockContext.eventName = "workflow_dispatch"; | ||
| mockContext.actor = "github-actions[bot]"; | ||
| mockContext.payload = { | ||
| inputs: { | ||
| aw_context: JSON.stringify({ | ||
| command_name: "triage", | ||
| actor: "octocat", | ||
| item_type: "pull_request", | ||
| item_number: "42", | ||
| }), | ||
| }, | ||
| }; | ||
| process.env.GH_AW_REQUIRED_ROLES = "write"; | ||
| const apiError = Object.assign(new Error("Internal Server Error"), { status: 500 }); | ||
| mockGithub.rest.pulls.get.mockRejectedValue(apiError); | ||
|
|
||
| const runPromise = runScript(); | ||
| await vi.runAllTimersAsync(); | ||
| await runPromise; | ||
|
|
||
| expect(mockGithub.rest.pulls.get).toHaveBeenCalledTimes(4); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("is_team_member", "false"); | ||
| expect(mockCore.setOutput).toHaveBeenCalledWith("result", "api_error"); | ||
| } finally { | ||
| vi.useRealTimers(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnosing-bugs] Both new tests cover the transient-500 path, but the PR description also claims "Do not retry permanent API failures" — that invariant isn't exercised by a test. 💡 Suggested regression testAdd a case where it("should not retry a permanent (404) provenance failure", async () => {
const apiError = Object.assign(new Error("Not Found"), { status: 404 });
mockGithub.rest.pulls.get.mockRejectedValue(apiError);
await runScript();
expect(mockGithub.rest.pulls.get).toHaveBeenCalledTimes(1);
expect(mockCore.setOutput).toHaveBeenCalledWith("result", "api_error");
});@copilot please address this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the requested 404 provenance regression test in |
||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe("configuration validation", () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.