-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Report failed GitHub PR and issue actions #521
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
Merged
+324
−4
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
scripts/screenshot/specs/github-action-error-toast.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /** | ||
| * Verifies that a failed gh action in the GitHub panel's PR detail pane | ||
| * (here, Close PR) reports the gh error as a toast instead of silently | ||
| * resetting the button. | ||
| */ | ||
|
|
||
| import userEvent from "@testing-library/user-event"; | ||
| import { expect, it, vi } from "vitest"; | ||
| import { GitHubPanel } from "../../../src/components/GitHubPanel"; | ||
| import type { GhPullRequest } from "../../../src/lib/api-types"; | ||
| import { render, screen } from "../../../test/test-utils"; | ||
| import { createTestRepo } from "../../../test/utils"; | ||
| import { captureDocument } from "../capture"; | ||
|
|
||
| const api = vi.hoisted(() => ({ | ||
| getGitRemoteUrl: vi.fn(), | ||
| ghListPrs: vi.fn(), | ||
| ghViewPr: vi.fn(), | ||
| ghClosePr: vi.fn(), | ||
| getPrChecksForPr: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("../../../src/lib/api", async () => { | ||
| const actual = await vi.importActual<typeof import("../../../src/lib/api")>( | ||
| "../../../src/lib/api", | ||
| ); | ||
| return { | ||
| ...actual, | ||
| getGitRemoteUrl: api.getGitRemoteUrl, | ||
| ghListIssues: vi.fn().mockResolvedValue({ items: [], hasMore: false }), | ||
| ghListPrs: api.ghListPrs, | ||
| ghViewPr: api.ghViewPr, | ||
| ghClosePr: api.ghClosePr, | ||
| getPrChecksForPr: api.getPrChecksForPr, | ||
| }; | ||
| }); | ||
|
|
||
| const PR: GhPullRequest = { | ||
| number: 42, | ||
| title: "Close me", | ||
| state: "OPEN", | ||
| url: "https://github.com/acme/treq/pull/42", | ||
| body: null, | ||
| author: { login: "octocat", avatar_url: null }, | ||
| labels: [], | ||
| head_ref_name: "feat/pr-42", | ||
| base_ref_name: "main", | ||
| merge_state_status: "CLEAN", | ||
| created_at: "2026-07-20T10:00:00Z", | ||
| updated_at: "2026-07-20T10:00:00Z", | ||
| comments: [], | ||
| is_draft: false, | ||
| }; | ||
|
|
||
| it("shows an error toast when Close PR fails", async () => { | ||
| const { repoPath } = createTestRepo(false); | ||
| api.getGitRemoteUrl.mockResolvedValue({ | ||
| owner: "acme", | ||
| repo: "treq", | ||
| full_name: "acme/treq", | ||
| }); | ||
| api.getPrChecksForPr.mockResolvedValue(null); | ||
| api.ghListPrs.mockResolvedValue({ items: [PR], hasMore: false }); | ||
| api.ghViewPr.mockResolvedValue(PR); | ||
| api.ghClosePr.mockRejectedValue( | ||
| "gh: GraphQL: Resource not accessible by integration (closePullRequest)", | ||
| ); | ||
|
|
||
| const user = userEvent.setup(); | ||
| render(<GitHubPanel repoPath={repoPath} onOpenSettings={vi.fn()} />); | ||
| await user.click(await screen.findByRole("tab", { name: /pull requests/i })); | ||
| await user.click(await screen.findByRole("button", { name: /close me/i })); | ||
| await user.click(await screen.findByRole("button", { name: /close pr/i })); | ||
|
|
||
| expect(await screen.findByText("Failed to close pull request")).toBeVisible(); | ||
| expect(screen.getByRole("button", { name: /close pr/i })).toBeEnabled(); | ||
|
|
||
| await captureDocument(document, { | ||
| name: "github-action-error-toast-01-close-failed", | ||
| expectations: [ | ||
| 'An error toast with a red alert icon reads "Failed to close pull request" with the gh "Resource not accessible by integration" message beneath it.', | ||
| "The PR detail still shows the PR as Open with an enabled Close PR button.", | ||
| ], | ||
| }); | ||
| }, 60000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/components/changes-diff-viewer/hooks/useReview.viewed.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { act, renderHook } from "@testing-library/react"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import type { ParsedFileChange } from "../../../lib/git-utils"; | ||
| import type { FileHunksData } from "../types"; | ||
| import { useReview } from "./useReview"; | ||
|
|
||
| vi.mock("../../../lib/api", async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import("../../../lib/api")>(); | ||
| return { | ||
| ...actual, | ||
| loadPendingReview: vi.fn().mockResolvedValue(null), | ||
| savePendingReview: vi.fn().mockResolvedValue(undefined), | ||
| clearPendingReview: vi.fn().mockResolvedValue(undefined), | ||
| markFileViewed: vi.fn().mockResolvedValue(undefined), | ||
| unmarkFileViewed: vi.fn().mockResolvedValue(undefined), | ||
| }; | ||
| }); | ||
|
|
||
| const FILE = "reviews-flow.txt"; | ||
|
|
||
| const LOADED: FileHunksData = { | ||
| filePath: FILE, | ||
| isLoading: false, | ||
| hunks: [ | ||
| { | ||
| id: "h1", | ||
| header: "@@ -0,0 +1,2 @@", | ||
| lines: ["+first review line\n", "+second review line\n"], | ||
| patch: "", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| function renderUseReview(allFileHunks: Map<string, FileHunksData>) { | ||
| const files = [{ path: FILE }] as unknown as ParsedFileChange[]; | ||
| return renderHook( | ||
| ({ hunks }: { hunks: Map<string, FileHunksData> }) => | ||
| useReview({ | ||
| comments: [], | ||
| setComments: vi.fn(), | ||
| conflictComments: new Map(), | ||
| setConflictComments: vi.fn(), | ||
| setHasUserAddedComments: vi.fn(), | ||
| allFileHunks: hunks, | ||
| setAllFileHunks: vi.fn(), | ||
| files, | ||
| workspacePath: "/tmp/ws", | ||
| repoPath: undefined, | ||
| workspaceId: undefined, | ||
| conflictRegionsByFile: new Map(), | ||
| actualConflictedFiles: [], | ||
| setCollapsedFiles: vi.fn(), | ||
| applyChangedFilesRef: { current: vi.fn() }, | ||
| isReloadingRef: { current: false }, | ||
| onCreateAgentWithReview: undefined, | ||
| onReviewSubmitted: undefined, | ||
| addToast: vi.fn(), | ||
| }), | ||
| { initialProps: { hunks: allFileHunks } }, | ||
| ); | ||
| } | ||
|
|
||
| describe("useReview viewed files", () => { | ||
| it("keeps a file viewed when it was marked before its diff finished loading", async () => { | ||
| const loading = new Map<string, FileHunksData>([ | ||
| [FILE, { filePath: FILE, hunks: [], isLoading: true }], | ||
| ]); | ||
| const { result, rerender } = renderUseReview(loading); | ||
|
|
||
| await act(async () => { | ||
| await result.current.handleMarkFileViewed(FILE); | ||
| }); | ||
| expect(result.current.viewedFiles.has(FILE)).toBe(true); | ||
|
|
||
| rerender({ hunks: new Map([[FILE, LOADED]]) }); | ||
|
|
||
| expect(result.current.viewedFiles.has(FILE)).toBe(true); | ||
| }); | ||
|
|
||
| it("still un-marks a viewed file whose loaded diff changes", async () => { | ||
| const { result, rerender } = renderUseReview(new Map([[FILE, LOADED]])); | ||
|
|
||
| await act(async () => { | ||
| await result.current.handleMarkFileViewed(FILE); | ||
| }); | ||
| expect(result.current.viewedFiles.has(FILE)).toBe(true); | ||
|
|
||
| rerender({ | ||
| hunks: new Map([ | ||
| [ | ||
| FILE, | ||
| { | ||
| ...LOADED, | ||
| hunks: [{ ...LOADED.hunks[0], lines: ["+changed line\n"] }], | ||
| }, | ||
| ], | ||
| ]), | ||
| }); | ||
|
|
||
| expect(result.current.viewedFiles.has(FILE)).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Collaborator
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.
Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useGhErrorToastlives here because both detail panes need it.openOrCreateWorkspaceerror path inPrDetail.String(error)covers Tauriinvokerejections, which arrive as plain strings rather thanErrorobjects.Generated by Claude Code