Skip to content

fix(patch): skip zero-hit comment lines in patch coverage#80

Open
betegon wants to merge 3 commits into
mainfrom
fix/patch-skip-zero-hit-comment-lines
Open

fix(patch): skip zero-hit comment lines in patch coverage#80
betegon wants to merge 3 commits into
mainfrom
fix/patch-skip-zero-hit-comment-lines

Conversation

@betegon
Copy link
Copy Markdown
Member

@betegon betegon commented May 13, 2026

Problem

When a coverage tool emits DA:x,0 entries for comment-only lines (JSDoc * ..., //, /*, #) — which happens with bun under --isolate --parallel due to TypeScript source-map artifacts — the action counts those lines as missed coverage. Lines with no DA entry at all are correctly ignored; the gap was zero-hit DA entries for non-executable lines.

Concrete example from getsentry/cli#960: bun's LCOV includes DA:18,0DA:24,0 for 7 JSDoc continuation lines that appear as + lines in the patch diff. The action counted all 7 as missing, pulling patch coverage from ~100% to 65% and failing the coverage gate.

bun's CodeCoverage.zig documents that comments should be excluded from coverage (lines 11–12), but under certain V8/source-map conditions this doesn't hold. The fix belongs here too — we should be defensive against any tool that emits zero-hit DA entries for comment lines.

Solution

Added isCommentOrBlankLine(diffLine) in patch-analyzer.ts. When a diff-added line has a DA entry with count === 0, we strip the + prefix and check whether the content is a comment (//, /*, *, #) or blank. If so, it's skipped — comments are never executable, so a zero-hit DA entry for them is always a false positive.

Lines absent from LCOV entirely are still ignored as before. This only affects lines that are both in the LCOV (with count=0) and contain only comment/whitespace content.

One new test covers the exact failure mode: DA:x,0 entries for JSDoc * lines, /**, */, //, and # lines alongside a real covered line. The real line counts; the comment lines don't.

Coverage tools (notably bun under --isolate --parallel) sometimes emit
DA:x,0 LCOV entries for JSDoc continuation lines and other comment-only
lines as a source-map artifact. The action was faithfully counting those
as "missing coverage", dragging patch percentages down incorrectly.

The fix: when a diff-added line has a DA entry with count=0, check whether
the line content is purely a comment (//…, /*…, * …, #…) or blank. If so,
skip it — comments are never executable and a zero-hit DA entry for them is
always a false positive.

Lines absent from the LCOV entirely were already ignored; this closes the
gap for zero-hit comment DA entries that some tools emit.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

Codecov Results 📊

197 passed | Total: 197 | Pass Rate: 100% | Execution Time: 287ms

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +3
Passed Tests 📈 +3
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 759 uncovered lines.
✅ Project coverage is 56.91%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    56.82%    56.91%    +0.09%
==========================================
  Files           24        24         —
  Lines         1753      1756        +3
  Branches      1257      1264        +7
==========================================
+ Hits           994       997        +3
- Misses         759       759         —
- Partials        97        97         —

Generated by Codecov Action

@betegon betegon marked this pull request as ready for review May 13, 2026 15:51
Comment thread src/analyzers/patch-analyzer.ts Outdated
startsWith("#") incorrectly treated private class members (#myField,
#_backing) as comments, causing their zero-hit DA entries to be skipped
instead of counted as missed coverage.

Replace with /^#(?!\w)/u — # is only a comment marker when NOT followed
by a word character. Shell/Python comments and shebangs (#!, # text) are
still detected; private fields (#field, #_count) are now correctly
treated as executable code.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Comment thread src/analyzers/patch-analyzer.ts Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 22652df. Configure here.

Comment thread src/analyzers/patch-analyzer.ts Outdated
startsWith("*") matched generator method declarations (*myGenerator,
*[Symbol.iterator]) in addition to JSDoc continuation lines, causing
those uncovered methods to be silently skipped instead of counted as
missed coverage.

Confirmed by actual bun LCOV output: an uncalled *range(n: number)
method produces DA:4,0 (bun's "unexecuted function range fill" writes
DA:x,0 for the entire function range). With startsWith("*"), that line
was classified as a comment and excluded from patch coverage.

Fix mirrors the earlier # fix: /^\*(?![a-zA-Z_$\[])/ treats * as a
comment marker only when NOT followed by an identifier-start char or [.
JSDoc * text and */ are still caught; *myGen and *[Symbol] are not.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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