GeezerVison is showing github.com — fix(web): review comments keep a trailing blank line in their diff · pingdotgg/t3code@6e03907
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/reviewCommentContext.test.ts +33Lines changed: 33 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test"; | 5 | 5 | import { | 6 | 6 | buildDiffReviewComment, | 7 | 7 | buildFileReviewComment, | | 8 | + buildReviewCommentRenderablePatch, | 8 | 9 | formatReviewCommentFence, | 9 | 10 | resolveDiffReviewAnchor, | 10 | 11 | resolveDiffReviewPosition, | @@ -75,6 +76,38 @@ describe("review comment context parsing", () => { | 75 | 76 | ); | 76 | 77 | }); | 77 | 78 |
| | 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 | + | 78 | 111 | it("restores Pierre line selections from persisted diff comment row indexes", () => { | 79 | 112 | const fileDiff = parsePatchFiles( | 80 | 113 | [ | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/reviewCommentContext.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -512,10 +512,10 @@ export function buildReviewCommentRenderablePatch(comment: ReviewCommentContext) | 512 | 512 | if ((comment.fenceLanguage ?? "diff") !== "diff") { | 513 | 513 | return ""; | 514 | 514 | } | 515 | | - const diff = comment.diff.trim(); | 516 | | - if (diff.length === 0) { | | 515 | + if (comment.diff.trim().length === 0) { | 517 | 516 | return ""; | 518 | 517 | } | | 518 | + const diff = comment.diff.trimStart().replace(/\n+$/, ""); | 519 | 519 | if (diff.startsWith("diff --git ")) { | 520 | 520 | return diff; | 521 | 521 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/composerContextReferences.test.ts +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -221,6 +221,29 @@ describe("provider projection", () => { | 221 | 221 | expect(project("a\n")).toContain("3 | a\n4 | \n</context>"); | 222 | 222 | }); | 223 | 223 |
| | 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 | + | 224 | 247 | it("emits no terminal lines when the captured range is inverted", () => { | 225 | 248 | const projected = projectComposerContextForProvider({ | 226 | 249 | text: "[log](t3-context://v1/terminal/ctx_t)", | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/composerContextReferences.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -289,7 +289,7 @@ function formatComposerContextProviderPayload(record: KnownComposerContextRecord | 289 | 289 | ]; | 290 | 290 | if (record.text.trim()) lines.push("comment:", indent(record.text.trim())); | 291 | 291 | 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+$/, ""))); | 293 | 293 | } | 294 | 294 | return lines.join("\n"); | 295 | 295 | } | |
|