feat(tia): continues to work on poc

This commit is contained in:
nuno maduro
2026-04-16 13:40:24 -07:00
parent 41f11c0ef3
commit 15035d37ef
2 changed files with 11 additions and 71 deletions

View File

@ -14,7 +14,6 @@ use Pest\Plugins\Tia\Fingerprint;
use Pest\Plugins\Tia\Graph;
use Pest\Plugins\Tia\Recorder;
use Pest\Plugins\Tia\ResultCollector;
use Pest\TestCaseFilters\TiaTestCaseFilter;
use Pest\Plugins\Tia\WatchPatterns;
use Pest\Support\Container;
use Pest\TestSuite;
@ -435,7 +434,7 @@ final class Tia implements AddsOutput, BeforeEachable, HandlesArguments, Termina
// the parent persisted, then install the per-file filter so
// whichever tests paratest happens to hand this worker are
// accepted / rejected consistently with the series path.
$this->installWorkerReplayFilter($projectRoot);
$this->installWorkerReplay($projectRoot);
return $arguments;
}
@ -458,7 +457,14 @@ final class Tia implements AddsOutput, BeforeEachable, HandlesArguments, Termina
return $arguments;
}
private function installWorkerReplayFilter(string $projectRoot): void
/**
* Wires worker-side replay. Mirrors the series path: sets `replayGraph`
* + `affectedFiles` so the `BeforeEachable` hook in `beforeEach()` can
* answer per-test. Unaffected tests replay their cached status (pass,
* fail, skip, todo, incomplete) so the user sees the full suite report
* in parallel runs exactly like in series.
*/
private function installWorkerReplay(string $projectRoot): void
{
$cachePath = self::cachePath();
$affectedPath = self::affectedPath();
@ -489,9 +495,8 @@ final class Tia implements AddsOutput, BeforeEachable, HandlesArguments, Termina
}
}
TestSuite::getInstance()->tests->addTestCaseFilter(
new TiaTestCaseFilter($projectRoot, $graph, $affectedSet),
);
$this->replayGraph = $graph;
$this->affectedFiles = $affectedSet;
}
/**

View File

@ -1,65 +0,0 @@
<?php
declare(strict_types=1);
namespace Pest\TestCaseFilters;
use Pest\Contracts\TestCaseFilter;
use Pest\Plugins\Tia\Graph;
/**
* Accepts a test file in one of three cases:
*
* 1. The file falls outside the project root (we cannot reason about it, so
* stay safe and run it).
* 2. The graph has no record of the file — this is a new test that was
* never part of a recording run, so we accept it by default. Skipping
* unknown tests would be a correctness hazard (developers add tests and
* TIA would silently not run them).
* 3. The graph knows the file AND it is in the affected set.
*
* @internal
*/
final readonly class TiaTestCaseFilter implements TestCaseFilter
{
/**
* @param array<string, true> $affectedTestFiles Keys are project-relative test file paths.
*/
public function __construct(
private string $projectRoot,
private Graph $graph,
private array $affectedTestFiles,
) {}
public function accept(string $testCaseFilename): bool
{
$rel = $this->relative($testCaseFilename);
if ($rel === null) {
return true;
}
if (! $this->graph->knowsTest($rel)) {
return true;
}
return isset($this->affectedTestFiles[$rel]);
}
private function relative(string $path): ?string
{
$real = @realpath($path);
if ($real === false) {
$real = $path;
}
$root = rtrim($this->projectRoot, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
if (! str_starts_with($real, $root)) {
return null;
}
return str_replace(DIRECTORY_SEPARATOR, '/', substr($real, strlen($root)));
}
}