fix(tia): memoize the merged baseline so replay stays linear (#1974)

Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
This commit is contained in:
Jose Luis
2026-11-14 17:13:03 +01:00
committed by GitHub
parent 89cdbd5bc9
commit a483e38ddd
4 changed files with 40 additions and 3 deletions
+17 -1
View File
@@ -62,6 +62,11 @@ final class Graph
private string $fallbackBranch = 'main';
/**
* @var array<string, array{0: array{sha: ?string, tree: array<string, string>, complete?: bool, results: array<string, array{status: int, message: string, time: float, assertions?: int, file?: string}>}, 1: array{sha: ?string, tree: array<string, string>, complete?: bool, results: array<string, array{status: int, message: string, time: float, assertions?: int, file?: string}>}, 2: array{sha: ?string, tree: array<string, string>, complete?: bool, results: array<string, array{status: int, message: string, time: float, assertions?: int, file?: string}>}}>
*/
private array $mergedBaselines = [];
private readonly string $projectRoot;
/** @var array<string, true>|null */
@@ -976,15 +981,26 @@ final class Graph
return $own;
}
$key = $branch."\0".$fallbackBranch;
$memo = $this->mergedBaselines[$key] ?? null;
if ($memo !== null && $memo[0] === $own && $memo[1] === $fallback) {
return $memo[2];
}
$under = ($own['complete'] ?? false) === true
? $this->withoutFilesCoveredBy($fallback['results'], $own['results'])
: $fallback['results'];
return [
$merged = [
'sha' => $own['sha'] ?? $fallback['sha'],
'tree' => $own['tree'] !== [] ? $own['tree'] : $fallback['tree'],
'results' => array_replace($under, $own['results']),
];
$this->mergedBaselines[$key] = [$own, $fallback, $merged];
return $merged;
}
/**