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.
This commit is contained in:
Manuk
2026-10-31 18:47:26 +04:00
committed by GitHub
parent 228c627b64
commit 3b51856354
3 changed files with 72 additions and 1 deletions
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace Pest\Exceptions;
use NunoMaduro\Collision\Contracts\RenderlessEditor;
use NunoMaduro\Collision\Contracts\RenderlessTrace;
use Pest\Contracts\Panicable;
use RuntimeException;
use Symfony\Component\Console\Exception\ExceptionInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* @internal
*/
final class TiaBaselineCommitMissing extends RuntimeException implements ExceptionInterface, Panicable, RenderlessEditor, RenderlessTrace
{
public function __construct(private readonly string $sha)
{
parent::__construct(sprintf(
'The Tia baseline was recorded at commit %s, which cannot be reached from this branch, so the files changed since then cannot be listed.',
$sha,
));
}
public function render(OutputInterface $output): void
{
$output->writeln([
'',
sprintf(' <fg=white;options=bold;bg=red> 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:',
'',
' <fg=yellow>git fetch</>',
'',
' Or use <fg=yellow>--fresh</> to record locally.',
'',
]);
}
public function exitCode(): int
{
return 1;
}
}
+6 -1
View File
@@ -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,
+16
View File
@@ -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');