Commit 8c98cb5
feat: implement partials_as_hits feature for LCOV parser (#383)
* feat: implement partials_as_hits feature for LCOV parser
This commit adds support for the partials_as_hits configuration option to the LCOV parser,
bringing it in line with other coverage parsers (JaCoCo, Cobertura, Go).
## Changes Made
### Core Implementation
- **lcov.py**: Added partials_as_hits configuration reading and conversion logic
- **_process_file()**: Updated to accept partials_as_hits parameter
- **Branch processing**: Convert partial coverage (e.g., '1/2') to hits (1) when enabled
### Configuration Schema
- **user_schema.py**: Added LCOV parser configuration validation
- Supports: parsers.lcov.partials_as_hits (boolean, default: false)
### Test Coverage
- **test_lcov.py**: Added comprehensive test cases:
- test_lcov_partials_as_hits_enabled(): Tests conversion of partials to hits
- test_lcov_partials_as_hits_disabled(): Tests default behavior preservation
- test_lcov_partials_as_hits_mixed_coverage(): Tests mixed scenarios
- **test_validation.py**: Added schema validation tests
### Documentation
- **LCOV_PARTIALS_AS_HITS.md**: Comprehensive feature documentation including:
- Implementation details and logic
- Usage examples and migration guide
- Consistency with other parsers
- Test coverage overview
## Behavior
### With partials_as_hits: true
- '1/2' partial coverage → 1 (hit)
- '2/3' partial coverage → 1 (hit)
- '2/2' full hit → '2/2' (unchanged)
- '0/2' miss → '0/2' (unchanged)
### With partials_as_hits: false (default)
- All coverage types remain unchanged (backward compatible)
## Configuration Example
## Implementation Details
- Follows established patterns from JaCoCo, Cobertura, and Go parsers
- Minimal performance impact (single boolean check per branch line)
- Comprehensive test coverage with realistic LCOV data
- Backward compatible (defaults to false)
Closes: #[issue-number] (if applicable)
Co-authored-by: TDD Implementation Process
* fix: preserve branch coverage type in LCOV partials_as_hits
Critical bug fix addressing incorrect branch counting when partials_as_hits is enabled.
## Problem
When partials_as_hits was enabled, partial branches were converted from:
- coverage: '1/2' -> 1 ✅ (correct)
- coverage_type: CoverageType.branch -> CoverageType.line ❌ (incorrect)
This caused get_line_totals() to exclude converted partials from branch counts
since it only counts lines with type='b' (CoverageType.branch maps to 'b').
## Solution
- Keep coverage_type as CoverageType.branch for converted partials
- This maintains proper branch counting: line.type = 'b'
- Aligns behavior with JaCoCo parser (preserves branch type)
- Ensures accurate branch coverage metrics
## Changes
- lcov.py: Remove incorrect coverage_type change to CoverageType.line
- test_lcov.py: Update test expectations to expect 'b' type for converted partials
- LCOV_PARTIALS_AS_HITS.md: Correct documentation
## Verification
- Converted partials now maintain branch type for proper counting
- Tests updated to reflect correct behavior
- Branch coverage metrics will be accurate
Fixes: Branch count inconsistency when partials_as_hits enabled
Severity: Critical - affects coverage metrics accuracy
* style: apply ruff formatting to test_lcov.py
Auto-formatting applied by pre-commit hooks to match project style guidelines.
The tuple formatting was changed to multi-line format for better readability.
* fix: correct LCOV partials_as_hits test expectations
The original tests incorrectly expected both line coverage AND branch coverage
to exist as separate entries when both DA: and BRDA: exist for the same line.
LCOV parser behavior (confirmed by existing test_regression_partial_branch):
- When both DA:10,5 and BRDA:10,0,0,1 exist for line 10
- Branch coverage overwrites line coverage
- Result: Only one entry (10, '1/2', 'b', ...) not two separate entries
Fixed test expectations to match actual LCOV parser behavior:
- test_lcov_partials_as_hits_enabled: Expect only branch entry with hit conversion
- test_lcov_partials_as_hits_disabled: Expect only branch entry with partial preserved
- test_lcov_partials_as_hits_mixed_coverage: Expect only branch entries
This aligns with how the existing LCOV parser works and maintains backward compatibility.
* style: apply ruff formatting to LCOV tests
Auto-formatting applied by pre-commit hooks:
- Remove trailing whitespace after triple quotes
- Multi-line format for long tuple in test_lcov_partials_as_hits_mixed_coverage
This prevents CI formatting loops by applying the formatting locally.
* fix: add boolean type casting for LCOV partials_as_hits config
- Fix issue where string 'false' would be truthy in YAML config
- Add robust boolean casting to handle 'false', 'true', '0', '1', etc.
- Add test to verify string 'false' correctly behaves as boolean False
- Refactor tests to eliminate duplication using class properties
- Move repeated LCOV test data to PARTIAL_BRANCH_LCOV_DATA class property
- Add reusable partial_test_path_fixer static method
This prevents configuration bugs where users specify boolean values as
strings in YAML, ensuring partials_as_hits works correctly regardless
of how the boolean is specified in the configuration.
* Empty commit to trigger CI
* Add .cursor to .gitignore
* Empty commit to trigger CI - investigating flaky test
* Delete LCOV_PARTIALS_AS_HITS.md
* Update action-enforce-license-compliance version
* Delete .gitignore
* restore .gitignore
---------
Co-authored-by: Joe Becher <[email protected]>1 parent 2a2ca6e commit 8c98cb5
File tree
4 files changed
+161
-2
lines changed- apps/worker/services/report/languages
- tests/unit
4 files changed
+161
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
28 | 39 | | |
29 | 40 | | |
30 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
31 | 44 | | |
32 | 45 | | |
33 | 46 | | |
34 | 47 | | |
35 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
36 | 51 | | |
37 | 52 | | |
38 | 53 | | |
| |||
175 | 190 | | |
176 | 191 | | |
177 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
178 | 200 | | |
179 | 201 | | |
180 | 202 | | |
| |||
Lines changed: 121 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
122 | 136 | | |
123 | 137 | | |
124 | 138 | | |
| |||
208 | 222 | | |
209 | 223 | | |
210 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
516 | 516 | | |
517 | 517 | | |
518 | 518 | | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
519 | 523 | | |
520 | 524 | | |
521 | 525 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
890 | 890 | | |
891 | 891 | | |
892 | 892 | | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
893 | 905 | | |
894 | 906 | | |
895 | 907 | | |
| |||
0 commit comments