Skip to content

fix: validate inline review comment lines against diff hunks - #1348

Merged
waynesun09 merged 2 commits into
mainfrom
fix-review-inline-comments
May 22, 2026
Merged

fix: validate inline review comment lines against diff hunks#1348
waynesun09 merged 2 commits into
mainfrom
fix-review-inline-comments

Conversation

@waynesun09

Copy link
Copy Markdown
Member

Summary

  • Fixes GitHub 422 errors when the review agent places inline comments on lines outside diff hunks. Previously only file-level validation was done; now line-level validation against parsed hunk headers prevents the 422.
  • Adds ListPullRequestFileDiffs to the forge interface to return unified diff patches alongside file paths
  • Adds parseDiffLineRanges to extract valid new-side line ranges from @@ -a,b +c,d @@ hunk headers
  • Updates findingsToReviewComments to filter by both file presence and line-in-hunk, with separate warning counts

Test plan

  • TestParseDiffLineRanges — single hunk, multiple hunks, new file, deletion-only, omitted size, empty patch, mixed
  • TestFindingsToReviewComments — no filtering when diffHunks is nil
  • TestFindingsToReviewComments_FiltersByDiffHunks — file not in diff, line outside hunk, line inside hunk
  • TestSubmitFormalReview_FiltersByPRFileDiffs — end-to-end with fake client and patches
  • TestSubmitFormalReview_ListPRFileDiffsErrorFallsBack — graceful fallback on API error
  • TestSubmitFormalReview_EmptyPRFileDiffListFallsBack — graceful fallback on empty list
  • TestListPullRequestFileDiffs — GitHub client correctly extracts path and patch
  • go test ./internal/cli/... ./internal/forge/... all pass
  • go vet clean

The post-review script was failing with GitHub 422 errors when the
review agent placed inline comments on lines that exist in the file
but fall outside any diff hunk. The existing validation only checked
whether the file was in the PR diff, not whether the specific line
was within a diff hunk.

Add ListPullRequestFileDiffs to the forge interface which returns the
unified diff patch alongside each file path. Parse hunk headers to
extract valid line ranges and filter out comments targeting lines
outside those ranges before submitting the review.

Signed-off-by: Wayne Sun <gsun@redhat.com>
@github-actions

github-actions Bot commented May 21, 2026

Copy link
Copy Markdown

Site preview

Preview: https://43c43f2c-site.fullsend-ai.workers.dev

Commit: 6de3ac6f5d6c0b04388cb0a03a171f8b2761c229

@fullsend-ai-review

fullsend-ai-review Bot commented May 21, 2026

Copy link
Copy Markdown

Review

Findings

Low

  • [style] internal/forge/forge.go:216ListPullRequestFiles becomes dead code after this PR. Its only call site in submitFormalReview is replaced by ListPullRequestFileDiffs. Consider removing the old method and its implementations (LiveClient, FakeClient) in a follow-up to reduce interface surface.

All seven review dimensions evaluated. The hunk-header parsing (parseDiffLineRanges) correctly handles single/multiple hunks, new files, deletion-only hunks, omitted size, and empty patches. The findingsToReviewComments refactor properly separates file-level and line-level filtering with graceful fallback for binary/truncated patches (empty hunk list skips line filtering). Test coverage is comprehensive across unit and integration levels.

Previous run

Review

Findings

No findings.

@fullsend-ai-review fullsend-ai-review Bot added the ready-for-merge All reviewers approved — ready to merge label May 21, 2026
Files with empty patches (binary, renamed-only, truncated large diffs)
had all inline comments silently dropped because parseDiffLineRanges
returned nil and lineInHunks always returned false. Skip line-level
filtering when hunk data is unavailable.

Also adds a strings.HasPrefix fast-path to skip regex evaluation on
non-hunk-header lines.

Signed-off-by: Wayne Sun <gsun@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-merge All reviewers approved — ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant