Skip to content

test(demo): off-by-one in parseAddedLines, breaks 2 tests - #1

Closed
DorianZheng wants to merge 1 commit into
mainfrom
demo-agent-runs-tests
Closed

DorianZheng wants to merge 1 commit into
mainfrom
demo-agent-runs-tests

Conversation

@DorianZheng

@DorianZheng DorianZheng commented Jul 8, 2026 •

Copy link
Copy Markdown
Member

Demo: reviewer runs the test suite in a BoxLite microVM.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed inline review comments so they now attach to the correct added lines in diffs.
    • Improved comment placement accuracy when reviewing changes, reducing missed or misaligned annotations.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A one-line fix in parseAddedLines removes an off-by-one shift when computing the starting line number from unified-diff hunk headers, correcting which added lines are eligible for inline review comment anchoring.

Changes

Added-line calculation fix

Layer / File(s) Summary
Fix newLine offset in parseAddedLines
lib/publish.mjs
Removes an incorrect + 1 shift when extracting the starting newLine value from hunk headers, aligning added-line numbers with the diff's RIGHT-side numbering.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the off-by-one fix in parseAddedLines, which is the main change in the patch.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch demo-agent-runs-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/publish.mjs`:
- Line 21: Remove the off-by-one offset in the hunk parsing logic: `publish.mjs`
currently initializes `newLine` from `hunk[1]` and then adds 1, which shifts
every added line number incorrectly. Update the line-number tracking in the
patch parsing flow so added lines use the hunk header’s right-side start
directly, and verify the downstream `partition()` mapping still matches findings
against `lines.has(f.line)` in `publish.test.mjs` expectations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b773e547-d38f-4df5-92d7-3aeadf84e5b8

📥 Commits

Reviewing files that changed from the base of the PR and between ece0a95 and 129a9e1.

📒 Files selected for processing (1)
  • lib/publish.mjs

Comment thread lib/publish.mjs
const hunk = row.match(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/)
if (hunk) {
newLine = Number.parseInt(hunk[1], 10)
newLine = Number.parseInt(hunk[1], 10) + 1 // BUG: shifts every added line by one

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

The + 1 introduces an off-by-one error that breaks added-line numbering.

The hunk header's newStart (captured in hunk[1]) is already the correct RIGHT-side starting line number. Adding + 1 shifts every subsequent added line up by one. Tracing the test patch @@ -1,3 +1,4 @@:

  • With + 1: newLine starts at 2, context advances to 3, so +added-a→3, +added-b→4 → result {3,4} ≠ expected {2,3}.
  • Without + 1: newLine starts at 1, context advances to 2, so +added-a→2, +added-b→3 → result {2,3} ✓

This breaks the unit test in test/publish.test.mjs and causes partition() (line 62) to anchor inline comments to wrong lines, since lines.has(f.line) will mismatch findings against shifted line numbers.

🐛 Proposed fix: remove the off-by-one offset
-      newLine = Number.parseInt(hunk[1], 10) + 1 // BUG: shifts every added line by one
+      newLine = Number.parseInt(hunk[1], 10)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
newLine = Number.parseInt(hunk[1], 10) + 1 // BUG: shifts every added line by one
newLine = Number.parseInt(hunk[1], 10)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/publish.mjs` at line 21, Remove the off-by-one offset in the hunk parsing
logic: `publish.mjs` currently initializes `newLine` from `hunk[1]` and then
adds 1, which shifts every added line number incorrectly. Update the line-number
tracking in the patch parsing flow so added lines use the hunk header’s
right-side start directly, and verify the downstream `partition()` mapping still
matches findings against `lines.has(f.line)` in `publish.test.mjs` expectations.

@DorianZheng DorianZheng left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📦 BoxLite review — 1 issue

Comment thread lib/publish.mjs
const hunk = row.match(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/)
if (hunk) {
newLine = Number.parseInt(hunk[1], 10)
newLine = Number.parseInt(hunk[1], 10) + 1 // BUG: shifts every added line by one

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Off-by-one shifts every added line number
parseAddedLines(PATCH) returns {3,4} instead of {2,3}; ran node --test test/publish.test.mjs → 2/8 fail, causing inline comments to map to wrong lines or hit GitHub's 422 diff-line rejection.

Suggested change
newLine = Number.parseInt(hunk[1], 10) + 1 // BUG: shifts every added line by one
newLine = Number.parseInt(hunk[1], 10)

@DorianZheng

Copy link
Copy Markdown
Member Author

📦 BoxLite review — 1 issue · 129a9e1

lib/publish.mjs
  parseAddedLines  +1/-1  hunk start line off by one

reviewed 129a9e1 in a BoxLite microVM · @boxlite review to re-run · powered by BoxLite

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