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 22, 23:15 UTC
fix(web): Add to agent works on pull requests you cannot comment on (#19701)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Shubhanshu Shukla committed
Oct 20, 2026 at 10:29 UTC
ee3a3e8eca5db4796a49d77ecb068743e3894c45
2 files changed
+171
-56
apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
+17
-6
@@ -463,6 +463,9 @@ function PullRequestCodeTab({
463
resolve: hostReview.resolve && detail.viewerPermissions.resolve,
464
};
465
const canCommentOnLines = review.inlineComment && commit === null;
466
+ // Agent context is local, so it does not require host comment permission.
467
+ const canSelectLines =
468
+ commit === null && (review.inlineComment || onAddToAgentSelection !== undefined);
469
// The cache key carries the theme, which is what the tokenizer caches against, so a theme
470
// change is still a fresh parse. The patch's own hash is part of it too: a refreshed page
471
// reuses its cursor, and a key of position alone would hand back the parse it replaced.
@@ -708,7 +711,7 @@ function PullRequestCodeTab({
711
range: SelectedLineRange | null,
712
context: { item: CodeViewItem<ReviewAnnotationGroup> },
713
) => {
711
- if (!range || !canCommentOnLines) return;
714
+ if (!range || !canSelectLines) return;
715
const item = context.item;
716
if (item.type !== "diff") return;
717
const file = files.find((candidate) => buildFileDiffRenderKey(candidate) === item.id);
@@ -832,8 +835,8 @@ function PullRequestCodeTab({
835
themeType: resolvedTheme,
836
stickyHeaders: true,
837
loadDiffFiles,
835
- enableGutterUtility: canCommentOnLines && draft === null,
836
- enableLineSelection: canCommentOnLines && draft === null,
838
+ enableGutterUtility: canSelectLines && draft === null,
839
+ enableLineSelection: canSelectLines && draft === null,
840
onGutterUtilityClick: beginComment,
841
onLineSelectionEnd: beginComment,
842
};
@@ -930,13 +933,13 @@ function PullRequestCodeTab({
933
onRemove={() => removeComment(reviewKey, comment.id)}
934
/>
935
))}
933
- {annotation.metadata.draft && draft ? (
936
+ {annotation.metadata.draft && draft && canSelectLines ? (
937
<DiffCommentAnnotation
938
kind="draft"
939
rangeLabel={`${draft.path}:${getReviewPositionAnchor(draft.position).line}`}
940
text=""
938
- submitLabel="Add to review"
939
- {...(onAddToAgentSelection
941
+ submitLabel={canCommentOnLines ? "Add to review" : "Add to agent"}
942
+ {...(canCommentOnLines && onAddToAgentSelection
943
? {
944
secondaryAction: {
945
label: "Add to agent",
@@ -952,6 +955,14 @@ function PullRequestCodeTab({
955
setSelectedLines(null);
956
}}
957
onComment={(body) => {
958
+ if (!canCommentOnLines) {
959
+ if (onAddToAgentSelection) {
960
+ finishSelection(draft, body, (comment) =>
961
+ onAddToAgentSelection({ comment, request: body }),
962
+ );
963
+ }
964
+ return;
965
+ }
966
addComment(reviewKey, {
967
id: nextPendingReviewCommentId(),
968
path: draft.path,
apps/web/src/components/pullRequest/PullRequestDetailPanel.browser.test.tsx
+154
-50
@@ -13,21 +13,32 @@ 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";
16
-import { page } from "vite-plus/test/browser";
16
+import { page, userEvent } from "vite-plus/test/browser";
17
import { DraftId, useComposerDraftStore } from "~/composerDraftStore";
18
19
import "~/index.css";
20
21
-const { newThread, prepareThread, refresh, update, addToast, updateToast, checkoutState } =
22
- vi.hoisted(() => ({
23
- newThread: vi.fn(),
24
- prepareThread: vi.fn(),
25
- refresh: vi.fn(),
26
- update: vi.fn(),
27
- addToast: vi.fn(),
28
- updateToast: vi.fn(),
29
- checkoutState: { error: null as Error | null },
30
- }));
21
+const {
22
+ newThread,
23
+ prepareThread,
24
+ refresh,
25
+ update,
26
+ addToast,
27
+ updateToast,
28
+ checkoutState,
29
+ hostCommand,
30
+ queries,
31
+} = vi.hoisted(() => ({
32
+ hostCommand: vi.fn(),
33
+ queries: { diff: undefined as unknown },
34
+ newThread: vi.fn(),
35
+ prepareThread: vi.fn(),
36
+ refresh: vi.fn(),
37
+ update: vi.fn(),
38
+ addToast: vi.fn(),
39
+ updateToast: vi.fn(),
40
+ checkoutState: { error: null as Error | null },
41
+}));
42
43
vi.mock(import("~/state/session"), async (original) => ({
44
...(await original()),
@@ -52,17 +63,20 @@ vi.mock(import("~/lib/sourceControlActions"), async (original) => ({
63
}));
64
vi.mock(import("~/state/use-atom-command"), async (original) => ({
65
...(await original()),
55
- useAtomCommand: ((command: unknown) => (command === "update" ? update : vi.fn())) as never,
66
+ useAtomCommand: ((command: unknown) => (command === "update" ? update : hostCommand)) as never,
67
}));
68
vi.mock(import("~/state/pullRequests"), async (original) => {
69
const actual = await original();
70
const { Atom } = await import("effect/reactivity");
71
const cannotWriteGuides = Atom.make(false);
72
+ const diff = Atom.make(null);
73
+ queries.diff = diff;
74
return {
75
...actual,
76
pullRequestEnvironment: {
77
...actual.pullRequestEnvironment,
78
detail: (() => "detail") as never,
79
+ diff: (() => diff) as never,
80
activity: (() => "activity") as never,
81
update: "update" as never,
82
reviewGuide: (() => "review-guide") as never,
@@ -76,7 +90,7 @@ vi.mock(import("~/state/pullRequests"), async (original) => {
90
vi.mock(import("~/state/query"), async (original) => ({
91
...(await original()),
92
useEnvironmentQuery: ((query: unknown) => ({
79
- data: query === "detail" ? detail : null,
93
+ data: query === "detail" ? currentDetail : query === queries.diff ? diff : null,
94
dataUpdatedAt: 0,
95
failure: null,
96
isPending: false,
@@ -95,8 +109,7 @@ vi.mock(import("~/state/usePullRequestStack"), async (original) => ({
109
refresh,
110
})) as never,
111
}));
98
-// The real tabs load diffs, markdown and checks from the environment; these stand-ins
99
-// expose the actions they hand back to the panel and a tall scroller.
112
+// The summary stand-in exposes its panel actions and nested scrolling.
113
vi.mock(import("./PullRequestSummaryTab"), async (original) => ({
114
...(await original()),
115
PullRequestSummaryTab: (({
@@ -122,38 +135,6 @@ vi.mock(import("./PullRequestSummaryTab"), async (original) => ({
135
</div>
136
)) as never,
137
}));
125
-vi.mock(import("./PullRequestCodeTab"), async (original) => ({
126
- ...(await original()),
127
- default: (({
128
- onAddToAgentSelection,
129
- scrollerRef,
130
- }: ComponentProps<typeof import("./PullRequestCodeTab").default>) => (
131
- <div ref={scrollerRef} data-testid="code-scroller" className="h-full overflow-y-auto">
132
- <button
133
- type="button"
134
- onClick={() =>
135
- onAddToAgentSelection?.({
136
- request: "Fix this line",
137
- comment: {
138
- id: "note-1",
139
- sectionId: "file:a.ts",
140
- sectionTitle: "a.ts",
141
- filePath: "a.ts",
142
- startIndex: 0,
143
- endIndex: 0,
144
- rangeLabel: "L1",
145
- text: "Please fix",
146
- diff: "+broken()",
147
- },
148
- })
149
- }
150
- >
151
- Add to agent
152
- </button>
153
- <div className="h-[3000px]" />
154
- </div>
155
- )) as never,
156
-}));
138
139
vi.mock(import("../ui/toast"), async (original) => {
140
const actual = await original();
@@ -165,6 +146,7 @@ vi.mock(import("../ui/toast"), async (original) => {
146
147
import { PullRequestDetailPanel } from "./PullRequestDetailPanel";
148
import { pullRequestPanelContext } from "./pullRequestDetail.logic";
149
+import { usePullRequestReviewStore } from "./pullRequestReviewStore";
150
151
const detail: PullRequestDetailView = {
152
provider: SourceControlProviderKind.make("github"),
@@ -218,6 +200,24 @@ const detail: PullRequestDetailView = {
200
},
201
};
202
203
+let currentDetail = detail;
204
+
205
+// Enough lines to exercise the panel's title folding with the real virtualized Code tab.
206
+const diff = {
207
+ patch: [
208
+ "diff --git a/a.ts b/a.ts",
209
+ "new file mode 100644",
210
+ "--- /dev/null",
211
+ "+++ b/a.ts",
212
+ "@@ -0,0 +1,100 @@",
213
+ "+broken()",
214
+ ...Array.from({ length: 99 }, (_, index) => `+// line ${index + 2}`),
215
+ "",
216
+ ].join("\n"),
217
+ truncated: false,
218
+ nextCursor: null,
219
+};
220
+
221
const threadRef: ScopedThreadRef = {
222
environmentId: EnvironmentId.make("env-1"),
223
threadId: ThreadId.make("thread-1"),
@@ -257,7 +257,10 @@ function render(props: Partial<ComponentProps<typeof PullRequestDetailPanel>> =
257
258
beforeEach(() => {
259
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
260
+ currentDetail = detail;
261
useComposerDraftStore.setState({ draftsByThreadKey: {} });
262
+ usePullRequestReviewStore.setState({ drafts: {}, summaries: {} });
263
+ hostCommand.mockReset();
264
newThread
265
.mockReset()
266
.mockResolvedValue({ draftId: newDraftId, threadId: ThreadId.make("new-thread") });
@@ -300,6 +303,16 @@ const unrelatedThread = {
303
304
const tab = (name: string) => page.getByRole("button", { name, exact: true });
305
306
+const selectionDraft = () => page.getByRole("textbox", { name: "Comment on lines a.ts:1" });
307
+
308
+async function selectFirstLine() {
309
+ const line = page.getByText("broken()", { exact: true });
310
+ await expect.element(line).toBeVisible();
311
+ const host = line.element().getRootNode() as ShadowRoot;
312
+ const gutter = host.querySelector<HTMLElement>('[data-column-number="1"]')!;
313
+ await userEvent.click(gutter);
314
+}
315
+
316
it.each([
317
{ isComposing: true, keyCode: 13 },
318
{ isComposing: false, keyCode: 229 },
@@ -333,6 +346,14 @@ it.each([
346
async function runAction(action: string) {
347
if (action === "Add to agent") {
348
await tab("Code").click();
349
+ await page.getByRole("button", { name: "Expand all files", exact: true }).click();
350
+ await selectFirstLine();
351
+ const draft = page.getByRole("textbox", { name: "Comment on lines a.ts:1" });
352
+ await expect.element(draft).toBeVisible();
353
+ expect(
354
+ page.getByRole("button", { name: "Add to review", exact: true }).elements(),
355
+ ).toHaveLength(0);
356
+ await draft.fill("Fix this line");
357
}
358
if (["Ask a question", "Explain this PR"].includes(action) || action.startsWith("Fix findings")) {
359
await page.getByRole("button", { name: "More pull request actions" }).click();
@@ -369,6 +390,17 @@ describe.each([
390
"Fix check",
391
"Add to agent",
392
])("%s writes to the correct composer", async (action) => {
393
+ // Cover both a host without inline comments and an account that cannot write them.
394
+ currentDetail =
395
+ thread === stackThread
396
+ ? {
397
+ ...detail,
398
+ capabilities: {
399
+ ...detail.capabilities,
400
+ review: { ...detail.capabilities.review, inlineComment: true },
401
+ },
402
+ }
403
+ : { ...detail, viewerPermissions: { ...detail.viewerPermissions, comment: true } };
404
if (target) useComposerDraftStore.getState().setPrompt(target, "Keep my draft");
405
await renderPanel();
406
await runAction(target ? action : action.replace("in this thread", "in a thread"));
@@ -384,8 +416,20 @@ describe.each([
416
if (action === "Add to agent") {
417
expect(draft()?.prompt).toContain("Fix this line");
418
expect(draft()?.reviewComments).toEqual(
387
- expect.arrayContaining([expect.objectContaining({ id: "note-1", diff: "+broken()" })]),
419
+ expect.arrayContaining([
420
+ expect.objectContaining({
421
+ filePath: "a.ts",
422
+ diff: expect.stringContaining("+broken()"),
423
+ startIndex: 0,
424
+ endIndex: 0,
425
+ }),
426
+ ]),
427
);
428
+ expect(usePullRequestReviewStore.getState().drafts).toEqual({});
429
+ expect(hostCommand).not.toHaveBeenCalled();
430
+ await expect
431
+ .element(page.getByRole("textbox", { name: "Comment on lines a.ts:1" }))
432
+ .not.toBeInTheDocument();
433
}
434
if (target) {
435
expect(draft()?.prompt).toContain("Keep my draft");
@@ -397,13 +441,72 @@ describe.each([
441
});
442
});
443
444
+it("offers both selection actions and queues a permitted host review locally", async () => {
445
+ currentDetail = {
446
+ ...detail,
447
+ capabilities: {
448
+ ...detail.capabilities,
449
+ review: { ...detail.capabilities.review, inlineComment: true },
450
+ },
451
+ viewerPermissions: { ...detail.viewerPermissions, comment: true },
452
+ };
453
+ await render({ composerDraftTarget: draftId, threadRef });
454
+ await tab("Code").click();
455
+ await page.getByRole("button", { name: "Expand all files", exact: true }).click();
456
+ await selectFirstLine();
457
+ const addToReview = page.getByRole("button", { name: "Add to review", exact: true });
458
+ await expect.element(addToReview).toBeVisible();
459
+ await expect
460
+ .element(page.getByRole("button", { name: "Add to agent", exact: true }))
461
+ .toBeVisible();
462
+ await selectionDraft().fill("Fix this line before merging");
463
+ await addToReview.click();
464
+ await expect.element(selectionDraft()).not.toBeInTheDocument();
465
+ expect(Object.values(usePullRequestReviewStore.getState().drafts).flat()).toEqual([
466
+ expect.objectContaining({ path: "a.ts", body: "Fix this line before merging" }),
467
+ ]);
468
+ expect(useComposerDraftStore.getState().getComposerDraft(draftId)?.reviewComments ?? []).toEqual(
469
+ [],
470
+ );
471
+ expect(hostCommand).not.toHaveBeenCalled();
472
+});
473
+
474
+it("cancels an agent-only selection and submits a fresh one with the keyboard without a host review", async () => {
475
+ await render({ composerDraftTarget: draftId, threadRef });
476
+ await tab("Code").click();
477
+ await page.getByRole("button", { name: "Expand all files", exact: true }).click();
478
+ await selectFirstLine();
479
+ await selectionDraft().fill("Discard this request");
480
+ await page.getByRole("button", { name: "Cancel", exact: true }).click();
481
+ await expect.element(selectionDraft()).not.toBeInTheDocument();
482
+ expect(useComposerDraftStore.getState().getComposerDraft(draftId)?.reviewComments ?? []).toEqual(
483
+ [],
484
+ );
485
+ expect(usePullRequestReviewStore.getState().drafts).toEqual({});
486
+ expect(hostCommand).not.toHaveBeenCalled();
487
+
488
+ await selectFirstLine();
489
+ await expect.element(selectionDraft()).toHaveValue("");
490
+ await selectionDraft().fill("Fix this line");
491
+ await userEvent.keyboard("{Control>}{Enter}{/Control}");
492
+ await expect.element(selectionDraft()).not.toBeInTheDocument();
493
+ expect(useComposerDraftStore.getState().getComposerDraft(draftId)?.prompt).toContain(
494
+ "Fix this line",
495
+ );
496
+ expect(usePullRequestReviewStore.getState().drafts).toEqual({});
497
+ expect(hostCommand).not.toHaveBeenCalled();
498
+});
499
+
500
it("folds the title only for the active tab's own scroller", async () => {
501
await render();
502
const title = page.getByRole("heading", { level: 1, name: "Test pull request" });
503
await expect.element(title).toBeVisible();
504
const titleFold = () => title.element().closest("[inert]") !== null;
505
const scrollTo = async (testId: string, top: number) => {
406
- const scroller = page.getByTestId(testId).element() as HTMLElement;
506
+ const scroller =
507
+ testId === "code-scroller"
508
+ ? document.querySelector<HTMLElement>(".\\@container.overflow-auto")!
509
+ : (page.getByTestId(testId).element() as HTMLElement);
510
await act(async () => {
511
scroller.scrollTop = top;
512
scroller.dispatchEvent(new Event("scroll"));
@@ -425,7 +528,8 @@ it("folds the title only for the active tab's own scroller", async () => {
528
await vi.waitFor(() => expect(titleFold()).toBe(true));
529
530
await tab("Code").click();
428
- await expect.element(page.getByTestId("code-scroller")).toBeInTheDocument();
531
+ await page.getByRole("button", { name: "Expand all files", exact: true }).click();
532
+ await expect.element(page.getByText("broken()", { exact: true })).toBeVisible();
533
await vi.waitFor(() => expect(titleFold()).toBe(false));
534
await scrollTo("code-scroller", 600);
535
await vi.waitFor(() => expect(titleFold()).toBe(true));