Skip to content

Commit 5231459

Browse files
saphidclaude
andauthored
fix(web): review comments keep a trailing blank line in their diff (#29575)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent b1913b9 commit 5231459

4 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎apps/web/src/reviewCommentContext.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test";
55
import {
66
buildDiffReviewComment,
77
buildFileReviewComment,
8+
buildReviewCommentRenderablePatch,
89
formatReviewCommentFence,
910
resolveDiffReviewAnchor,
1011
resolveDiffReviewPosition,
@@ -75,6 +76,38 @@ describe("review comment context parsing", () => {
7576
);
7677
});
7778

79+
it("keeps a selection's trailing blank line and whitespace in the rendered excerpt", () => {
80+
const fileDiff = parsePatchFiles(
81+
[
82+
"diff --git a/src/app.ts b/src/app.ts",
83+
"--- a/src/app.ts",
84+
"+++ b/src/app.ts",
85+
"@@ -1,4 +1,4 @@",
86+
" one",
87+
"-two",
88+
"+two\t",
89+
" ",
90+
" four",
91+
].join("\n"),
92+
"review-comment-trailing-blank",
93+
)[0]!.files[0]!;
94+
const comment = (end: number) =>
95+
buildDiffReviewComment({
96+
id: "comment-blank",
97+
sectionId: "turn:1",
98+
sectionTitle: "Turn 1",
99+
filePath: "src/app.ts",
100+
fileDiff,
101+
range: { start: 2, side: "additions", end, endSide: "additions" },
102+
text: "Insert here.",
103+
})!;
104+
105+
expect(buildReviewCommentRenderablePatch(comment(2))).toMatch(/\n\+two\t$/);
106+
expect(buildReviewCommentRenderablePatch(comment(3))).toMatch(
107+
/\n@@ -3,1 \+2,2 @@\n\+two\t\n $/,
108+
);
109+
});
110+
78111
it("restores Pierre line selections from persisted diff comment row indexes", () => {
79112
const fileDiff = parsePatchFiles(
80113
[

‎apps/web/src/reviewCommentContext.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,10 @@ export function buildReviewCommentRenderablePatch(comment: ReviewCommentContext)
512512
if ((comment.fenceLanguage ?? "diff") !== "diff") {
513513
return "";
514514
}
515-
const diff = comment.diff.trim();
516-
if (diff.length === 0) {
515+
if (comment.diff.trim().length === 0) {
517516
return "";
518517
}
518+
const diff = comment.diff.trimStart().replace(/\n+$/, "");
519519
if (diff.startsWith("diff --git ")) {
520520
return diff;
521521
}

‎packages/shared/src/composerContextReferences.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,29 @@ describe("provider projection", () => {
225225
expect(project("a\n")).toContain("3 | a\n4 | \n</context>");
226226
});
227227

228+
it("keeps a review excerpt's trailing blank line and whitespace", () => {
229+
const projected = projectComposerContextForProvider({
230+
text: "[Comment](t3-context://v1/review-comment/ctx_r)",
231+
records: [
232+
{
233+
version: 1,
234+
contextId: ctx("ctx_r"),
235+
kind: "review-comment",
236+
label: "Comment",
237+
sectionId: "turn:1",
238+
sectionTitle: "Turn 1",
239+
filePath: "src/app.ts",
240+
startIndex: 1,
241+
endIndex: 2,
242+
rangeLabel: "2 to 3",
243+
text: "Insert here.",
244+
diff: "@@ -3,1 +2,2 @@\n+two\t\n \n",
245+
},
246+
],
247+
});
248+
expect(projected).toContain("diff:\n @@ -3,1 +2,2 @@\n +two\t\n \n</context>");
249+
});
250+
228251
it("emits no terminal lines when the captured range is inverted", () => {
229252
const projected = projectComposerContextForProvider({
230253
text: "[log](t3-context://v1/terminal/ctx_t)",

‎packages/shared/src/composerContextReferences.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ function formatComposerContextProviderPayload(record: KnownComposerContextRecord
293293
];
294294
if (record.text.trim()) lines.push("comment:", indent(record.text.trim()));
295295
if (record.diff.trim()) {
296-
lines.push(`${record.fenceLanguage ?? "diff"}:`, indent(record.diff.trimEnd()));
296+
lines.push(`${record.fenceLanguage ?? "diff"}:`, indent(record.diff.replace(/\n+$/, "")));
297297
}
298298
return lines.join("\n");
299299
}

0 commit comments

Comments
 (0)