From 7691a5401282efcb1d7fb0e0c8879f32e79df975 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 19:37:22 +0000 Subject: [PATCH 1/2] test(web): dismissing the pull request checkout toast should stop the handoff Repro for #34491. Fails on main: the handoff still points a thread at the checkout and writes the task into its composer after the toast is closed. AI-assisted; verified with the tests and tools listed above. --- .../usePullRequestActions.browser.test.tsx | 79 ++++++++++++++++++- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/pullRequest/usePullRequestActions.browser.test.tsx b/apps/web/src/components/pullRequest/usePullRequestActions.browser.test.tsx index 48e1f7412702a..018a5012fbf30 100644 --- a/apps/web/src/components/pullRequest/usePullRequestActions.browser.test.tsx +++ b/apps/web/src/components/pullRequest/usePullRequestActions.browser.test.tsx @@ -1,15 +1,27 @@ -import { EnvironmentId, ProjectId, type PullRequestRef } from "@t3tools/contracts"; +import { EnvironmentId, ProjectId, ThreadId, type PullRequestRef } from "@t3tools/contracts"; import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; import { expect, it, vi } from "vite-plus/test"; import { userEvent } from "vite-plus/test/browser"; import { act, render } from "../../../test/render"; -import { usePullRequestActionRunner } from "./usePullRequestActions"; +import { useComposerDraftStore } from "~/composerDraftStore"; +import { ToastProvider } from "../ui/toast"; +import { usePullRequestActionRunner, usePullRequestHandoffs } from "./usePullRequestActions"; -const state = vi.hoisted(() => ({ runAction: vi.fn() })); +const state = vi.hoisted(() => ({ + runAction: vi.fn(), + newThread: vi.fn(), + prepareThread: vi.fn(), +})); vi.mock(import("~/state/use-atom-command"), () => ({ useAtomCommand: (() => state.runAction) as never, })); +vi.mock(import("~/hooks/useHandleNewThread"), () => ({ + useNewThreadHandler: (() => state.newThread) as never, +})); +vi.mock(import("~/state/sourceControlActions"), () => ({ + usePreparePullRequestThreadAction: (() => ({ run: state.prepareThread })) as never, +})); function deferred() { let resolve!: (value: T) => void; @@ -72,3 +84,64 @@ it("keeps pending merges with their pull request when navigating between threads }); await expect.element(button).toHaveTextContent("Merge"); }); + +function FixChecksButton() { + const { startHandoff } = usePullRequestHandoffs({ + environmentId: EnvironmentId.make("environment"), + detail: { + projectId: ProjectId.make("project"), + workspaceRoot: "/repo", + url: "https://github.com/owner/repo/pull/1", + }, + }); + return ( + + ); +} + +it("stops a pull request handoff when its loading toast is dismissed", async () => { + const prepared = deferred<{ + _tag: "Success"; + value: { + branch: string; + worktreePath: string; + isOnPullRequestHead: boolean; + pullRequest: { url: string }; + }; + }>(); + state.newThread + .mockReset() + .mockResolvedValueOnce({ draftId: "draft-1", threadId: ThreadId.make("thread-1") }) + .mockResolvedValueOnce({ draftId: "draft-2", threadId: ThreadId.make("thread-1") }); + state.prepareThread.mockReset().mockReturnValueOnce(prepared.promise); + await using screen = await render( + + + , + ); + + await userEvent.click(screen.getByRole("button", { name: "Fix" })); + const toast = screen.getByRole("dialog", { name: "Preparing the pull request checkout..." }); + await expect.element(toast).toBeVisible(); + await userEvent.click(toast.getByRole("button", { name: "Dismiss notification" })); + await expect.element(toast).not.toBeInTheDocument(); + await act(async () => { + prepared.resolve({ + _tag: "Success", + value: { + branch: "pr-1", + worktreePath: "/repo-worktrees/pr-1", + isOnPullRequestHead: true, + pullRequest: { url: "https://github.com/owner/repo/pull/1" }, + }, + }); + await prepared.promise; + }); + + expect(state.newThread).toHaveBeenCalledTimes(1); + expect(useComposerDraftStore.getState().getComposerDraft("draft-2" as never)?.prompt ?? "").toBe( + "", + ); +}); From c889e5c210654ec8c4eec573e982af8d0d4980ee Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 19:45:45 +0000 Subject: [PATCH 2/2] fix(web): dismissing the pull request checkout toast stops the handoff AI-assisted; verified with the tests and tools listed above. --- .../pullRequest/usePullRequestActions.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/web/src/components/pullRequest/usePullRequestActions.ts b/apps/web/src/components/pullRequest/usePullRequestActions.ts index 2cc81c4885364..63681b4cf2167 100644 --- a/apps/web/src/components/pullRequest/usePullRequestActions.ts +++ b/apps/web/src/components/pullRequest/usePullRequestActions.ts @@ -332,10 +332,17 @@ export function usePullRequestHandoffs({ ) => { if (!detail || handoff !== null) return; setHandoff(kind); + // Dismissing the loading toast cancels the handoff before it touches a draft. + let cancelled = false; // Explicit timeouts survive toast updates and would pin the result after loading. const toastId = toastManager.add({ type: "loading", title: `Preparing the ${terminology.singular} checkout...`, + data: { + onClose: () => { + cancelled = true; + }, + }, }); const projectRef = scopeProjectRef(environmentId, detail.projectId); // Checkout setup requires the thread to exist first. @@ -343,6 +350,10 @@ export function usePullRequestHandoffs({ (session) => session, () => null, ); + if (cancelled) { + setHandoff(null); + return; + } if (opened === null) { setHandoff(null); toastManager.update(toastId, { @@ -357,6 +368,10 @@ export function usePullRequestHandoffs({ mode, threadId: opened.threadId, }); + if (cancelled) { + setHandoff(null); + return; + } if (prepared._tag === "Failure") { setHandoff(null); toastManager.update(toastId, { @@ -376,6 +391,10 @@ export function usePullRequestHandoffs({ (session) => session, () => null, ); + if (cancelled) { + setHandoff(null); + return; + } if (pointed === null) { setHandoff(null); toastManager.update(toastId, {