This commit is contained in:
nuno maduro
2026-04-14 09:29:41 -07:00
parent cb5f6e1bd2
commit 7cbb1fcdb2
2 changed files with 17 additions and 4 deletions

View File

@ -50,6 +50,11 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
*/ */
private static bool $timeBalanced = false; private static bool $timeBalanced = false;
/**
* Whether the shards.json file is outdated.
*/
private static bool $shardsOutdated = false;
/** /**
* Collected timings from workers or subscribers. * Collected timings from workers or subscribers.
* *
@ -110,15 +115,18 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
$timings = $this->loadShardsFile(); $timings = $this->loadShardsFile();
if ($timings !== null) { if ($timings !== null) {
$missingTests = array_diff($tests, array_keys($timings)); $knownTests = array_values(array_filter($tests, fn (string $test): bool => isset($timings[$test])));
$newTests = array_values(array_diff($tests, $knownTests));
if ($missingTests !== []) { $partitions = $this->partitionByTime($knownTests, $timings, $total);
throw new InvalidOption('The [tests/.pest/shards.json] file is out of date. Run [--update-shards] to update it.');
foreach ($newTests as $i => $test) {
$partitions[$i % $total][] = $test;
} }
$partitions = $this->partitionByTime($tests, $timings, $total);
$testsToRun = $partitions[$index - 1] ?? []; $testsToRun = $partitions[$index - 1] ?? [];
self::$timeBalanced = true; self::$timeBalanced = true;
self::$shardsOutdated = $newTests !== [];
} else { } else {
$testsToRun = (array_chunk($tests, max(1, (int) ceil(count($tests) / $total))))[$index - 1] ?? []; $testsToRun = (array_chunk($tests, max(1, (int) ceil(count($tests) / $total))))[$index - 1] ?? [];
} }
@ -250,6 +258,10 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
$suffix, $suffix,
)); ));
if (self::$shardsOutdated) {
$this->output->writeln(' <fg=yellow;options=bold>WARN</> <fg=default>The [tests/.pest/shards.json] file is out of date. Run [--update-shards] to update it.</>');
}
return $exitCode; return $exitCode;
} }

View File

@ -19,6 +19,7 @@ arch()->preset()->security()->ignoring([
'exec', 'exec',
'md5', 'md5',
'unserialize', 'unserialize',
'uniqid',
'extract', 'extract',
'assert', 'assert',
]); ]);