perf(test): cache project test inventories

This commit is contained in:
Peter Steinberger
2026-07-06 13:46:49 -04:00
parent dabc40d42c
commit bb59790646
+24 -6
View File
@@ -2340,14 +2340,22 @@ function splitTargetChunks(targets, chunkCount) {
return chunks;
}
let cachedBroadScriptTestTargets = null;
let cachedBroadScriptTestTargetsCwd = null;
function listBroadScriptTestTargets(pattern, cwd) {
const root = path.join(cwd, "test/scripts");
if (!fs.existsSync(root)) {
return [];
if (cachedBroadScriptTestTargetsCwd !== cwd) {
// Broad-target expansion can ask for the same process-stable checkout twice.
// Keep one inventory so planning does not repeat the directory walk.
cachedBroadScriptTestTargets = fs.existsSync(root)
? listRepoFilesRecursive(root, cwd)
.filter((file) => file.endsWith(".test.ts"))
.toSorted((left, right) => left.localeCompare(right))
: [];
cachedBroadScriptTestTargetsCwd = cwd;
}
return listRepoFilesRecursive(root, cwd)
.filter((file) => file.endsWith(".test.ts") && path.matchesGlob(file, pattern))
.toSorted((left, right) => left.localeCompare(right));
return cachedBroadScriptTestTargets.filter((file) => path.matchesGlob(file, pattern));
}
function listBroadToolingScriptTestTargets(pattern, cwd) {
@@ -2356,14 +2364,24 @@ function listBroadToolingScriptTestTargets(pattern, cwd) {
);
}
let cachedToolingFullSuiteTestTargets = null;
let cachedToolingFullSuiteTestTargetsCwd = null;
function listToolingFullSuiteTestTargets(cwd) {
return uniqueOrdered(
if (cachedToolingFullSuiteTestTargets && cachedToolingFullSuiteTestTargetsCwd === cwd) {
return cachedToolingFullSuiteTestTargets;
}
// The CLI plans against one process-stable checkout. Reuse its inventory when
// callers compare full-suite modes instead of walking the tree for every mode.
cachedToolingFullSuiteTestTargets = uniqueOrdered(
[path.join(cwd, "test"), path.join(cwd, "src", "scripts")].flatMap((root) =>
fs.existsSync(root) ? listRepoFilesRecursive(root, cwd) : [],
),
)
.filter((file) => file.endsWith(".test.ts") && classifyTarget(file, cwd) === "tooling")
.toSorted((left, right) => left.localeCompare(right));
cachedToolingFullSuiteTestTargetsCwd = cwd;
return cachedToolingFullSuiteTestTargets;
}
function listUnitFastFullSuiteTestTargets() {