Skip to content

fix: Tia coverage cache recorded on another machine empties the merged report and passes --min - #1798

Open
AlessioGiacobbe wants to merge 1 commit into
pestphp:5.xfrom
AlessioGiacobbe:fix/tia-coverage-cache-foreign-paths
Open

fix: Tia coverage cache recorded on another machine empties the merged report and passes --min#1798
AlessioGiacobbe wants to merge 1 commit into
pestphp:5.xfrom
AlessioGiacobbe:fix/tia-coverage-cache-foreign-paths

Conversation

@AlessioGiacobbe

Copy link
Copy Markdown

Fixes #1796.

The bug

A TIA baseline recorded on one machine (e.g. GitHub Actions) ships its coverage cache with the recording machine's absolute paths serialized inside. When another machine downloads it via pest()->tia()->baselined() and runs --tia --coverage, CoverageMerger merges that cache with the local run's coverage, producing a data set with two disjoint path roots. php-code-coverage's report builder silently skips every file whose reconstructed path fails is_file(), so the final report has zero file nodes: Pest prints an empty per-file table with a bogus Total: 100.0 %, and --coverage --min=X passes regardless of the real coverage — the check fails open with no warning.

The fix

Make the cache path-portable and refuse to merge what cannot be mapped:

  • Write side (serializeRelativeToProjectRoot()): the cache now stores file paths relative to the project root (canonical / separators), so a baseline recorded on CI stays meaningful on any machine that downloads it.
  • Read side (readCache() / rebaseOntoProjectRoot()): relative entries are mapped onto the local project root before the strip + merge. Absolute entries under the local root are kept, preserving caches written by previous versions on the same machine. Absolute entries of another machine make the cache unusable — it is discarded and the current run seeds a fresh (portable) one, so the printed report falls back to correct current-run data instead of an empty table that satisfies --min.
  • An unreadable cache (gzip or unserialize failure) now also reseeds from the current run; previously it was deleted and the run produced no cache at all.

Tests

tests/Unit/Plugins/Tia/CoverageMergerPortability.php (new):

  • a cache recorded under another root is discarded, the marker is consumed, and the current run becomes a relative-path cache (fails on 5.x by keeping the foreign-path merge);
  • relative cached entries are rebased onto the local root before merging, and the rewritten cache is relative again;
  • a same-machine cache with absolute paths still merges (back-compat).

Note: this touches the same applyIfMarked() flow as #1792 — the two fixes are independent but will conflict textually; happy to rebase whichever lands second.

🤖 Generated with Claude Code

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.

Tia: coverage cache downloaded from another machine empties the coverage report — no per-file rows, bogus Total: 100.0%, --min passes

1 participant