feat: let a shard unit bundle several test classes - #1829
Open
maks-oleksyuk wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--shardsplits test classes and weighs each one on its own. That holds while a test class is the whole unit of work, but not when the work a shard has to do spans several of them: splitting those classes across shards duplicates the work and leaves every shard with a partial result.Mutation testing is the case that needs this. A mutation belongs to a source file, several test classes can cover that file, so the file is the unit and its covering test classes have to travel together. Related to #1691.
What changed
Shard::useTimings()accepts a richer value. Instead of a duration per test class, a unit may be['time' => float, 'tests' => list<string>]under any key. A bare float still means a test class bundling only itself, so an existingshards.jsonand the behaviour of a plain--update-shardsrun are unchanged.LPT partitioning now runs over units, and the
--filtera shard receives is the union of the test classes its units bundle.Shard::selectedUnits()exposes the keys allocated to the current shard, so a plugin can narrow the work it generates to match.Shard::useTimings()also takes optional metadata, stored next to the units and read back throughShard::metadata(). That lets a plugin carry a reference value from the unsharded run that produces the file into the sharded runs that consume it.Three smaller fixes ride along. The timings file is written when a plugin supplied the units and the run exits non-zero, so a job whose only purpose is to record timings is not lost to an unrelated failure. The count reported by
--update-shardsnow matches the number of entries actually written. The--list-testssubprocess no longer inherits--coveragearguments.Testing
tests/Unit/Plugins/Shard.phpcovers unit normalisation, partitioning that keeps a bundle intact, both file shapes on read and write, precedence of plugin-supplied units, and the zero entries written for test classes that produced no work of their own.Follow-ups
The plugin side that consumes this API lands in pestphp/pest-plugin-mutate#40, with the timeout it depends on in pestphp/pest-plugin-mutate#41. Together with #40 this closes the request in #1691.