Repository navigation
fix(hub): repair mention search, prompt copying, and Inbox checks #322
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f8a8957
fix(hub): search review mentions by typed login
arniebradfo b95c5d1
fix(hub): let repository viewers copy kickoff prompts
arniebradfo 8644a9b
fix(hub): reduce GitHub checks for review and Inbox
arniebradfo 06adac0
fix(hub): preserve prompt copying after handoff denial
arniebradfo 0b1320f
fix(hub): reconcile unread counts after Inbox acknowledgments
arniebradfo 70ba51d
test(hub): keep handoff denial stories lint-clean
arniebradfo 9d4058d
fix(hub): refresh unread count after a failed Inbox update
arniebradfo a6a703d
fix(hub): address mention and Inbox review regressions
arniebradfo 0241fe3
fix(hub): reconcile the final unread count in All
arniebradfo fa2ac53
fix(hub): carry Inbox count refresh across rapid saves
arniebradfo 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
43 changes: 43 additions & 0 deletions
43
hub/client/application/hub/requests/authorize-copilot-handoff/index.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,43 @@ | ||
| import { describe, expect, it, vi } from "vitest" | ||
|
|
||
| import { authorizeCopilotHandoff } from "." | ||
|
|
||
| describe("authorizeCopilotHandoff()", () => { | ||
| it("allows explicit copy fallback only for callers that opt in", async () => { | ||
| const fetch = vi.fn(() => | ||
| Promise.resolve( | ||
| Response.json({ error: "GitHub unavailable", canCopy: true }, { status: 503 }), | ||
| ), | ||
| ) | ||
| vi.stubGlobal("fetch", fetch) | ||
|
|
||
| await expect(authorizeCopilotHandoff("2001", { allowCopyFallback: true })).resolves.toBe(false) | ||
| await expect(authorizeCopilotHandoff("2001")).rejects.toMatchObject({ status: 503 }) | ||
| }) | ||
|
|
||
| it.each([ | ||
| { status: 401, canCopy: true }, | ||
| { status: 404, canCopy: true }, | ||
| { status: 503, canCopy: undefined }, | ||
| { status: 503, canCopy: false }, | ||
| ])("rejects a $status with no applicable copy authorization", async ({ status, canCopy }) => { | ||
| vi.stubGlobal( | ||
| "fetch", | ||
| vi | ||
| .fn() | ||
| .mockResolvedValue(Response.json({ error: "Access unavailable", canCopy }, { status })), | ||
| ) | ||
|
|
||
| await expect( | ||
| authorizeCopilotHandoff("2001", { allowCopyFallback: true }), | ||
| ).rejects.toMatchObject({ status }) | ||
| }) | ||
|
|
||
| it("does not allow copy when the request cannot reach Hub", async () => { | ||
| vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new TypeError("Network unavailable"))) | ||
|
|
||
| await expect( | ||
| authorizeCopilotHandoff("2001", { allowCopyFallback: true }), | ||
| ).rejects.toMatchObject({ status: 0 }) | ||
| }) | ||
| }) |
30 changes: 24 additions & 6 deletions
30
hub/client/application/hub/requests/authorize-copilot-handoff/index.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 |
|---|---|---|
| @@ -1,11 +1,29 @@ | ||
| import { z } from "zod" | ||
|
|
||
| import { ApiRequestError } from "../api-request-error" | ||
| import { requestJson } from "../request-json" | ||
|
|
||
| export async function authorizeCopilotHandoff(repositoryId: string) { | ||
| const permission = await requestJson( | ||
| new URL(`/api/repositories/${repositoryId}/create/permission`, window.location.origin), | ||
| z.object({ canCreate: z.boolean() }), | ||
| ) | ||
| return permission.canCreate | ||
| const copyFallback = z.object({ canCopy: z.literal(true) }) | ||
|
|
||
| export async function authorizeCopilotHandoff( | ||
| repositoryId: string, | ||
| { allowCopyFallback = false } = {}, | ||
| ) { | ||
| try { | ||
| const permission = await requestJson( | ||
| new URL(`/api/repositories/${repositoryId}/create/permission`, window.location.origin), | ||
| z.object({ canCreate: z.boolean() }), | ||
| ) | ||
| return permission.canCreate | ||
| } catch (error) { | ||
| if ( | ||
| allowCopyFallback && | ||
| error instanceof ApiRequestError && | ||
| error.status === 503 && | ||
| copyFallback.safeParse(error.body).success | ||
| ) { | ||
| return false | ||
| } | ||
| throw error | ||
| } | ||
| } |
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
60 changes: 60 additions & 0 deletions
60
hub/client/application/hub/screens/prototype-screen/index.test.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,60 @@ | ||
| import { fireEvent, render, screen, within } from "@testing-library/react" | ||
| import { http, HttpResponse } from "msw" | ||
| import { setupServer } from "msw/node" | ||
| import { createMemoryRouter, RouterProvider } from "react-router" | ||
| import { expect, it, onTestFinished, vi } from "vitest" | ||
|
|
||
| import { createMockStore } from "@application/hub/mocks/create-mock-store" | ||
| import { createReviewHandlers } from "@application/hub/mocks/create-review-handlers" | ||
| import { HubThemeProvider } from "@hooks/use-hub-theme" | ||
|
|
||
| import { PrototypeScreen } from "." | ||
|
|
||
| it("sends the typed mention login to the review candidates API", async () => { | ||
| const store = createMockStore({ origin: window.location.origin }) | ||
| const workspace = store.getWorkspace() | ||
| const data = store.getPrototype("2001", "1", undefined, true) | ||
| const repository = workspace.repositories.find(({ id }) => id === data.repository.id)! | ||
| repository.capabilities = { reviewPrototypes: true, manageSharing: false } | ||
| const path = `/repositories/${data.repository.id}/prototypes/${data.prototype.id}` | ||
| const server = setupServer( | ||
| http.get(`${store.origin}/api${path}/review-comments/mention-candidates`, ({ request }) => | ||
| HttpResponse.json({ | ||
| candidates: | ||
| new URL(request.url).searchParams.get("q") === "mon" | ||
| ? [{ githubId: 501, login: "mona", avatarUrl: null }] | ||
| : [], | ||
| }), | ||
| ), | ||
| ...createReviewHandlers(store.review, store.origin, store.session), | ||
| ) | ||
| server.listen({ onUnhandledRequest: "error" }) | ||
| onTestFinished(() => server.close()) | ||
| const router = createMemoryRouter( | ||
| [ | ||
| { | ||
| path, | ||
| element: ( | ||
| <PrototypeScreen | ||
| workspace={workspace} | ||
| data={data} | ||
| onSaveDetails={vi.fn()} | ||
| savingDetails={false} | ||
| detailsError={null} | ||
| detailsSaved={false} | ||
| /> | ||
| ), | ||
| }, | ||
| ], | ||
| { initialEntries: [path] }, | ||
| ) | ||
| onTestFinished(() => router.dispose()) | ||
| render(<RouterProvider router={router} />, { wrapper: HubThemeProvider }) | ||
|
|
||
| fireEvent.click(await screen.findByRole("button", { name: /^Comments, 1/ })) | ||
| fireEvent.click(await screen.findByRole("button", { name: /welcome heading clearer/ })) | ||
| const conversation = await screen.findByRole("dialog", { name: "Conversation" }) | ||
| const reply = within(conversation).getByRole("textbox", { name: "Reply" }) | ||
| fireEvent.change(reply, { target: { value: "Please review @mon" } }) | ||
| expect(await screen.findByRole("option", { name: "@mona" })).toBeVisible() | ||
| }) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.