Skip to content

Commit 6e03907

Browse files
saphidclaude
authored andcommitted
fix(web): review comments keep a trailing blank line in their diff
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cbd3e14 commit 6e03907

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
@@ -221,6 +221,29 @@ describe("provider projection", () => {
221221
expect(project("a\n")).toContain("3 | a\n4 | \n</context>");
222222
});
223223

224+
it("keeps a review excerpt's trailing blank line and whitespace", () => {
225+
const projected = projectComposerContextForProvider({
226+
text: "[Comment](t3-context://v1/review-comment/ctx_r)",
227+
records: [
228+
{
229+
version: 1,
230+
contextId: ctx("ctx_r"),
231+
kind: "review-comment",
232+
label: "Comment",
233+
sectionId: "turn:1",
234+
sectionTitle: "Turn 1",
235+
filePath: "src/app.ts",
236+
startIndex: 1,
237+
endIndex: 2,
238+
rangeLabel: "2 to 3",
239+
text: "Insert here.",
240+
diff: "@@ -3,1 +2,2 @@\n+two\t\n \n",
241+
},
242+
],
243+
});
244+
expect(projected).toContain("diff:\n @@ -3,1 +2,2 @@\n +two\t\n \n</context>");
245+
});
246+
224247
it("emits no terminal lines when the captured range is inverted", () => {
225248
const projected = projectComposerContextForProvider({
226249
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
@@ -289,7 +289,7 @@ function formatComposerContextProviderPayload(record: KnownComposerContextRecord
289289
];
290290
if (record.text.trim()) lines.push("comment:", indent(record.text.trim()));
291291
if (record.diff.trim()) {
292-
lines.push(`${record.fenceLanguage ?? "diff"}:`, indent(record.diff.trimEnd()));
292+
lines.push(`${record.fenceLanguage ?? "diff"}:`, indent(record.diff.replace(/\n+$/, "")));
293293
}
294294
return lines.join("\n");
295295
}

0 commit comments

Comments
 (0)