fix(tia): reuse baselines across replacement CI merge commits (#1923)

* perf(tia): reuse baselines across replacement CI merge commits

* style: apply Rector rules to merge baseline validation
This commit is contained in:
Daniel Polito
2026-09-18 06:00:59 -03:00
committed by GitHub
parent 94f4f1ff48
commit 8b6607e344
2 changed files with 69 additions and 1 deletions
+17 -1
View File
@@ -297,7 +297,23 @@ final readonly class ChangedFiles
private function shaIsReachable(string $sha): bool
{
return $this->git->succeeds(['merge-base', '--is-ancestor', $sha, 'HEAD']);
if ($this->git->succeeds(['merge-base', '--is-ancestor', $sha, 'HEAD'])) {
return true;
}
$parents = $this->git->raw(['show', '--no-patch', '--format=%P', $sha]);
if ($parents === null) {
return false;
}
$parents = explode(' ', trim($parents));
if (count($parents) < 2) {
return false;
}
return array_all($parents, fn (string $parent): bool => $this->git->succeeds(['merge-base', '--is-ancestor', $parent, 'HEAD']));
}
/**
+52
View File
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
use Pest\Plugins\Tia\ChangedFiles;
use Tests\Fixtures\Tia\Project;
afterEach(function (): void {
Project::destroyAll();
});
test('a replacement CI merge reuses its baseline and selects changed tests on either parent', function (array $arguments, string $changedBranch): void {
$project = Project::make('master');
$git = $project->git();
$git->switchTo('feature', new: true);
$git->commit('feature');
$git->run(['checkout', '--detach', 'master']);
$git->run(['merge', '--no-ff', '--no-edit', 'feature']);
$project->seed('123/merge');
$git->switchTo($changedBranch);
$project->write('tests/Unit/CalculatorTest.php', str_replace(
'->add(1, 2)',
'->add(2, 1)',
file_get_contents($project->path('tests/Unit/CalculatorTest.php')) ?: throw new RuntimeException('Missing calculator test fixture.'),
));
$git->commit('change calculator');
$git->run(['checkout', '--detach', 'master']);
$git->run(['merge', '--no-ff', '--no-edit', 'feature']);
$result = $project->pestWithEnvironment($project->path(), [
'GITHUB_REF_NAME' => '123/merge',
], '--tia', ...$arguments);
expect($result->exitCode)->toBe(0, $result->describe())
->and($result->output)->not->toContain('no longer reachable')
->and($result->replayed())->toBe(4, $result->describe())
->and($result->tally())->toContain('6 passed');
})->with(Project::SEQUENTIAL_AND_PARALLEL)->with(['feature', 'master'])->skipOnWindows();
test('a merge baseline is rejected when one of its parents is absent from the current history', function (): void {
$project = Project::make('master');
$git = $project->git();
$git->switchTo('feature', new: true);
$git->commit('feature');
$git->run(['checkout', '--detach', 'master']);
$git->run(['merge', '--no-ff', '--no-edit', 'feature']);
$sha = $git->sha();
$git->switchTo('master');
expect(new ChangedFiles($project->path())->since($sha))->toBeNull();
})->skipOnWindows();