mirror of
https://github.com/pestphp/pest.git
synced 2026-12-05 07:15:33 +01:00
fix(tia): keep the run going when git is slow at boot (#2088)
* fix(tia): keep the run going when git is slow at boot * fix(tia): catch GitTimedOut in the boot git calls Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins\Tia;
|
||||
|
||||
use Pest\Exceptions\GitTimedOut;
|
||||
use Pest\Support\Git;
|
||||
|
||||
/**
|
||||
@@ -134,12 +135,20 @@ final class Storage
|
||||
|
||||
private static function rawOriginUrl(string $projectRoot): ?string
|
||||
{
|
||||
return new Git($projectRoot)->originUrl();
|
||||
try {
|
||||
return new Git($projectRoot)->originUrl();
|
||||
} catch (GitTimedOut) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function gitPrefix(string $projectRoot): string
|
||||
{
|
||||
return new Git($projectRoot)->pathPrefix();
|
||||
try {
|
||||
return new Git($projectRoot)->pathPrefix();
|
||||
} catch (GitTimedOut) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
private static function slug(string $name): string
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
use Tests\Fixtures\Tia\Project;
|
||||
|
||||
afterEach(function (): void {
|
||||
Project::destroyAll();
|
||||
});
|
||||
|
||||
function slowGitAtBootPath(Project $project, string $command): string
|
||||
{
|
||||
$git = (new ExecutableFinder)->find('git');
|
||||
|
||||
assert(is_string($git));
|
||||
|
||||
$directory = $project->path('.slow-git');
|
||||
$realGit = escapeshellarg($git);
|
||||
$slept = escapeshellarg($directory.'/slept');
|
||||
|
||||
mkdir($directory);
|
||||
file_put_contents($directory.'/git', <<<SH
|
||||
#!/bin/sh
|
||||
case "\$1 \$2" in
|
||||
"{$command}") [ -e {$slept} ] || { touch {$slept}; exec sleep 6; } ;;
|
||||
esac
|
||||
exec {$realGit} "\$@"
|
||||
SH);
|
||||
chmod($directory.'/git', 0755);
|
||||
|
||||
return $directory.PATH_SEPARATOR.getenv('PATH');
|
||||
}
|
||||
|
||||
test('a slow git while reading the origin url does not stop a run without --tia', function (): void {
|
||||
$project = Project::make('master');
|
||||
$project->seed('master');
|
||||
|
||||
$path = slowGitAtBootPath($project, 'config --get');
|
||||
$result = $project->pestWithEnvironment($project->path(), ['PATH' => $path]);
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->tally())->toContain(Project::TOTAL_TESTS.' passed')
|
||||
->and($project->path('.slow-git/slept'))->toBeFile('the slow git never ran');
|
||||
})->skipOnWindows();
|
||||
|
||||
test('a slow git while reading the path prefix does not stop a run without --tia', function (): void {
|
||||
$project = Project::make('master');
|
||||
$project->seed('master');
|
||||
|
||||
$path = slowGitAtBootPath($project, 'rev-parse --show-prefix');
|
||||
$result = $project->pestWithEnvironment($project->path(), ['PATH' => $path]);
|
||||
|
||||
expect($result->exitCode)->toBe(0, $result->describe())
|
||||
->and($result->tally())->toContain(Project::TOTAL_TESTS.' passed')
|
||||
->and($project->path('.slow-git/slept'))->toBeFile('the slow git never ran');
|
||||
})->skipOnWindows();
|
||||
Reference in New Issue
Block a user