Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function parseAddedLines(patch) {
for (const row of patch.split('\n')) {
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.

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)

continue
}
if (row.startsWith('+++') || row.startsWith('---')) continue // defensive: file headers
Expand Down
Loading