From 69415946ddaf5dd699544f7da1b0f4ae512c7ed0 Mon Sep 17 00:00:00 2001 From: PP <128917720+huhuhulululu@users.noreply.github.com> Date: Fri, 3 Jul 2026 20:25:32 -0400 Subject: [PATCH] fix(github): count PR diff lines whose added content starts with ++ (#6819) Co-authored-by: ping --- .../github/pr-review-comment-lines.test.ts | 18 ++++++++++++++++++ src/main/github/pr-review-comment-lines.ts | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/github/pr-review-comment-lines.test.ts b/src/main/github/pr-review-comment-lines.test.ts index 13a525bca..4871ee88b 100644 --- a/src/main/github/pr-review-comment-lines.test.ts +++ b/src/main/github/pr-review-comment-lines.test.ts @@ -23,4 +23,22 @@ describe('getPRReviewCommentLineNumbersFromPatch', () => { it('returns an empty list when GitHub omits the patch', () => { expect(getPRReviewCommentLineNumbersFromPatch(undefined)).toEqual([]) }) + + it('counts added lines whose content begins with ++', () => { + // Inside a hunk, GitHub's per-file patch never carries a `+++ b/file` header + // (those precede the first @@), so `+++count` is an added line of content `++count` + // and must stay comment-eligible. + const patch = ['@@ -1,1 +1,2 @@', ' const a = 1', '+++count'].join('\n') + + expect(getPRReviewCommentLineNumbersFromPatch(patch)).toEqual([1, 2]) + }) + + it('does not treat removed lines whose content begins with -- as commentable', () => { + // Asymmetry guard: removed lines never advance the new-side counter, so `--count` + // (diff line `---count`) must not become commentable. Locks the intended difference + // from the added-line case so a future "symmetric" edit can't regress it. + const patch = ['@@ -1,2 +1,1 @@', ' const a = 1', '---count'].join('\n') + + expect(getPRReviewCommentLineNumbersFromPatch(patch)).toEqual([1]) + }) }) diff --git a/src/main/github/pr-review-comment-lines.ts b/src/main/github/pr-review-comment-lines.ts index 0d64d214e..2c8d74729 100644 --- a/src/main/github/pr-review-comment-lines.ts +++ b/src/main/github/pr-review-comment-lines.ts @@ -21,7 +21,10 @@ export function getPRReviewCommentLineNumbersFromPatch(patch: string | undefined continue } - if (line.startsWith('+') && !line.startsWith('+++')) { + // Inside a hunk every `+` line is added content. GitHub's per-file patch keeps the + // `+++ b/file` header before the first @@, so a `+++…` line here is `++…` content, + // not a header, and must stay comment-eligible. + if (line.startsWith('+')) { lineNumbers.push(nextModifiedLine) nextModifiedLine++ continue