From 228c627b649c8a862c33c181b1f09ddfa7f4ec5f Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Sat, 31 Oct 2026 19:47:06 +0500 Subject: [PATCH] fix(tia): record new dependencies of known tests on coverage runs (#1955) * fix(tia): record new dependencies of known tests on coverage runs * chore(tia): drop the keepExisting docblock line --- src/Plugins/Tia/Graph.php | 7 +----- tests/Features/Tia/CoveragePiggyback.php | 32 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/Plugins/Tia/Graph.php b/src/Plugins/Tia/Graph.php index cbf74210..09051268 100644 --- a/src/Plugins/Tia/Graph.php +++ b/src/Plugins/Tia/Graph.php @@ -1025,7 +1025,6 @@ final class Graph /** * @param array> $testToFiles - * @param bool $keepExisting Leave already-recorded edge sets alone. */ public function replaceEdges(array $testToFiles, bool $keepExisting = false): void { @@ -1036,11 +1035,7 @@ final class Graph continue; } - if ($keepExisting && ($this->edges[$testRel] ?? []) !== []) { - continue; - } - - $this->edges[$testRel] = []; + $this->edges[$testRel] = $keepExisting ? ($this->edges[$testRel] ?? []) : []; foreach ($sources as $source) { $this->link($testFile, $source); diff --git a/tests/Features/Tia/CoveragePiggyback.php b/tests/Features/Tia/CoveragePiggyback.php index a28b2280..8fd60189 100644 --- a/tests/Features/Tia/CoveragePiggyback.php +++ b/tests/Features/Tia/CoveragePiggyback.php @@ -90,3 +90,35 @@ test('a coverage report leaves the edges of an existing graph alone', function ( ->and($delta->removed())->toBe(0, $delta->summary()) ->and($delta->added())->toBe(0, $delta->summary()); })->skipOnWindows(); + +test('a coverage report adds a new dependency to the edges of an existing graph', function (array $arguments): void { + $project = Project::make('master'); + $project->seed('master'); + + $project->write('app/Greeter.php', <<<'PHP' + add(1, 1); + + return sprintf('Hello, %s!', $name); + } + } + PHP); + + $result = $project->pest('--tia', '--coverage', ...$arguments); + + $graph = $project->graph(); + $edges = array_map(fn (int $id): string => $graph['files'][$id], $graph['edges']['tests/Unit/GreeterTest.php']); + + expect($result->exitCode)->toBe(0, $result->describe()) + ->and($edges)->toContain('app/Greeter.php') + ->and($edges)->toContain('app/Calculator.php'); +})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows()->skip(! Coverage::isAvailable(), 'Coverage is not available');