Skip to content

fix(normalizer): detect the container prefix from clover path= - #8

Merged
Ostico merged 2 commits into
mainfrom
fix/jest-clover-container-path
Oct 20, 2026
Merged

Ostico merged 2 commits into
mainfrom
fix/jest-clover-container-path

Conversation

@Ostico

@Ostico Ostico commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Problem

Layer 1 passes every changed JS file of a Jest coverage report produced inside a container with pass — in coverage report, but no executable lines changed, even when the diff changes executable lines. Observed on MateCat PR #4927 (run 39423022273): 4 changed JS files, 18 changed executable lines, all passed.

Jest's clover reporter writes the basename in name= and the absolute path in path=. _extract_clover_paths() read name or path, so detect_path_prefix() never saw an absolute path, nothing was stripped, diff-cover read path= (/var/www/...), could not match it, and the file fell into unmeasurable_absent.

Changes

  • _extract_clover_paths() returns, per <file>, whichever of name= / path= is absolute (name= first, then path=, else name or path as before). PHPUnit behaviour is unchanged.
  • New find_suffix_only_match(); is_in_report() reuses it with identical behaviour.
  • Layer 1 emits ::warning::Coverage path mismatch when a changed file is in a Clover report only under a longer or shorter path. diff-cover matches Clover paths exactly (violations_reporter.py), so such a file was never measured. The verdict is unchanged; paths under the checkout are exempt; JaCoCo is excluded (its paths are legitimately shorter).
  • README: Clover normalization row and the path-mismatch note. .gitignore: .code-review-graph/.

Verification

  • pytest: 466 passed (455 before, 11 new). The new normalizer and Layer 1 tests fail on main.
  • Real report from the PR #4927 CI run (717 files, 4 changed): prints stripped prefix '/var/www/matecat/'; all 717 path= become relative; the 4 changed files are found with their executable lines. The 4-file reduction is committed as tests/fixtures/jest_clover_container_paths.xml.
  • ruff check is clean on the touched files. main already has 7 ruff check findings (all in benchmarks/) and 16 files that ruff format --check would reformat; this PR does not add to them.

Release note for consumers

Consumers that run Jest in a container start being measured on JS after this ships. PRs with untested JS lines, which used to pass, will fail Layer 1. That is the intended behaviour; announce it with the release.

Not in this PR

Failing (instead of warning) a file that the report lists with executable lines on changed lines needs the per-file diff in Layer 1, a hunk parser and a per-format executable-line extractor. Deferred until a second mismatch is observed in practice.

Jest's clover reporter writes a basename in name= and the container path in
path=, so prefix detection saw no absolute path and left the report untouched.
Pick whichever attribute is absolute, name= first.
…hanged file

diff-cover matches Clover paths exactly, so a file the report mentions under a
longer or shorter path (a second container root, a path relative to a
subdirectory) is never measured, yet it passed as "no executable lines
changed". Emit a path-mismatch warning for that case; the verdict is unchanged.
Paths under the checkout resolve in diff-cover and are exempt, JaCoCo keeps its
shorter paths.

Document the Jest path= handling and the warning, and ignore the local code
graph directory.
@github-actions

Copy link
Copy Markdown

🧪 Test-Guard Report

✅ PASS — All changed source files have adequate test coverage.

Coverage Analysis: ✅ PASS

Changed lines: 100.0% covered (threshold: 100%)

📋 2 files: 2 ✅ pass
File Verdict Reason
src/coverage_normalizer.py ✅ pass 100% diff coverage ≥ 100% threshold
src/layer1_coverage.py ✅ pass 100% diff coverage ≥ 100% threshold

Result: ✅ PASS

@Ostico
Ostico merged commit a4d06d6 into main Oct 20, 2026
3 checks passed
@Ostico
Ostico deleted the fix/jest-clover-container-path branch October 20, 2026 14:19
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