From f4bd34d21358f39e96408212a46a04c32b548a44 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 10:03:08 +0000 Subject: [PATCH 1/2] test: make CacheWarmerTest::testFailFastStopsAfterFirstError order independent In-process warm-up walks the files in the order the file system lists them, which is not sorted. With the valid src/Some.php from setUp() next to the two broken files, a listing that put Some.php first made the warmer process it, fail on the next file and stop: "Total processed 2" instead of 1. That is what failed the coverage job in goaop/framework#788. The test now removes the valid file, so only the two broken files remain and the warmer processes exactly one of them, whichever is listed first. It also asserts that only one file failed, i.e. the second broken file was skipped. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FxhC1F17fBJcmZzT44WKzi --- tests/Instrument/ClassLoading/CacheWarmerTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Instrument/ClassLoading/CacheWarmerTest.php b/tests/Instrument/ClassLoading/CacheWarmerTest.php index b5b4328d..c2a103c0 100644 --- a/tests/Instrument/ClassLoading/CacheWarmerTest.php +++ b/tests/Instrument/ClassLoading/CacheWarmerTest.php @@ -424,7 +424,9 @@ public function testWarmUpReportsErrorsToErrorOutputAndReturnsTheirCount(): void public function testFailFastStopsAfterFirstError(): void { - // Two broken files: whichever comes first, the warmer stops before the second one + // Only two broken files: the file system lists them in any order, and a valid file listed before them would + // be processed too. Whichever broken file comes first, the warmer stops before the second one + unlink($this->sourceFile); file_put_contents($this->appDir . '/src/Broken.php', "appDir . '/src/AlsoBroken.php', "assertSame(1, $warmer->warmUp()); $display = $output->fetch(); $this->assertStringContainsString('[STOP]: Warmup was interrupted, stopping...', $display); + $this->assertSame(1, substr_count($display, 'Cannot weave file'), 'The second broken file is not processed'); $this->assertStringContainsString('Total processed 1, 1 errors in ', $display); } } From 8653fb97a1afabcf0e3c8a3bf8db8f4c768dd597 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 10:26:08 +0000 Subject: [PATCH 2/2] fix(warmup): weave the enumerated files in path order The file system lists a directory in any order, which differs between machines, so in-process warm-up wove the files in a different order on each CI runner. With fail-fast it then stopped on a different file: CacheWarmerTest::testFailFastStopsAfterFirstError reported "Total processed 2" whenever the valid Some.php was listed before the broken files. The warmer now sorts the collected files by path, so every run weaves them in the same order and fail-fast stops on the same file. The worker pool keeps ordering by size; its sort is stable, so files of the same size stay in path order. The test keeps all three files (the previous commit removed the valid one) and asserts which file stopped the warm-up. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FxhC1F17fBJcmZzT44WKzi --- src/Instrument/ClassLoading/CacheWarmer.php | 6 +++++- tests/Instrument/ClassLoading/CacheWarmerTest.php | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Instrument/ClassLoading/CacheWarmer.php b/src/Instrument/ClassLoading/CacheWarmer.php index eff2d79f..fe1450ba 100644 --- a/src/Instrument/ClassLoading/CacheWarmer.php +++ b/src/Instrument/ClassLoading/CacheWarmer.php @@ -110,6 +110,9 @@ private function weaveApplication(): int // One walk of the application tree: the collected list is counted and then processed $enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); $files = iterator_to_array($enumerator->enumerate(), false); + // In path order: the file system lists a directory in any order, which differs between machines. + // Sorted, every run weaves the files in the same order, and with fail-fast stops on the same file + usort($files, static fn(SplFileInfo $left, SplFileInfo $right): int => strcmp($left->getPathname(), $right->getPathname())); // No more workers than files; without a command line to start them, the files are woven here $workers = $this->workerCommandLine !== [] ? max(1, min($this->workers, count($files))) : 1; @@ -174,7 +177,8 @@ private function warmUpInWorkers(array $files, int $workers, WarmupReporter $rep // Loads every aspect once, which writes their advisor caches before the workers need them $container->getService(AdvisorIndex::class)->getAdvisors(); - // Largest files first: they take longest, and the small ones left for the end even out the workers + // Largest files first: they take longest, and the small ones left for the end even out the workers. + // The sort is stable: files of the same size stay in path order usort($files, static fn(SplFileInfo $left, SplFileInfo $right): int => $right->getSize() <=> $left->getSize()); $paths = array_map(self::pathOf(...), $files); diff --git a/tests/Instrument/ClassLoading/CacheWarmerTest.php b/tests/Instrument/ClassLoading/CacheWarmerTest.php index c2a103c0..57ca610d 100644 --- a/tests/Instrument/ClassLoading/CacheWarmerTest.php +++ b/tests/Instrument/ClassLoading/CacheWarmerTest.php @@ -424,9 +424,8 @@ public function testWarmUpReportsErrorsToErrorOutputAndReturnsTheirCount(): void public function testFailFastStopsAfterFirstError(): void { - // Only two broken files: the file system lists them in any order, and a valid file listed before them would - // be processed too. Whichever broken file comes first, the warmer stops before the second one - unlink($this->sourceFile); + // Next to the valid Some.php from setUp(), two broken files. Files are woven in path order, whatever order + // the file system lists them in: AlsoBroken.php fails first, and the warmer stops before the other two file_put_contents($this->appDir . '/src/Broken.php', "appDir . '/src/AlsoBroken.php', "assertSame(1, $warmer->warmUp()); $display = $output->fetch(); $this->assertStringContainsString('[STOP]: Warmup was interrupted, stopping...', $display); - $this->assertSame(1, substr_count($display, 'Cannot weave file'), 'The second broken file is not processed'); + $this->assertStringContainsString('AlsoBroken.php: Cannot weave file', $display); + $this->assertDoesNotMatchRegularExpression('#[/\\\\]Broken\.php: Cannot weave#', $display); $this->assertStringContainsString('Total processed 1, 1 errors in ', $display); } }