Skip to content

Commit 70a869d

Browse files
fix(web): keep review thread replies with their finding in pull request comments (#20894)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 2bc2d80 commit 70a869d

8 files changed

Lines changed: 787 additions & 122 deletions

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.browser.test.tsx‎

Lines changed: 149 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ vi.mock(import("~/state/pullRequests"), async (original) => {
9292
vi.mock(import("~/state/query"), async (original) => ({
9393
...(await original()),
9494
useEnvironmentQuery: ((query: unknown) => ({
95-
data: query === "detail" ? currentDetail : query === queries.diff ? diff : null,
95+
data:
96+
query === "detail"
97+
? (activityDetail ?? currentDetail)
98+
: query === "activity"
99+
? activityDetail
100+
: query === queries.diff
101+
? diff
102+
: null,
96103
dataUpdatedAt: 0,
97104
failure: null,
98105
isPending: false,
@@ -111,33 +118,41 @@ vi.mock(import("~/state/usePullRequestStack"), async (original) => ({
111118
refresh,
112119
})) as never,
113120
}));
114-
// The summary stand-in exposes its panel actions and nested scrolling.
115-
vi.mock(import("./PullRequestSummaryTab"), async (original) => ({
116-
...(await original()),
117-
PullRequestSummaryTab: (({
118-
onFixFinding,
119-
scrollerRef,
120-
}: ComponentProps<typeof import("./PullRequestSummaryTab").PullRequestSummaryTab>) => (
121-
<div ref={scrollerRef} data-testid="summary-scroller" className="h-full overflow-y-auto">
122-
<button
123-
type="button"
124-
onClick={() =>
125-
onFixFinding?.({
126-
kind: "check",
127-
check: { name: "Unit tests", status: "failure", description: "Test failed", url: null },
128-
})
129-
}
130-
>
131-
Fix check
132-
</button>
133-
<div data-testid="nested-scroller" className="h-40 overflow-y-auto">
134-
<div className="h-[2000px]" />
135-
</div>
136-
<div className="h-[3000px]" />
137-
</div>
138-
)) as never,
139-
}));
140-
121+
// Action and scroll tests use stand-ins; activity tests render the real Summary.
122+
vi.mock(import("./PullRequestSummaryTab"), async (original) => {
123+
const actual = await original();
124+
return {
125+
...actual,
126+
PullRequestSummaryTab: ((props: ComponentProps<typeof actual.PullRequestSummaryTab>) => {
127+
if (activityDetail !== null) return <actual.PullRequestSummaryTab {...props} />;
128+
const { onFixFinding, scrollerRef } = props;
129+
return (
130+
<div ref={scrollerRef} data-testid="summary-scroller" className="h-full overflow-y-auto">
131+
<button
132+
type="button"
133+
onClick={() =>
134+
onFixFinding?.({
135+
kind: "check",
136+
check: {
137+
name: "Unit tests",
138+
status: "failure",
139+
description: "Test failed",
140+
url: null,
141+
},
142+
})
143+
}
144+
>
145+
Fix check
146+
</button>
147+
<div data-testid="nested-scroller" className="h-40 overflow-y-auto">
148+
<div className="h-[2000px]" />
149+
</div>
150+
<div className="h-[3000px]" />
151+
</div>
152+
);
153+
}) as never,
154+
};
155+
});
141156
vi.mock(import("../ui/toast"), async (original) => {
142157
const actual = await original();
143158
return {
@@ -203,6 +218,7 @@ const detail: PullRequestDetailView = {
203218
};
204219

205220
let currentDetail = detail;
221+
let activityDetail: PullRequestDetailView | null = null;
206222

207223
// Enough lines to exercise the panel's title folding with the real virtualized Code tab.
208224
const diff = {
@@ -258,6 +274,7 @@ function render(props: Partial<ComponentProps<typeof PullRequestDetailPanel>> =
258274
}
259275

260276
beforeEach(() => {
277+
activityDetail = null;
261278
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
262279
currentDetail = detail;
263280
useComposerDraftStore.setState({ draftsByThreadKey: {} });
@@ -698,3 +715,107 @@ it("shows the current checkout recovery detail on the first failure and on retry
698715
second.detail,
699716
]);
700717
});
718+
719+
it("keeps discussion counts and Timeline expansion in sync with activity refreshes", async () => {
720+
activityDetail = {
721+
...detail,
722+
provider: SourceControlProviderKind.make("gitlab"),
723+
url: "https://gitlab.com/owner/repo/-/merge_requests/1",
724+
comments: [],
725+
commentCount: 0,
726+
commentsTruncated: true,
727+
reviewThreads: [
728+
{
729+
id: "discussion-1",
730+
path: "src/index.ts",
731+
line: 1,
732+
side: "right",
733+
isResolved: false,
734+
isOutdated: false,
735+
comments: [
736+
{
737+
id: "note-1",
738+
author: detail.author,
739+
body: "Discussion finding",
740+
createdAt: "2026-09-01T00:01:00Z",
741+
url: "https://gitlab.com/owner/repo/-/merge_requests/1#note_1",
742+
},
743+
{
744+
id: "note-2",
745+
author: detail.author,
746+
body: "Discussion reply",
747+
createdAt: "2026-09-01T00:02:00Z",
748+
url: "https://gitlab.com/owner/repo/-/merge_requests/1#note_2",
749+
},
750+
],
751+
},
752+
],
753+
};
754+
await render({ reference: activityDetail });
755+
await expect.element(page.getByText("Discussion finding", { exact: true })).toBeVisible();
756+
await expect.element(page.getByText("Discussion reply", { exact: true })).toBeVisible();
757+
expect
758+
.soft(page.getByRole("button", { name: /^Comments \(/ }).element().textContent)
759+
.toBe("Comments (2)");
760+
const warning = page.getByText(/open it on the host to read the rest/).element().textContent;
761+
expect.soft(warning).toMatch(/\b2\b/);
762+
expect.soft(warning).not.toMatch(/most recent/i);
763+
764+
await tab("Timeline").click();
765+
await expect.element(page.getByText("Discussion finding", { exact: true }).last()).toBeVisible();
766+
await expect.element(page.getByText("Discussion reply", { exact: true }).last()).toBeVisible();
767+
expect.soft(page.getByLabelText(/^[0-9]+ comments?$/).element().textContent).toBe("2");
768+
769+
const threadToggle = page.getByRole("button", { name: /^src\/index\.ts:1/ });
770+
const expectThread = (expanded: boolean, status: string | null) => {
771+
const toggle = threadToggle.element();
772+
if (status) expect(toggle.textContent).toContain(status);
773+
else expect(toggle.textContent).not.toMatch(/Resolved|Review dismissed/);
774+
const visibleBody = (toggle.parentElement as HTMLElement).innerText;
775+
expect({
776+
expanded: toggle.getAttribute("aria-expanded"),
777+
findingVisible: visibleBody.includes("Discussion finding"),
778+
replyVisible: visibleBody.includes("Discussion reply"),
779+
}).toEqual({
780+
expanded: String(expanded),
781+
findingVisible: expanded,
782+
replyVisible: expanded,
783+
});
784+
};
785+
const refreshActivity = async (isResolved: boolean, reviewState: string | null = null) => {
786+
await tab("Code").click();
787+
await expect
788+
.element(page.getByRole("button", { name: "Expand all files", exact: true }))
789+
.toBeVisible();
790+
const current = activityDetail!;
791+
activityDetail = {
792+
...current,
793+
comments: current.reviewThreads.flatMap((thread) =>
794+
thread.comments.map((comment) => ({
795+
...comment,
796+
kind: "review-comment" as const,
797+
path: thread.path,
798+
reviewState,
799+
})),
800+
),
801+
reviewThreads: current.reviewThreads.map((thread) => ({ ...thread, isResolved })),
802+
};
803+
await tab("Timeline").click();
804+
};
805+
806+
expectThread(true, null);
807+
await refreshActivity(true);
808+
expectThread(false, "Resolved");
809+
await threadToggle.click();
810+
expectThread(true, "Resolved");
811+
await refreshActivity(true);
812+
expectThread(true, "Resolved");
813+
await threadToggle.click();
814+
expectThread(false, "Resolved");
815+
await refreshActivity(false);
816+
expectThread(true, null);
817+
await refreshActivity(false, "DISMISSED");
818+
expectThread(false, "Review dismissed");
819+
await refreshActivity(false);
820+
expectThread(true, null);
821+
});

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,15 @@ function usePullRequestDetail(
531531
author: activity?.author ?? coreDetail.author,
532532
reviewers: activity?.reviewers ?? coreDetail.reviewers,
533533
comments: activity?.comments ?? [],
534-
commentCount: activity?.commentCount ?? 0,
534+
commentCount: Math.max(
535+
activity?.commentCount ?? 0,
536+
new Set([
537+
...(activity?.comments.map((comment) => comment.id) ?? []),
538+
...(activity?.reviewThreads.flatMap((thread) =>
539+
thread.comments.map((comment) => comment.id),
540+
) ?? []),
541+
]).size,
542+
),
535543
commentsTruncated: activity?.commentsTruncated ?? false,
536544
reviewThreads: activity?.reviewThreads ?? [],
537545
commits: activity?.commits ?? [],
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { PullRequestReplyAvailability } from "./pullRequestDetail.logic";
2+
3+
export function PullRequestMoreReplies({
4+
moreReplies,
5+
hasMoreReplies,
6+
url,
7+
}: PullRequestReplyAvailability) {
8+
if (!hasMoreReplies) return null;
9+
return (
10+
<div className="flex flex-wrap items-baseline gap-2 py-1 text-xs text-muted-foreground">
11+
<span>
12+
{moreReplies > 0
13+
? `${moreReplies.toLocaleString()} more ${moreReplies === 1 ? "reply" : "replies"}`
14+
: "More replies"}
15+
</span>
16+
{url ? (
17+
<a
18+
href={url}
19+
target="_blank"
20+
rel="noopener noreferrer"
21+
className="hover:text-foreground hover:underline"
22+
>
23+
View on host
24+
</a>
25+
) : null}
26+
</div>
27+
);
28+
}

‎apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx‎

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { SourceControlProviderKind } from "@t3tools/contracts";
2-
import { EnvironmentId, ProjectId, type PullRequestDetailView } from "@t3tools/contracts";
2+
import {
3+
EnvironmentId,
4+
ProjectId,
5+
type PullRequestDetailView,
6+
type PullRequestComment,
7+
} from "@t3tools/contracts";
38
import { act } from "react";
49
import { createRoot, type Root } from "react-dom/client";
510
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
@@ -219,3 +224,62 @@ it("hides bot and resolved comments until the filter shows them, and remembers t
219224
await userEvent.click(filterButton());
220225
expect(filterItem("Bot comments").getAttribute("aria-checked")).toBe("true");
221226
});
227+
228+
it("reveals whole older conversations with honest partial reply counts and a host link", async () => {
229+
const comment = (index: number): PullRequestComment => ({
230+
id: `comment-${index}`,
231+
kind: "issue-comment",
232+
author: detail.author,
233+
body: `Comment ${index}`,
234+
createdAt: `2026-09-01T00:00:${String(index).padStart(2, "0")}Z`,
235+
url: `${detail.url}#comment-${index}`,
236+
path: null,
237+
reviewState: null,
238+
});
239+
const finding = { ...comment(0), kind: "review-comment" as const, body: "Review finding" };
240+
const reply = { ...comment(12), kind: "review-comment" as const, body: "Loaded reply" };
241+
const thread = {
242+
id: "partial-thread",
243+
path: "src/index.ts",
244+
line: 1,
245+
side: "right" as const,
246+
isResolved: true,
247+
isOutdated: false,
248+
comments: [finding, reply],
249+
nextCommentsCursor: "next-page",
250+
};
251+
const value: PullRequestDetailView = {
252+
...detail,
253+
comments: [finding, ...Array.from({ length: 10 }, (_, index) => comment(index + 1)), reply],
254+
commentCount: 15,
255+
reviewThreads: [{ ...thread, commentCount: 5 }],
256+
};
257+
await render(value);
258+
await toggleFilter("Resolved or dismissed");
259+
await userEvent.keyboard("{Escape}");
260+
const older = [...container.querySelectorAll("button")].find((button) =>
261+
button.textContent?.startsWith("Show 1 older"),
262+
)!;
263+
expect(older).toBeDefined();
264+
expect.soft(older.textContent).toMatch(/1 older conversation.*1 hidden/);
265+
expect(commentTexts()).not.toContain(reply.body);
266+
await userEvent.click(older);
267+
const resolved = [...container.querySelectorAll("button")].find(
268+
(button) => button.textContent === "Resolved",
269+
)!;
270+
expect(resolved.getAttribute("aria-expanded")).toBe("false");
271+
expect(commentTexts()).not.toContain(reply.body);
272+
expect.soft(visibleText()).toContain("4 replies");
273+
await userEvent.click(resolved);
274+
expect(commentTexts().slice(-2)).toEqual([finding.body, reply.body]);
275+
expect.soft(visibleText()).toContain("3 more replies");
276+
const hostLink = [...container.querySelectorAll("a")].find(
277+
(link) =>
278+
link.href === finding.url && /host/i.test(link.textContent ?? "") && link.checkVisibility(),
279+
);
280+
expect.soft(hostLink, "visible link to the unloaded replies on the host").toBeDefined();
281+
282+
await render({ ...value, reviewThreads: [thread] });
283+
expect.soft(visibleText()).toMatch(/more replies/i);
284+
expect(visibleText()).not.toContain("3 more replies");
285+
});

0 commit comments

Comments
 (0)