From 3b51856354b65710e200e95695ec1b1f3610ed2f Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 31 Oct 2026 18:47:26 +0400 Subject: [PATCH] fix(tia): stop a replay when the baseline commit cannot be reached (#1951) A fetched baseline can be recorded at a commit that the local clone does not have, or that the current branch does not contain. The changed files cannot be listed then, and the replay treated the changed set as empty: every test was replayed as passed. Stop with an error that names the commit and says how to recover. --- src/Exceptions/TiaBaselineCommitMissing.php | 50 +++++++++++++++++++++ src/Plugins/Tia.php | 7 ++- tests/Features/Tia/RemoteBaseline.php | 16 +++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/Exceptions/TiaBaselineCommitMissing.php diff --git a/src/Exceptions/TiaBaselineCommitMissing.php b/src/Exceptions/TiaBaselineCommitMissing.php new file mode 100644 index 00000000..b640a74d --- /dev/null +++ b/src/Exceptions/TiaBaselineCommitMissing.php @@ -0,0 +1,50 @@ +writeln([ + '', + sprintf(' ERROR The Tia baseline commit %s cannot be reached from this branch.', substr($this->sha, 0, 12)), + '', + ' Either the commit is not in this clone, or this branch does not contain it.', + ' Without it the files changed since the baseline cannot be listed, and every', + ' test would be replayed as unchanged.', + '', + ' Fetch it, or merge the branch it was recorded on, then run again:', + '', + ' git fetch', + '', + ' Or use --fresh to record locally.', + '', + ]); + } + + public function exitCode(): int + { + return 1; + } +} diff --git a/src/Plugins/Tia.php b/src/Plugins/Tia.php index 058b7f64..7c7b2234 100644 --- a/src/Plugins/Tia.php +++ b/src/Plugins/Tia.php @@ -12,6 +12,7 @@ use Pest\Contracts\Plugins\Terminable; use Pest\Exceptions\InvalidOption; use Pest\Exceptions\MissingDependency; use Pest\Exceptions\NoAffectedTestsFound; +use Pest\Exceptions\TiaBaselineCommitMissing; use Pest\Exceptions\TiaRequiresCommit; use Pest\Exceptions\TiaRequiresDefaultBranch; use Pest\Exceptions\TiaRequiresRemote; @@ -1082,7 +1083,11 @@ final class Tia implements AddsOutput, HandlesArguments, HandlesOriginalArgument $changedFiles = new ChangedFiles($projectRoot); $branchSha = $graph->recordedAtSha($this->branch); - $changed = $changedFiles->since($branchSha) ?? []; + $changed = $changedFiles->since($branchSha); + + if ($changed === null) { + Panic::with(new TiaBaselineCommitMissing((string) $branchSha)); + } $changed = $changedFiles->filterUnchangedSinceLastRun( $changed, diff --git a/tests/Features/Tia/RemoteBaseline.php b/tests/Features/Tia/RemoteBaseline.php index d47fb0a1..b0c543be 100644 --- a/tests/Features/Tia/RemoteBaseline.php +++ b/tests/Features/Tia/RemoteBaseline.php @@ -64,6 +64,22 @@ test('a fetched baseline recorded against another tree is not used', function () ->and($result->replayed())->toBe(0, $result->describe()); })->skipOnWindows(); +test('a fetched baseline recorded at a commit this clone lacks fails loudly', function (): void { + [$project, $environment] = tiaPublishedBaseline('ok', function (array $graph): array { + foreach (array_keys($graph['baselines']) as $branch) { + $graph['baselines'][$branch]['sha'] = str_repeat('1', 40); + } + + return $graph; + }); + + $result = $project->pestWithEnvironment($project->path(), $environment, '--tia', '--baselined'); + + expect($result->exitCode)->toBe(1, $result->describe()) + ->and($result->output)->toContain('cannot be reached from this branch') + ->and($result->replayed())->toBe(0, $result->describe()); +})->skipOnWindows(); + test('an artifact without a graph in it fails loudly', function (): void { [$project, $environment] = tiaPublishedBaseline('missing-asset');