@@ -807,6 +807,53 @@ const targetedEntries = (() => {
807807 return [ createTargetedEntry ( owner , false , uniqueFilters ) ] ;
808808 } ) . flat ( ) ;
809809} ) ( ) ;
810+ const estimateTopLevelEntryDurationMs = ( entry ) => {
811+ const filters = getExplicitEntryFilters ( entry . args ) ;
812+ if ( filters . length === 0 ) {
813+ return unitTimingManifest . defaultDurationMs ;
814+ }
815+ return filters . reduce ( ( totalMs , file ) => {
816+ if ( isUnitConfigTestFile ( file ) ) {
817+ return totalMs + estimateUnitDurationMs ( file ) ;
818+ }
819+ if ( channelTestPrefixes . some ( ( prefix ) => file . startsWith ( prefix ) ) ) {
820+ return totalMs + 3_000 ;
821+ }
822+ if ( file . startsWith ( "extensions/" ) ) {
823+ return totalMs + 2_000 ;
824+ }
825+ return totalMs + 1_000 ;
826+ } , 0 ) ;
827+ } ;
828+ const topLevelSingleShardAssignments = ( ( ) => {
829+ if ( shardIndexOverride === null || shardCount <= 1 ) {
830+ return new Map ( ) ;
831+ }
832+
833+ // Single-file and other non-shardable explicit lanes would otherwise run on
834+ // every shard. Assign them to one top-level shard instead.
835+ const entriesNeedingAssignment = runs . filter ( ( entry ) => {
836+ const explicitFilterCount = countExplicitEntryFilters ( entry . args ) ;
837+ if ( explicitFilterCount === null ) {
838+ return false ;
839+ }
840+ const effectiveShardCount = Math . min ( shardCount , Math . max ( 1 , explicitFilterCount - 1 ) ) ;
841+ return effectiveShardCount <= 1 ;
842+ } ) ;
843+
844+ const assignmentMap = new Map ( ) ;
845+ const buckets = packFilesByDuration (
846+ entriesNeedingAssignment ,
847+ shardCount ,
848+ estimateTopLevelEntryDurationMs ,
849+ ) ;
850+ for ( const [ bucketIndex , bucket ] of buckets . entries ( ) ) {
851+ for ( const entry of bucket ) {
852+ assignmentMap . set ( entry , bucketIndex + 1 ) ;
853+ }
854+ }
855+ return assignmentMap ;
856+ } ) ( ) ;
810857// Node 25 local runs still show cross-process worker shutdown contention even
811858// after moving the known heavy files into singleton lanes.
812859const topLevelParallelEnabled =
@@ -1258,6 +1305,13 @@ const runOnce = (entry, extraArgs = []) =>
12581305
12591306const run = async ( entry , extraArgs = [ ] ) => {
12601307 const explicitFilterCount = countExplicitEntryFilters ( entry . args ) ;
1308+ const topLevelAssignedShard = topLevelSingleShardAssignments . get ( entry ) ;
1309+ if ( topLevelAssignedShard !== undefined ) {
1310+ if ( shardIndexOverride !== null && shardIndexOverride !== topLevelAssignedShard ) {
1311+ return 0 ;
1312+ }
1313+ return runOnce ( entry , extraArgs ) ;
1314+ }
12611315 // Vitest requires the shard count to stay strictly below the number of
12621316 // resolved test files, so explicit-filter lanes need a `< fileCount` cap.
12631317 const effectiveShardCount =
0 commit comments