Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/web/src/reviewCommentContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test";
import {
buildDiffReviewComment,
buildFileReviewComment,
buildReviewCommentRenderablePatch,
formatReviewCommentFence,
resolveDiffReviewAnchor,
resolveDiffReviewPosition,
Expand Down Expand Up @@ -75,6 +76,38 @@ describe("review comment context parsing", () => {
);
});

it("keeps a selection's trailing blank line and whitespace in the rendered excerpt", () => {
const fileDiff = parsePatchFiles(
[
"diff --git a/src/app.ts b/src/app.ts",
"--- a/src/app.ts",
"+++ b/src/app.ts",
"@@ -1,4 +1,4 @@",
" one",
"-two",
"+two\t",
" ",
" four",
].join("\n"),
"review-comment-trailing-blank",
)[0]!.files[0]!;
const comment = (end: number) =>
buildDiffReviewComment({
id: "comment-blank",
sectionId: "turn:1",
sectionTitle: "Turn 1",
filePath: "src/app.ts",
fileDiff,
range: { start: 2, side: "additions", end, endSide: "additions" },
text: "Insert here.",
})!;

expect(buildReviewCommentRenderablePatch(comment(2))).toMatch(/\n\+two\t$/);
expect(buildReviewCommentRenderablePatch(comment(3))).toMatch(
/\n@@ -3,1 \+2,2 @@\n\+two\t\n $/,
);
});

it("restores Pierre line selections from persisted diff comment row indexes", () => {
const fileDiff = parsePatchFiles(
[
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/reviewCommentContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,10 @@ export function buildReviewCommentRenderablePatch(comment: ReviewCommentContext)
if ((comment.fenceLanguage ?? "diff") !== "diff") {
return "";
}
const diff = comment.diff.trim();
if (diff.length === 0) {
if (comment.diff.trim().length === 0) {
return "";
}
const diff = comment.diff.trimStart().replace(/\n+$/, "");
if (diff.startsWith("diff --git ")) {
return diff;
}
Expand Down
23 changes: 23 additions & 0 deletions packages/shared/src/composerContextReferences.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,29 @@ describe("provider projection", () => {
expect(project("a\n")).toContain("3 | a\n4 | \n</context>");
});

it("keeps a review excerpt's trailing blank line and whitespace", () => {
const projected = projectComposerContextForProvider({
text: "[Comment](t3-context://v1/review-comment/ctx_r)",
records: [
{
version: 1,
contextId: ctx("ctx_r"),
kind: "review-comment",
label: "Comment",
sectionId: "turn:1",
sectionTitle: "Turn 1",
filePath: "src/app.ts",
startIndex: 1,
endIndex: 2,
rangeLabel: "2 to 3",
text: "Insert here.",
diff: "@@ -3,1 +2,2 @@\n+two\t\n \n",
},
],
});
expect(projected).toContain("diff:\n @@ -3,1 +2,2 @@\n +two\t\n \n</context>");
});

it("emits no terminal lines when the captured range is inverted", () => {
const projected = projectComposerContextForProvider({
text: "[log](t3-context://v1/terminal/ctx_t)",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/composerContextReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function formatComposerContextProviderPayload(record: KnownComposerContextRecord
];
if (record.text.trim()) lines.push("comment:", indent(record.text.trim()));
if (record.diff.trim()) {
lines.push(`${record.fenceLanguage ?? "diff"}:`, indent(record.diff.trimEnd()));
lines.push(`${record.fenceLanguage ?? "diff"}:`, indent(record.diff.replace(/\n+$/, "")));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
return lines.join("\n");
}
Expand Down
Loading