@@ -2340,14 +2340,22 @@ function splitTargetChunks(targets, chunkCount) {
23402340 return chunks ;
23412341}
23422342
2343+ let cachedBroadScriptTestTargets = null ;
2344+ let cachedBroadScriptTestTargetsCwd = null ;
2345+
23432346function listBroadScriptTestTargets ( pattern , cwd ) {
23442347 const root = path . join ( cwd , "test/scripts" ) ;
2345- if ( ! fs . existsSync ( root ) ) {
2346- return [ ] ;
2347- }
2348- return listRepoFilesRecursive ( root , cwd )
2349- . filter ( ( file ) => file . endsWith ( ".test.ts" ) && path . matchesGlob ( file , pattern ) )
2350- . toSorted ( ( left , right ) => left . localeCompare ( right ) ) ;
2348+ if ( cachedBroadScriptTestTargetsCwd !== cwd ) {
2349+ // Broad-target expansion can ask for the same process-stable checkout twice.
2350+ // Keep one inventory so planning does not repeat the directory walk.
2351+ cachedBroadScriptTestTargets = fs . existsSync ( root )
2352+ ? listRepoFilesRecursive ( root , cwd )
2353+ . filter ( ( file ) => file . endsWith ( ".test.ts" ) )
2354+ . toSorted ( ( left , right ) => left . localeCompare ( right ) )
2355+ : [ ] ;
2356+ cachedBroadScriptTestTargetsCwd = cwd ;
2357+ }
2358+ return cachedBroadScriptTestTargets . filter ( ( file ) => path . matchesGlob ( file , pattern ) ) ;
23512359}
23522360
23532361function listBroadToolingScriptTestTargets ( pattern , cwd ) {
@@ -2356,14 +2364,24 @@ function listBroadToolingScriptTestTargets(pattern, cwd) {
23562364 ) ;
23572365}
23582366
2367+ let cachedToolingFullSuiteTestTargets = null ;
2368+ let cachedToolingFullSuiteTestTargetsCwd = null ;
2369+
23592370function listToolingFullSuiteTestTargets ( cwd ) {
2360- return uniqueOrdered (
2371+ if ( cachedToolingFullSuiteTestTargets && cachedToolingFullSuiteTestTargetsCwd === cwd ) {
2372+ return cachedToolingFullSuiteTestTargets ;
2373+ }
2374+ // The CLI plans against one process-stable checkout. Reuse its inventory when
2375+ // callers compare full-suite modes instead of walking the tree for every mode.
2376+ cachedToolingFullSuiteTestTargets = uniqueOrdered (
23612377 [ path . join ( cwd , "test" ) , path . join ( cwd , "src" , "scripts" ) ] . flatMap ( ( root ) =>
23622378 fs . existsSync ( root ) ? listRepoFilesRecursive ( root , cwd ) : [ ] ,
23632379 ) ,
23642380 )
23652381 . filter ( ( file ) => file . endsWith ( ".test.ts" ) && classifyTarget ( file , cwd ) === "tooling" )
23662382 . toSorted ( ( left , right ) => left . localeCompare ( right ) ) ;
2383+ cachedToolingFullSuiteTestTargetsCwd = cwd ;
2384+ return cachedToolingFullSuiteTestTargets ;
23672385}
23682386
23692387function listUnitFastFullSuiteTestTargets ( ) {
0 commit comments