diff --git a/src/Plugins/Tia/Graph.php b/src/Plugins/Tia/Graph.php index 3854a45a..51ff1c02 100644 --- a/src/Plugins/Tia/Graph.php +++ b/src/Plugins/Tia/Graph.php @@ -62,6 +62,11 @@ final class Graph private string $fallbackBranch = 'main'; + /** + * @var array, complete?: bool, results: array}, 1: array{sha: ?string, tree: array, complete?: bool, results: array}, 2: array{sha: ?string, tree: array, complete?: bool, results: array}}> + */ + private array $mergedBaselines = []; + private readonly string $projectRoot; /** @var array|null */ @@ -976,15 +981,26 @@ final class Graph return $own; } + $key = $branch."\0".$fallbackBranch; + $memo = $this->mergedBaselines[$key] ?? null; + + if ($memo !== null && $memo[0] === $own && $memo[1] === $fallback) { + return $memo[2]; + } + $under = ($own['complete'] ?? false) === true ? $this->withoutFilesCoveredBy($fallback['results'], $own['results']) : $fallback['results']; - return [ + $merged = [ 'sha' => $own['sha'] ?? $fallback['sha'], 'tree' => $own['tree'] !== [] ? $own['tree'] : $fallback['tree'], 'results' => array_replace($under, $own['results']), ]; + + $this->mergedBaselines[$key] = [$own, $fallback, $merged]; + + return $merged; } /** diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 76039dfc..926fd67e 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1984,6 +1984,7 @@ ✓ 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 + ✓ branch baseline over the fallback → it reads results written after an earlier read PASS Tests\Unit\Plugins\Tia\IsEnabledForRun ✓ does not throw when an integer --random-order-seed is passed as a separate argv element @@ -2346,4 +2347,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, 37 skipped, 1665 passed (3701 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1666 passed (3706 assertions) \ No newline at end of file diff --git a/tests/Unit/Plugins/Tia/Graph.php b/tests/Unit/Plugins/Tia/Graph.php index 6d7d45be..8447b5da 100644 --- a/tests/Unit/Plugins/Tia/Graph.php +++ b/tests/Unit/Plugins/Tia/Graph.php @@ -326,3 +326,23 @@ describe('clearResults()', function (): void { ->and($graph->getResult('main', 'Tests\FooTest::it passes'))->toBeNull(); }); }); + +describe('branch baseline over the fallback', function (): void { + it('reads results written after an earlier read', function (): void { + $graph = new Graph(sys_get_temp_dir()); + $graph->setResult('main', 'Tests\FooTest::it passes', 0, '', 0.1, 1, 'tests/Feature/FooTest.php'); + $graph->setResult('main', 'Tests\BarTest::it passes', 0, '', 0.2, 1, 'tests/Feature/BarTest.php'); + $graph->setResult('feature', 'Tests\FooTest::it passes', 0, '', 0.3, 1, 'tests/Feature/FooTest.php'); + $graph->markBaselineComplete('feature'); + + expect($graph->getTime('feature', 'Tests\FooTest::it passes', 'main'))->toBe(0.3) + ->and($graph->getTime('feature', 'Tests\BarTest::it passes', 'main'))->toBe(0.2); + + $graph->setResult('feature', 'Tests\FooTest::it passes', 7, 'boom', 0.4, 1, 'tests/Feature/FooTest.php'); + $graph->setResult('main', 'Tests\BarTest::it passes', 0, '', 0.5, 1, 'tests/Feature/BarTest.php'); + + expect($graph->getTime('feature', 'Tests\FooTest::it passes', 'main'))->toBe(0.4) + ->and($graph->getResult('feature', 'Tests\FooTest::it passes', 'main')?->isFailure())->toBeTrue() + ->and($graph->getTime('feature', 'Tests\BarTest::it passes', 'main'))->toBe(0.5); + }); +}); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 73af80d7..15447af4 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -21,7 +21,7 @@ test('parallel', function () use ($run): void { $output = implode("\n", array_slice(explode("\n", (string) $output), -10)); $profileOutput = $run('tests/Fixtures/Suites/SuccessOnly.php', '--profile'); - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1636 passed (3623 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1637 passed (3628 assertions)'; expect($output) ->toContain("Tests: {$expected}")