@devries-cameron20 / t3code Mirror · read-only / commits / 83cf6dbebe
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 23, 01:45 UTC

fix(web): show pull request checkout error detail (#15007)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Oct 20, 2026 at 05:07 UTC 83cf6dbebe88f0f5dd1cf7eac9b2d5c338234932
6 files changed +209 -17
apps/web/src/components/chat/ThreadDetailsPrRow.browser.test.tsx
+95 -2
@@ -1,4 +1,13 @@
1 -import { EnvironmentId, type PullRequestCheck } from "@t3tools/contracts";
1 +import {
2 + EnvironmentId,
3 + GitCommandError,
4 + GitManagerError,
5 + ProjectId,
6 + ThreadId,
7 + type PullRequestCheck,
8 +} from "@t3tools/contracts";
9 +import * as Cause from "effect/Cause";
10 +import { DraftId } from "~/composerDraftStore";
11 import { AsyncResult } from "effect/reactivity";
12 import { act } from "react";
13 import { createRoot, type Root } from "react-dom/client";
@@ -8,6 +17,11 @@ const state = vi.hoisted(() => ({
17 status: "success" as PullRequestCheck["status"],
18 extraStatus: null as PullRequestCheck["status"] | null,
19 perform: vi.fn(),
20 + newThread: vi.fn(),
21 + prepareThread: vi.fn(),
22 + checkoutError: null as Error | null,
23 + addToast: vi.fn(),
24 + updateToast: vi.fn(),
25 }));
26
27 vi.mock(import("~/state/entities"), async (importOriginal) => ({
@@ -15,6 +29,9 @@ vi.mock(import("~/state/entities"), async (importOriginal) => ({
29 useServerConfigs: (() => new Map()) as never,
30 }));
31 const queryData = () => ({
32 + projectId: ProjectId.make("project"),
33 + workspaceRoot: "/workspace",
34 + url: "https://github.com/owner/repo/pull/1",
35 number: 1,
36 title: "Test PR",
37 state: "open",
@@ -45,9 +62,32 @@ vi.mock(import("~/state/query"), async (importOriginal) => ({
62 vi.mock(import("../pullRequest/usePullRequestActions"), async (importOriginal) => ({
63 ...(await importOriginal()),
64 usePullRequestActionRunner: () => ({ actionPending: false, perform: state.perform }),
48 - usePullRequestHandoffs: () => ({ handoff: null, startAsk: vi.fn(), startHandoff: vi.fn() }),
65 }));
66
67 +vi.mock(import("~/hooks/useHandleNewThread"), async (original) => ({
68 + ...(await original()),
69 + useNewThreadHandler: (() => state.newThread) as never,
70 +}));
71 +vi.mock(import("~/lib/sourceControlActions"), async (original) => ({
72 + ...(await original()),
73 + usePreparePullRequestThreadAction: (() => ({
74 + run: state.prepareThread,
75 + isAllowed: true,
76 + error: state.checkoutError,
77 + })) as never,
78 +}));
79 +vi.mock(import("../ui/toast"), async (original) => {
80 + const actual = await original();
81 + return {
82 + ...actual,
83 + toastManager: {
84 + ...actual.toastManager,
85 + add: state.addToast,
86 + update: state.updateToast,
87 + } as never,
88 + };
89 +});
90 +
91 import { ThreadDetailsPrRow } from "./ThreadDetailsPrRow";
92
93 let root: Root;
@@ -57,6 +97,14 @@ beforeEach(() => {
97 container = document.createElement("div");
98 document.body.append(container);
99 root = createRoot(container);
100 + state.checkoutError = null;
101 + state.newThread.mockReset().mockResolvedValue({
102 + draftId: DraftId.make("new-draft"),
103 + threadId: ThreadId.make("new-thread"),
104 + });
105 + state.prepareThread.mockReset();
106 + state.addToast.mockReset().mockReturnValue("checkout-toast");
107 + state.updateToast.mockReset();
108 });
109 afterEach(() => {
110 act(() => root.unmount());
@@ -133,3 +181,48 @@ it.each<[PullRequestCheck["status"], PullRequestCheck["status"], string]>([
181 .filter((value) => /^\d+\/\d+$/.test(value));
182 expect(new Set(counts)).toEqual(new Set(count ? [count] : []));
183 });
184 +
185 +it("shows the current checkout recovery detail when fixing checks fails and is retried", async () => {
186 + state.status = "failure";
187 + const first = new GitManagerError({
188 + cwd: "/workspace",
189 + operation: "preparePullRequestThread",
190 + detail: "This PR branch is already checked out in the main repo. Use Local.",
191 + });
192 + const second = new GitCommandError({
193 + cwd: "/workspace",
194 + operation: "GitVcsDriver.createWorktree",
195 + command: "git worktree add",
196 + detail: "The worktree directory already exists. Choose another directory.",
197 + });
198 + await act(async () => {
199 + root.render(
200 + <ThreadDetailsPrRow
201 + environmentId={EnvironmentId.make("environment")}
202 + pr={null}
203 + number={1}
204 + status={null}
205 + project={null}
206 + label="Test PR"
207 + openAriaLabel="Open PR"
208 + onOpen={vi.fn()}
209 + />,
210 + );
211 + });
212 +
213 + for (const error of [first, second]) {
214 + state.prepareThread.mockImplementationOnce(async () => {
215 + state.checkoutError = error;
216 + return { _tag: "Failure", cause: Cause.fail(error) };
217 + });
218 + await act(async () => {
219 + [...container.querySelectorAll("button")]
220 + .find((button) => button.textContent?.trim() === "Fix")!
221 + .click();
222 + });
223 + }
224 + expect(state.updateToast.mock.calls.map(([, toast]) => toast.description)).toEqual([
225 + expect.stringContaining(first.detail),
226 + second.detail,
227 + ]);
228 +});
apps/web/src/components/pullRequest/PullRequestDetailPanel.browser.test.tsx
+54 -6
@@ -1,5 +1,7 @@
1 import {
2 EnvironmentId,
3 + GitCommandError,
4 + GitManagerError,
5 ProjectId,
6 SourceControlProviderKind,
7 ThreadId,
@@ -7,6 +9,7 @@ import {
9 type ScopedThreadRef,
10 type ThreadPullRequestLink,
11 } from "@t3tools/contracts";
12 +import * as Cause from "effect/Cause";
13 import { act, type ComponentProps } from "react";
14 import { createRoot, type Root } from "react-dom/client";
15 import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
@@ -15,11 +18,16 @@ import { DraftId, useComposerDraftStore } from "~/composerDraftStore";
18
19 import "~/index.css";
20
18 -const { newThread, prepareThread, refresh } = vi.hoisted(() => ({
19 - newThread: vi.fn(),
20 - prepareThread: vi.fn(),
21 - refresh: vi.fn(),
22 -}));
21 +const { newThread, prepareThread, refresh, addToast, updateToast, checkoutState } = vi.hoisted(
22 + () => ({
23 + newThread: vi.fn(),
24 + prepareThread: vi.fn(),
25 + refresh: vi.fn(),
26 + addToast: vi.fn(),
27 + updateToast: vi.fn(),
28 + checkoutState: { error: null as Error | null },
29 + }),
30 +);
31
32 vi.mock(import("~/state/session"), async (original) => ({
33 ...(await original()),
@@ -39,7 +47,7 @@ vi.mock(import("~/lib/sourceControlActions"), async (original) => ({
47 usePreparePullRequestThreadAction: (() => ({
48 run: prepareThread,
49 isAllowed: true,
42 - error: null,
50 + error: checkoutState.error,
51 })) as never,
52 }));
53 vi.mock(import("~/state/use-atom-command"), async (original) => ({
@@ -146,6 +154,14 @@ vi.mock(import("./PullRequestCodeTab"), async (original) => ({
154 )) as never,
155 }));
156
157 +vi.mock(import("../ui/toast"), async (original) => {
158 + const actual = await original();
159 + return {
160 + ...actual,
161 + toastManager: { ...actual.toastManager, add: addToast, update: updateToast } as never,
162 + };
163 +});
164 +
165 import { PullRequestDetailPanel } from "./PullRequestDetailPanel";
166 import { pullRequestPanelContext } from "./pullRequestDetail.logic";
167
@@ -244,6 +260,9 @@ beforeEach(() => {
260 newThread
261 .mockReset()
262 .mockResolvedValue({ draftId: newDraftId, threadId: ThreadId.make("new-thread") });
263 + addToast.mockReset().mockReturnValue("checkout-toast");
264 + updateToast.mockReset();
265 + checkoutState.error = null;
266 prepareThread.mockReset().mockResolvedValue({
267 _tag: "Success",
268 value: { branch: "feature", worktreePath: "/workspace/pr" },
@@ -386,3 +405,32 @@ it("folds the title only for the active tab's own scroller", async () => {
405 await tab("Code").click();
406 await vi.waitFor(() => expect(titleFold()).toBe(true));
407 });
408 +
409 +it("shows the current checkout recovery detail on the first failure and on retry", async () => {
410 + const first = new GitManagerError({
411 + cwd: "/workspace",
412 + operation: "preparePullRequestThread",
413 + detail: "This PR branch is already checked out in the main repo. Use Local.",
414 + });
415 + const second = new GitCommandError({
416 + cwd: "/workspace",
417 + operation: "GitVcsDriver.createWorktree",
418 + command: "git worktree add",
419 + detail: "The worktree directory already exists. Choose another directory.",
420 + });
421 + await render();
422 +
423 + for (const [index, error] of [first, second].entries()) {
424 + prepareThread.mockImplementationOnce(async () => {
425 + checkoutState.error = error;
426 + return { _tag: "Failure", cause: Cause.fail(error) };
427 + });
428 + await page.getByRole("button", { name: "Check out", exact: true }).click();
429 + await page.getByRole("menuitem", { name: /In a separate worktree/ }).click();
430 + await vi.waitFor(() => expect(updateToast).toHaveBeenCalledTimes(index + 1));
431 + }
432 + expect(updateToast.mock.calls.map(([, toast]) => toast.description)).toEqual([
433 + expect.stringContaining(first.detail),
434 + second.detail,
435 + ]);
436 +});
apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+8 -4
@@ -8,7 +8,10 @@ import {
8 scopeProjectRef,
9 scopeThreadRef,
10 } from "@t3tools/client-runtime/environment";
11 -import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
11 +import {
12 + isAtomCommandInterrupted,
13 + squashAtomCommandFailure,
14 +} from "@t3tools/client-runtime/state/runtime";
15 import {
16 AuthOrchestrationOperateScope,
17 AuthSourceControlWriteScope,
@@ -155,6 +158,7 @@ import {
158 pullRequestFindingKey,
159 pullRequestHandoffLabels,
160 PULL_REQUEST_MERGE_METHOD_LABELS,
161 + checkoutFailureDescription,
162 readableFailure,
163 readPullRequestDetailSnapshot,
164 resolvePullRequestReferenceHost,
@@ -1214,12 +1218,12 @@ export function PullRequestDetailPanel({
1218 });
1219 if (prepared._tag === "Failure") {
1220 setHandoff(null);
1217 - const detailMessage =
1218 - prepareThread.error instanceof Error ? prepareThread.error.message : null;
1221 toastManager.update(toastId, {
1222 type: "error",
1223 title: "Could not prepare the pull request checkout",
1222 - ...(detailMessage ? { description: detailMessage } : {}),
1224 + description: checkoutFailureDescription(
1225 + isAtomCommandInterrupted(prepared) ? undefined : squashAtomCommandFailure(prepared),
1226 + ),
1227 });
1228 return;
1229 }
apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
+24
@@ -2,6 +2,7 @@ import { SourceControlProviderKind } from "@t3tools/contracts";
2 import { resolvePlanFollowUpSubmission } from "../../proposedPlan";
3 import { serializeLegacyContextMessage } from "@t3tools/shared/composerContextLegacySend";
4 import {
5 + GitCommandError,
6 ProjectId,
7 PullRequestAction,
8 type PullRequestCheck,
@@ -49,6 +50,7 @@ import {
50 pullRequestCheckoutCommand,
51 pullRequestFindingKey,
52 pullRequestReviewOutcome,
53 + checkoutFailureDescription,
54 readableFailure,
55 readPullRequestDetailSnapshot,
56 resolveDisplayedPullRequestDetail,
@@ -1050,6 +1052,28 @@ describe("what to say when an action fails", () => {
1052 expect(readableFailure(undefined, hint)).toBe(hint);
1053 });
1054
1055 + it("uses bounded git diagnostics and falls back when checkout has no useful detail", () => {
1056 + const diagnostic = (detail: string, reason?: GitCommandError["reason"]) =>
1057 + new GitCommandError({
1058 + cwd: "/workspace",
1059 + operation: "GitVcsDriver.createWorktree",
1060 + command: "git worktree add",
1061 + detail,
1062 + reason,
1063 + });
1064 + expect(
1065 + checkoutFailureDescription(diagnostic("git worktree add failed", "path_already_exists")),
1066 + ).toBe("git worktree add failed (path_already_exists)");
1067 + const reason = "The worktree directory already exists. Choose another directory.";
1068 + expect(checkoutFailureDescription(diagnostic(reason))).toBe(reason);
1069 + expect(checkoutFailureDescription(diagnostic("x".repeat(900)))).toBe(`${"x".repeat(319)}…`);
1070 + for (const failure of [undefined, diagnostic(""), diagnostic("exited with code 1")]) {
1071 + expect(checkoutFailureDescription(failure)).toBe(
1072 + "Check that the branch still exists and is not checked out elsewhere, then try again.",
1073 + );
1074 + }
1075 + });
1076 +
1077 it("bounds a host that answers with a page of output", () => {
1078 const long = readableFailure(new Error("x".repeat(900)), hint);
1079 expect(long.length).toBeLessThanOrEqual(320);
apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
+15
@@ -2,6 +2,7 @@ import { sourceControlClients } from "@t3tools/client-runtime/source-control-cli
2 import * as Schema from "effect/Schema";
3
4 import {
5 + GitCommandError,
6 PullRequestDetail,
7 PullRequestOperationError,
8 pullRequestHostOf,
@@ -1095,6 +1096,20 @@ export function readableFailure(failure: unknown, hint: string): string {
1096 return bounded;
1097 }
1098
1099 +const isGitCommandError = Schema.is(GitCommandError);
1100 +
1101 +export function checkoutFailureDescription(failure: unknown): string {
1102 + const description = isGitCommandError(failure)
1103 + ? failure.reason === undefined
1104 + ? failure.detail
1105 + : `${failure.detail} (${failure.reason})`
1106 + : failure;
1107 + return readableFailure(
1108 + description,
1109 + "Check that the branch still exists and is not checked out elsewhere, then try again.",
1110 + );
1111 +}
1112 +
1113 export function resolveBaseFreshness(detail: {
1114 readonly state: PullRequestState;
1115 readonly mergeability: PullRequestMergeability;
apps/web/src/components/pullRequest/usePullRequestActions.ts
+13 -5
@@ -1,6 +1,9 @@
1 import { useAtomCommand } from "~/state/use-atom-command";
2 import { scopeProjectRef } from "@t3tools/client-runtime/environment";
3 -import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
3 +import {
4 + isAtomCommandInterrupted,
5 + squashAtomCommandFailure,
6 +} from "@t3tools/client-runtime/state/runtime";
7 import type {
8 EnvironmentId,
9 ProjectId,
@@ -28,7 +31,12 @@ import type { ReviewCommentContext } from "~/reviewCommentContext";
31 import { pullRequestEnvironment } from "~/state/pullRequests";
32
33 import { toastManager } from "../ui/toast";
31 -import { handoffPrompt, handoffReviewComments, readableFailure } from "./pullRequestDetail.logic";
34 +import {
35 + checkoutFailureDescription,
36 + handoffPrompt,
37 + handoffReviewComments,
38 + readableFailure,
39 +} from "./pullRequestDetail.logic";
40 import { pullRequestEntryKey, type EnvironmentPullRequestEntry } from "./pullRequestList.logic";
41
42 export function usePullRequestDefaultMergeMethodResolver(
@@ -337,12 +345,12 @@ export function usePullRequestHandoffs({
345 });
346 if (prepared._tag === "Failure") {
347 setHandoff(null);
340 - const detailMessage =
341 - prepareThread.error instanceof Error ? prepareThread.error.message : null;
348 toastManager.update(toastId, {
349 type: "error",
350 title: "Could not prepare the pull request checkout",
345 - ...(detailMessage ? { description: detailMessage } : {}),
351 + description: checkoutFailureDescription(
352 + isAtomCommandInterrupted(prepared) ? undefined : squashAtomCommandFailure(prepared),
353 + ),
354 });
355 return;
356 }