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