Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Plugins/Tia.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public function terminate(): void
$changedFiles = new ChangedFiles($projectRoot);
$currentSha = $changedFiles->currentSha();

$currentFingerprint = Fingerprint::compute($projectRoot);
$currentFingerprint = Fingerprint::compute($projectRoot, $this->originalArguments);

if ($this->structuralFingerprintShifted($currentFingerprint)) {
$this->renderBadge('WARN', 'Project files changed during the run — discarding recorded edges.');
Expand Down Expand Up @@ -708,7 +708,7 @@ public function addOutput(int $exitCode): int
$changedFiles = new ChangedFiles($projectRoot);
$currentSha = $changedFiles->currentSha();

$currentFingerprint = Fingerprint::compute($projectRoot);
$currentFingerprint = Fingerprint::compute($projectRoot, $this->originalArguments);

if ($this->structuralFingerprintShifted($currentFingerprint)) {
$this->renderBadge('WARN', 'Project files changed during the run — discarding recorded edges.');
Expand Down Expand Up @@ -846,7 +846,7 @@ private function handleParent(array $arguments, string $projectRoot, bool $force
: new TiaRequiresRemote);
}

$fingerprint = Fingerprint::compute($projectRoot);
$fingerprint = Fingerprint::compute($projectRoot, $this->originalArguments);
$this->startFingerprint = $fingerprint;

if ($forceRebuild && ! $this->detachedHead) {
Expand Down
70 changes: 67 additions & 3 deletions src/Plugins/Tia/Fingerprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
];

/**
* @param array<int, string> $arguments
* @return array{
* structural: array<string, int|string|null>,
* environmental: array<string, int|string|null>,
* }
*/
public static function compute(string $projectRoot): array
public static function compute(string $projectRoot, array $arguments = []): array
{
return [
'structural' => [
'schema' => self::SCHEMA_VERSION,
'composer_lock' => self::composerLockHash($projectRoot),
'phpunit_xml' => self::trackedHash($projectRoot, 'phpunit.xml'),
'phpunit_xml_dist' => self::trackedHash($projectRoot, 'phpunit.xml.dist'),
'phpunit_xml' => self::phpunitConfigurationHash($projectRoot, $arguments),
'vite_config' => self::viteConfigHash($projectRoot),
'package_lock' => self::packageLockHash($projectRoot),
'js_config' => self::jsConfigHash($projectRoot),
Expand Down Expand Up @@ -197,6 +197,70 @@ private static function jsConfigHash(string $projectRoot): ?string
return $parts === [] ? null : hash('xxh128', implode("\n", $parts));
}

/**
* @param array<int, string> $arguments
*/
private static function phpunitConfigurationHash(string $projectRoot, array $arguments): ?string
{
foreach (self::configurationCandidates($projectRoot, $arguments) as $candidate) {
$hash = self::hashIfExists($candidate);

if ($hash !== null) {
return $hash;
}
}

return null;
}

/**
* @param array<int, string> $arguments
* @return list<string>
*/
private static function configurationCandidates(string $projectRoot, array $arguments): array
{
$option = self::configurationOption($arguments);

$path = $option === null ? $projectRoot : realpath($option);

if ($path === false) {
return [];
}

if (is_file($path)) {
return [$path];
}

return [
$path.DIRECTORY_SEPARATOR.'phpunit.xml',
$path.DIRECTORY_SEPARATOR.'phpunit.xml.dist',
];
}

/**
* @param array<int, string> $arguments
*/
private static function configurationOption(array $arguments): ?string
{
$arguments = array_values($arguments);

foreach ($arguments as $index => $argument) {
if ($argument === '-c' || $argument === '--configuration') {
return $arguments[$index + 1] ?? null;
}

if (str_starts_with($argument, '--configuration=')) {
return substr($argument, strlen('--configuration='));
}

if (str_starts_with($argument, '-c')) {
return substr($argument, 2);
}
}

return null;
}

private static function composerLockHash(string $projectRoot): ?string
{
return self::trackedHash($projectRoot, 'composer.lock');
Expand Down
9 changes: 6 additions & 3 deletions src/Restarters/XdebugRestarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ private function runLooksDroppable(array $arguments, string $projectRoot): bool
return false;
}

return $this->tiaWillReplay($projectRoot);
return $this->tiaWillReplay($projectRoot, $arguments);
}

private function tiaWillReplay(string $projectRoot): bool
/**
* @param array<int, string> $arguments
*/
private function tiaWillReplay(string $projectRoot, array $arguments): bool
{
$path = Storage::tempDir($projectRoot).DIRECTORY_SEPARATOR.Tia::KEY_GRAPH;

Expand All @@ -111,7 +114,7 @@ private function tiaWillReplay(string $projectRoot): bool

return Fingerprint::structuralMatches(
$graph->fingerprint(),
Fingerprint::compute($projectRoot),
Fingerprint::compute($projectRoot, $arguments),
);
}
}
5 changes: 3 additions & 2 deletions tests/Features/Tia.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
$projectRoot = dirname(__DIR__, 2);
$home = sys_get_temp_dir().'/pest-tia-'.bin2hex(random_bytes(8));
$fixture = 'tests/Fixtures/Suites/TiaReplayHooks.php';
$arguments = ['--configuration', 'tests/Fixtures/Suites/TiaReplayHooks.xml', '--tia'];

mkdir($home, 0755, true);

Expand All @@ -24,7 +25,7 @@
$id = fn (string $description): string => 'P\Tests\Fixtures\Suites\TiaReplayHooks::'.Str::evaluable($description);

$graph = new Graph($projectRoot);
$graph->setFingerprint(Fingerprint::compute($projectRoot));
$graph->setFingerprint(Fingerprint::compute($projectRoot, $arguments));
$graph->setRecordedAtSha($branch, $sha);
$graph->setLastRunTree($branch, $changedFiles->snapshotTree($changedFiles->since($sha) ?? []));
$graph->markKnownTestFiles([$fixture]);
Expand All @@ -48,7 +49,7 @@
expect($storage->write(Tia::KEY_GRAPH, (string) $json))->toBeTrue();

$process = new Process(
['php', 'bin/pest', '--configuration', 'tests/Fixtures/Suites/TiaReplayHooks.xml', '--tia'],
['php', 'bin/pest', ...$arguments],
$projectRoot,
[
'COLLISION_PRINTER' => 'DefaultPrinter',
Expand Down
Loading