@devries-cameron20 / t3code Mirror · read-only / commits / d6cdb4f161
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

fix(web): scope checkout errors to the selected pull request (#39554)

Wout Stiens committed Nov 20, 2026 at 08:21 UTC d6cdb4f1619f19a30f26f1334750f25a955bb01a
3 files changed +149 -20
apps/web/src/components/PullRequestThreadDialog.browser.test.tsx new
+45
@@ -0,0 +1,45 @@
1 +import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2 +import * as Cause from "effect/Cause";
3 +import { AsyncResult } from "effect/reactivity";
4 +import { expect, it } from "vite-plus/test";
5 +import { page } from "vite-plus/test/browser";
6 +
7 +import { AppAtomRegistryProvider, appAtomRegistry } from "~/rpc/atomRegistry";
8 +import { vcsActionManager } from "~/state/vcs";
9 +import { act, render } from "../../test/render";
10 +import { PullRequestThreadDialog } from "./PullRequestThreadDialog";
11 +
12 +it("keeps another caller's checkout failure out of the dialog", async () => {
13 + const target = { environmentId: EnvironmentId.make("checkout-error-test"), cwd: "/repo" };
14 + const failure = AsyncResult.failure(Cause.fail(new Error("Pull request #42 has local changes.")));
15 + const reply = Promise.withResolvers<typeof failure>();
16 +
17 + await using _screen = await render(
18 + <AppAtomRegistryProvider>
19 + <PullRequestThreadDialog
20 + {...target}
21 + open
22 + initialReference={null}
23 + threadId={ThreadId.make("checkout-error-test")}
24 + onOpenChange={() => {}}
25 + onPrepared={() => {}}
26 + />
27 + </AppAtomRegistryProvider>,
28 + );
29 +
30 + const dialog = page.getByRole("dialog");
31 + const cancel = dialog.getByRole("button", { name: "Cancel" });
32 + const checkout = vcsActionManager.track(
33 + appAtomRegistry,
34 + target,
35 + { operation: "prepare_pull_request_thread", label: "Preparing pull request thread" },
36 + () => reply.promise,
37 + );
38 + await expect.element(cancel).toBeDisabled();
39 + await act(async () => {
40 + reply.resolve(failure);
41 + await checkout;
42 + });
43 + await expect.element(cancel).toBeEnabled();
44 + expect(dialog.getByText(/Failed to prepare .* request thread\./).query()).toBeNull();
45 +});
apps/web/src/components/PullRequestThreadDialog.tsx
+14 -20
@@ -11,7 +11,7 @@ import { thrownErrorMessage } from "@t3tools/client-runtime/errors";
11 import { m } from "../i18n/messages";
12 import { useDebouncedValue } from "@tanstack/react-pacer";
13 import { useRef, useState } from "react";
14 -import { T, useGT, useMessages, Var } from "gt-react";
14 +import { T, useGT, Var } from "gt-react";
15 import { changeRequestTermKind } from "./pullRequest/changeRequestTerm";
16
17 import {
@@ -77,12 +77,13 @@ export function PullRequestThreadDialog({
77 onPrepared,
78 }: PullRequestThreadDialogProps) {
79 const gt = useGT();
80 - const messages = useMessages();
80 const referenceInputRef = useRef<HTMLInputElement>(null);
81 const [reference, setReference] = useState(initialReference ?? "");
82 const [referenceDirty, setReferenceDirty] = useState(false);
83 const [preparingMode, setPreparingMode] = useState<"local" | "worktree" | null>(null);
85 - const [prepareErrorMessage, setPrepareErrorMessage] = useState<string | null>(null);
84 + const [checkoutError, setCheckoutError] = useState<{ target: string; message: string } | null>(
85 + null,
86 + );
87 const [debouncedReference, referenceDebouncer] = useDebouncedValue(
88 reference,
89 { wait: 450 },
@@ -122,6 +123,7 @@ export function PullRequestThreadDialog({
123 ? (pullRequestResolution.data?.pullRequest ?? null)
124 : null;
125 const resolvedPullRequest = liveResolvedPullRequest ?? cachedPullRequest;
126 + const checkoutTarget = JSON.stringify([environmentId, cwd, threadId, parsedReference]);
127 const isResolving =
128 open &&
129 parsedReference !== null &&
@@ -147,7 +149,7 @@ export function PullRequestThreadDialog({
149 if (!parsedReference || !resolvedPullRequest || !cwd) {
150 return;
151 }
150 - setPrepareErrorMessage(null);
152 + setCheckoutError(null);
153 setPreparingMode(mode);
154 const result = await preparePullRequestThreadAction.run({
155 reference: parsedReference,
@@ -156,17 +158,17 @@ export function PullRequestThreadDialog({
158 });
159 setPreparingMode(null);
160 if (result._tag === "Failure") {
159 - if (isAtomCommandInterrupted(result)) {
160 - preparePullRequestThreadAction.resetError();
161 - } else {
161 + if (!isAtomCommandInterrupted(result)) {
162 const error = squashAtomCommandFailure(result);
163 - setPrepareErrorMessage(
164 - thrownErrorMessage(error, m) ??
163 + setCheckoutError({
164 + target: checkoutTarget,
165 + message:
166 + thrownErrorMessage(error, m) ??
167 gt(
168 "Failed to prepare {term, select, mr {merge request} cr {change request} other {pull request}} thread.",
169 { term },
170 ),
169 - );
171 + });
172 }
173 return;
174 }
@@ -196,16 +198,8 @@ export function PullRequestThreadDialog({
198 : null;
199 const errorMessage =
200 validationMessage ??
199 - prepareErrorMessage ??
200 - (resolvedPullRequest === null && pullRequestResolution.error
201 - ? pullRequestResolution.error
202 - : preparePullRequestThreadAction.error
203 - ? (thrownErrorMessage(preparePullRequestThreadAction.error, messages) ??
204 - gt(
205 - "Failed to prepare {term, select, mr {merge request} cr {change request} other {pull request}} thread.",
206 - { term },
207 - ))
208 - : null);
201 + (checkoutError?.target === checkoutTarget ? checkoutError.message : null) ??
202 + (resolvedPullRequest === null ? pullRequestResolution.error : null);
203
204 return (
205 <Dialog
scripts/scenarios/pull-request-checkout-error-follows-reference.e2e.ts new
+90
@@ -0,0 +1,90 @@
1 +/// <reference lib="dom" />
2 +import type { GitResolvePullRequestResult } from "@t3tools/contracts";
3 +import { expect } from "e2e";
4 +
5 +import { test, WEB } from "./t3.ts";
6 +
7 +test(
8 + "A failed local checkout does not show its error on another pull request",
9 + WEB,
10 + async ({ t3, app, browser, screen }) => {
11 + await t3.project("demo");
12 + await browser.setViewport({ width: 1280, height: 800 });
13 + await browser.addInitScript(() => {
14 + const send = WebSocket.prototype.send;
15 + WebSocket.prototype.send = function (data) {
16 + const request: {
17 + _tag: string;
18 + id: string;
19 + tag: string;
20 + payload: { cwd: string; reference: string };
21 + } | null = typeof data === "string" ? JSON.parse(data) : null;
22 + if (request?._tag !== "Request") return send.call(this, data);
23 + const reply = (exit: unknown) =>
24 + queueMicrotask(() =>
25 + this.dispatchEvent(
26 + new MessageEvent("message", {
27 + data: JSON.stringify({ _tag: "Exit", requestId: request.id, exit }),
28 + }),
29 + ),
30 + );
31 + if (request.tag === "git.resolvePullRequest") {
32 + const number = Number(request.payload.reference.replace(/^#/, ""));
33 + const value: GitResolvePullRequestResult = {
34 + pullRequest: {
35 + number,
36 + title: number === 42 ? "Update the release notes" : "Fix the status badge",
37 + url: `https://github.com/example/demo/pull/${number}`,
38 + baseBranch: "main",
39 + headBranch: `change-${number}`,
40 + state: "open",
41 + },
42 + };
43 + reply({ _tag: "Success", value });
44 + return;
45 + }
46 + if (request.tag === "git.preparePullRequestThread") {
47 + reply({
48 + _tag: "Failure",
49 + cause: [
50 + {
51 + _tag: "Fail",
52 + error: {
53 + _tag: "GitManagerError",
54 + operation: "preparePullRequestThread",
55 + cwd: request.payload.cwd,
56 + detail:
57 + "This repository has uncommitted changes. Commit or stash them before checking out pull request #42 here, or check it out in its own folder.",
58 + },
59 + },
60 + ],
61 + });
62 + return;
63 + }
64 + return send.call(this, data);
65 + };
66 + });
67 +
68 + await t3.open("/");
69 + await browser
70 + .locator('[data-slot="combobox-trigger"][aria-label^="Branch:"]:visible')
71 + .first()
72 + .click();
73 + await screen.getByPlaceholder("Search refs...").fill("#42");
74 + const checkoutLabel = /Checkout (?:pull|change) request/i;
75 + await screen.getByRole("option", checkoutLabel).tap();
76 +
77 + const dialog = screen.getByRole("dialog", checkoutLabel);
78 + await dialog.getByText("Update the release notes", { exact: true }).waitFor();
79 + await dialog.getByRole("button", "Local", { exact: true }).tap();
80 + const previousError = dialog.getByText(/before checking out pull request #42 here/);
81 + await previousError.waitFor();
82 + await dialog.getByRole("textbox").fill("#43");
83 + await dialog.getByText("Fix the status badge", { exact: true }).waitFor();
84 + await app.screenshot("second-pull-request");
85 + expect(
86 + await previousError.isVisible(),
87 + "The second pull request does not display the first checkout error",
88 + ).toBe(false);
89 + },
90 +);