From 0224b4238b617ebc00a9b6651f3a1e7b1c770d01 Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Tue, 3 Nov 2026 18:09:26 +0500 Subject: [PATCH] fix(tia): drop the results of every branch on environment drift (#2011) Co-authored-by: Punyapal Shah --- src/Plugins/Tia.php | 2 +- src/Plugins/Tia/Graph.php | 7 ++++--- tests/.snapshots/success.txt | 3 ++- tests/Unit/Plugins/Tia/Graph.php | 14 ++++++++++++++ tests/Visual/Parallel.php | 2 +- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Plugins/Tia.php b/src/Plugins/Tia.php index c107c115..d26866dd 100644 --- a/src/Plugins/Tia.php +++ b/src/Plugins/Tia.php @@ -835,7 +835,7 @@ final class Tia implements AddsOutput, HandlesArguments, HandlesOriginalArgument implode(', ', $drift), )); - $graph->clearResults($this->branch); + $graph->clearResults(); $graph->setFingerprint($current); $this->saveGraph($graph); $this->deleteState(self::KEY_COVERAGE_CACHE); diff --git a/src/Plugins/Tia/Graph.php b/src/Plugins/Tia/Graph.php index 09051268..3854a45a 100644 --- a/src/Plugins/Tia/Graph.php +++ b/src/Plugins/Tia/Graph.php @@ -943,10 +943,11 @@ final class Graph $this->baselines[$branch]['tree'] = $tree; } - public function clearResults(string $branch): void + public function clearResults(): void { - $this->ensureBaseline($branch); - $this->baselines[$branch]['results'] = []; + foreach (array_keys($this->baselines) as $branch) { + $this->baselines[$branch]['results'] = []; + } } /** diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index cbace89f..4d5ef140 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1943,6 +1943,7 @@ ✓ markKnownTestFiles() → it makes a test file with no edges known ✓ markKnownTestFiles() → it does not clobber edges of an already-known test file ✓ markKnownTestFiles() → it ignores paths outside the project root + ✓ clearResults() → it drops the results of the fallback branch too PASS Tests\Unit\Plugins\Tia\IsEnabledForRun ✓ does not throw when an integer --random-order-seed is passed as a separate argv element @@ -2293,4 +2294,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 36 skipped, 1625 passed (3589 assertions) + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 36 skipped, 1626 passed (3592 assertions) diff --git a/tests/Unit/Plugins/Tia/Graph.php b/tests/Unit/Plugins/Tia/Graph.php index 19ea5ca0..6d7d45be 100644 --- a/tests/Unit/Plugins/Tia/Graph.php +++ b/tests/Unit/Plugins/Tia/Graph.php @@ -312,3 +312,17 @@ describe('markKnownTestFiles()', function (): void { expect($graph->knowsTest('/somewhere/else/tests/FooTest.php'))->toBeFalse(); }); }); + +describe('clearResults()', function (): void { + it('drops the results of the fallback branch too', function (): void { + $graph = new Graph(sys_get_temp_dir()); + $graph->setResult('main', 'Tests\FooTest::it passes', 0, '', 0.1, 1); + $graph->setResult('feature', 'Tests\BarTest::it passes', 0, '', 0.1, 1); + + $graph->clearResults(); + + expect($graph->getResult('feature', 'Tests\FooTest::it passes'))->toBeNull() + ->and($graph->getResult('feature', 'Tests\BarTest::it passes'))->toBeNull() + ->and($graph->getResult('main', 'Tests\FooTest::it passes'))->toBeNull(); + }); +}); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index c4a6e5dd..e53c756e 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -20,7 +20,7 @@ test('parallel', function () use ($run): void { $output = $run('--exclude-group=integration'); $output = implode("\n", array_slice(explode("\n", (string) $output), -10)); - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 28 skipped, 1606 passed (3531 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 28 skipped, 1607 passed (3534 assertions)'; expect($output) ->toContain("Tests: {$expected}")