fix(tia): skip locally() when the process is on CI (#1999)

* fix(tia): skip locally() when the process is on CI

locally() only looked at --ci, so a CI job that followed the docs and
ran plain pest replayed cached results.

Fixes #1970

* test(tia): clear CI variables so the local assertion passes on CI

* test: update snapshots for TIA CI detection

---------

Co-authored-by: Tiago Santos <tsantos@lynixt.pt>
Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
Tiago Santos
2026-11-02 11:56:12 +00:00
committed by GitHub
parent e7a1b483f0
commit 8eb2892f69
6 changed files with 96 additions and 5 deletions
@@ -1,6 +1,9 @@
<?php
use Pest\Plugins\Tia;
use Pest\Plugins\Tia\WatchPatterns;
use Pest\Support\Ci;
use Pest\Support\Container;
test('does not throw when an integer --random-order-seed is passed as a separate argv element', function (): void {
$arguments = ['--order-by=random', '--random-order-seed', 1782350398];
@@ -13,3 +16,56 @@ test('still detects --tia when an integer argument is present', function (): voi
expect(Tia::isEnabledForRun($arguments))->toBeTrue();
});
test('locally configured tia runs outside CI', function (): void {
$previous = [];
foreach (Ci::ENVIRONMENT_VARIABLES as $variable) {
$previous[$variable] = getenv($variable);
putenv($variable);
}
try {
withLocalTia(function (): void {
expect(Tia::isEnabledForRun([]))->toBeTrue();
});
} finally {
foreach ($previous as $variable => $value) {
putenv($value === false ? $variable : $variable.'='.$value);
}
}
});
test('locally configured tia stays off when CI is detected', function (string $variable): void {
withLocalTia(function () use ($variable): void {
$previous = getenv($variable);
putenv($variable.'=true');
try {
expect(Tia::isEnabledForRun([]))->toBeFalse()
->and(Tia::isEnabledForRun(['--ci']))->toBeFalse();
} finally {
putenv($previous === false ? $variable : $variable.'='.$previous);
}
});
})->with(['CI', 'GITHUB_ACTIONS']);
function withLocalTia(Closure $callback): void
{
$patterns = Container::getInstance()->get(WatchPatterns::class);
$reflection = new ReflectionClass($patterns);
$enabled = $reflection->getProperty('enabled');
$locally = $reflection->getProperty('locally');
$wasEnabled = $enabled->getValue($patterns);
$wasLocally = $locally->getValue($patterns);
$patterns->markEnabled();
$patterns->markLocally();
try {
$callback();
} finally {
$enabled->setValue($patterns, $wasEnabled);
$locally->setValue($patterns, $wasLocally);
}
}