This commit is contained in:
nuno maduro
2026-05-02 15:26:58 +01:00
parent 348b439172
commit 460401c379
2 changed files with 24 additions and 5 deletions

View File

@ -49,6 +49,10 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
private const string FILTERED_OPTION = '--filtered'; private const string FILTERED_OPTION = '--filtered';
private const string ENV_TIA = 'PEST_TIA';
private const string ENV_FILTERED = 'PEST_TIA_FILTERED';
public const string KEY_GRAPH = 'graph.json'; public const string KEY_GRAPH = 'graph.json';
public const string KEY_AFFECTED = 'affected.json'; public const string KEY_AFFECTED = 'affected.json';
@ -174,7 +178,7 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
*/ */
public static function isEnabledForRun(array $arguments): bool public static function isEnabledForRun(array $arguments): bool
{ {
if (in_array(self::OPTION, $arguments, true)) { if (in_array(self::OPTION, $arguments, true) || self::envFlagEnabled(self::ENV_TIA)) {
return true; return true;
} }
@ -188,6 +192,11 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
return ! ($watchPatterns->isLocally() && in_array('--ci', $arguments, true)); return ! ($watchPatterns->isLocally() && in_array('--ci', $arguments, true));
} }
private static function envFlagEnabled(string $name): bool
{
return filter_var(getenv($name), FILTER_VALIDATE_BOOL);
}
public function getStatus(string $filename, string $testId): ?TestStatus public function getStatus(string $filename, string $testId): ?TestStatus
{ {
if (! $this->replayGraph instanceof Graph) { if (! $this->replayGraph instanceof Graph) {
@ -249,11 +258,11 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
/** @var WatchPatterns $watchPatterns */ /** @var WatchPatterns $watchPatterns */
$watchPatterns = Container::getInstance()->get(WatchPatterns::class); $watchPatterns = Container::getInstance()->get(WatchPatterns::class);
$disabled = $this->hasArgument(self::NO_OPTION, $arguments); $disabled = $this->hasArgument(self::NO_OPTION, $arguments);
$cliEnabled = $this->hasArgument(self::OPTION, $arguments); $cliEnabled = $this->hasArgument(self::OPTION, $arguments) || self::envFlagEnabled(self::ENV_TIA);
$alwaysEnabled = $watchPatterns->isEnabled() $alwaysEnabled = $watchPatterns->isEnabled()
&& (! $watchPatterns->isLocally() || Environment::name() === Environment::LOCAL); && (! $watchPatterns->isLocally() || Environment::name() === Environment::LOCAL);
$enabled = ! $disabled && ($cliEnabled || $alwaysEnabled); $enabled = ! $disabled && ($cliEnabled || $alwaysEnabled);
$this->filteredMode = ($this->hasArgument(self::FILTERED_OPTION, $arguments) || $watchPatterns->isFiltered()) $this->filteredMode = ($this->hasArgument(self::FILTERED_OPTION, $arguments) || self::envFlagEnabled(self::ENV_FILTERED) || $watchPatterns->isFiltered())
&& ! $this->hasExplicitPathArgument($arguments); && ! $this->hasExplicitPathArgument($arguments);
$freshRequested = $this->hasArgument(self::FRESH_OPTION, $arguments); $freshRequested = $this->hasArgument(self::FRESH_OPTION, $arguments);
$this->forceRefetch = $this->hasArgument(self::REFETCH_OPTION, $arguments); $this->forceRefetch = $this->hasArgument(self::REFETCH_OPTION, $arguments);

View File

@ -9,12 +9,12 @@ namespace Pest\Plugins\Tia;
*/ */
final readonly class Fingerprint final readonly class Fingerprint
{ {
private const int SCHEMA_VERSION = 14; private const int SCHEMA_VERSION = 15;
/** /**
* @return array{ * @return array{
* structural: array<string, int|string|null>, * structural: array<string, int|string|null>,
* environmental: array<string, string|null>, * environmental: array<string, int|string|null>,
* } * }
*/ */
public static function compute(string $projectRoot): array public static function compute(string $projectRoot): array
@ -22,6 +22,7 @@ final readonly class Fingerprint
return [ return [
'structural' => [ 'structural' => [
'schema' => self::SCHEMA_VERSION, 'schema' => self::SCHEMA_VERSION,
'composer_lock' => self::composerLockHash($projectRoot),
'phpunit_xml' => self::hashIfExists($projectRoot.'/phpunit.xml'), 'phpunit_xml' => self::hashIfExists($projectRoot.'/phpunit.xml'),
'phpunit_xml_dist' => self::hashIfExists($projectRoot.'/phpunit.xml.dist'), 'phpunit_xml_dist' => self::hashIfExists($projectRoot.'/phpunit.xml.dist'),
'pest_factory' => self::contentHashOrNull(__DIR__.'/../../Factories/TestCaseFactory.php'), 'pest_factory' => self::contentHashOrNull(__DIR__.'/../../Factories/TestCaseFactory.php'),
@ -33,6 +34,10 @@ final readonly class Fingerprint
'composer_json' => self::composerJsonHash($projectRoot), 'composer_json' => self::composerJsonHash($projectRoot),
], ],
'environmental' => [ 'environmental' => [
'php_minor' => PHP_MAJOR_VERSION,
// 'extensions' => self::extensionsFingerprint($projectRoot),
// 'env_files' => self::envFilesHash($projectRoot),
], ],
]; ];
} }
@ -226,6 +231,11 @@ final readonly class Fingerprint
return $json === false ? null : hash('xxh128', $json); return $json === false ? null : hash('xxh128', $json);
} }
private static function composerLockHash(string $projectRoot): ?string
{
return self::hashIfExists($projectRoot.'/composer.lock');
}
private static function packageLockHash(string $projectRoot): ?string private static function packageLockHash(string $projectRoot): ?string
{ {
$parts = []; $parts = [];