Skip to content

Feat: coverage in shards#1686

Open
MrPunyapal wants to merge 17 commits into
pestphp:4.xfrom
MrPunyapal:feat/coverage-in-sharding
Open

Feat: coverage in shards#1686
MrPunyapal wants to merge 17 commits into
pestphp:4.xfrom
MrPunyapal:feat/coverage-in-sharding

Conversation

@MrPunyapal
Copy link
Copy Markdown
Contributor

@MrPunyapal MrPunyapal commented Apr 23, 2026

What:

  • Bug Fix
  • New Feature

Description:

This PR adds first-class coverage support for sharded Pest runs and fixes the CI/composer setup required to run that flow reliably.

It solves two concrete problems:

  • --coverage and --shard=X/Y did not provide a built-in way to collect coverage from each shard and merge it into one final report.
  • CI dependency resolution could be inconsistent in detached HEAD environments when resolving the root package together with dev dependencies such as pestphp/pest-plugin-browser.

What changed:

  • pest --shard=X/Y --coverage now stores coverage as .cov files under .pest/coverage/ instead of trying to render a report per shard.
  • pest --shards-coverage now merges all shard coverage files and prints one combined coverage report.
  • --shards-coverage supports the existing coverage thresholds via --min and --exactly, supports --only-covered, and can clean up temporary coverage files with --clean.
  • During sharded coverage runs, output-style coverage report flags are stripped and Pest shows a follow-up command to run after all shards finish.
  • Help output and coverage tests were updated to document and verify the new flow.
  • CI now sets COMPOSER_ROOT_VERSION=4.x-dev and uses the supported Symfony floors (7.4.8 and 8.0.8) so dependency resolution stays stable across the matrix.

How To Use Locally:

Run each shard with coverage enabled:

pest --shard=1/2 --coverage
pest --shard=2/2 --coverage

Merge the generated shard coverage files into one final report:

pest --shards-coverage

Useful local variants:

pest --shard=1/3 --coverage
pest --shard=2/3 --coverage
pest --shard=3/3 --coverage

pest --shards-coverage --min=80
pest --shards-coverage --exactly=91.5
pest --shards-coverage --only-covered
pest --shards-coverage --clean

Notes:

  • Shard coverage files are written to .pest/coverage/{shard}.cov.
  • --clean removes the temporary .cov files after the merged report is generated.
  • If a sharded run receives output-oriented coverage flags, Pest warns and points you to the merge step instead.

How To Use In CI:

  1. Run each shard in a parallel job and upload .pest/coverage/ as an artifact.
  2. In a follow-up job, download all shard artifacts then run the merge.
# shard jobs (run in parallel, e.g. strategy matrix)
- run: php bin/pest --shard=${{ matrix.shard }}/3 --coverage
- uses: actions/upload-artifact@v4
  with:
    name: coverage-shard-${{ matrix.shard }}
    path: .pest/coverage/

# merge job (depends on all shard jobs)
- uses: actions/download-artifact@v4
  with:
    pattern: coverage-shard-*
    merge-multiple: true
    path: .pest/coverage/
- run: pest --shards-coverage --min=80 --clean
20260424-1834-59.9415647.mp4

@MrPunyapal MrPunyapal marked this pull request as ready for review April 24, 2026 18:46
@MrPunyapal MrPunyapal force-pushed the feat/coverage-in-sharding branch from 3546319 to 0d7ce47 Compare May 4, 2026 09:47
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