Skip to content

Fix extractHunkAroundLines bug for top-of-file hunks, add 19 tests#767

Merged
selfcontained merged 1 commit into
mainfrom
agt_cc697f2f1a15/job-test-enforcer-2b126694
Jul 14, 2026
Merged

Fix extractHunkAroundLines bug for top-of-file hunks, add 19 tests#767
selfcontained merged 1 commit into
mainfrom
agt_cc697f2f1a15/job-test-enforcer-2b126694

Conversation

@selfcontained

Copy link
Copy Markdown
Owner

Summary

  • Bug fix: extractHunkAroundLines used newLineNum === 0 as a guard to skip lines before the first hunk header, but this also blocked all lines in hunks starting at +1 (top of file). Replaced with an insideHunk boolean flag.
  • Extraction: Moved the function from a private local in reviews.ts to shared/lib/extract-hunk.ts for testability.
  • Tests: Added 19 unit tests covering single-line targets, multi-line ranges, context windows, multi-hunk diffs, deletion line handling, hunk headers with function names, edge cases (empty diff, no hunk headers, +0 hunks), and adjacent hunks.

Test plan

  • pnpm run check passes
  • pnpm run test passes (2386 server + 195 web)
  • pnpm run test:e2e passes (168 passed, 12 skipped terminal-live)
  • New test file runs in isolation: vitest run test/extract-hunk.test.ts — 19/19 pass
  • Review agent confirmed fix correctness and no flaky-test risk

🤖 Generated with Claude Code

The `newLineNum === 0` guard conflated "before any hunk header" with
"hunk starting at +1", silently dropping all lines from top-of-file
hunks. Replaced with an `insideHunk` boolean flag. Extracted the
function to shared/lib/extract-hunk.ts for testability.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@selfcontained selfcontained merged commit 5c97586 into main Jul 14, 2026
1 check passed
@selfcontained selfcontained deleted the agt_cc697f2f1a15/job-test-enforcer-2b126694 branch July 14, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant