22//
33// node scripts/jtreg/select.ts [<base> | --full]
44//
5- // Prints GitHub Actions outputs: `filters`, the test areas to pass to run.ts
6- // (empty for all of them), and `shards`, a JSON list of shard numbers ([] when
7- // no test is needed). A changed file this does not know runs every test.
5+ // Prints GitHub Actions outputs: `filters`, the tests to pass to run.ts (empty
6+ // for all of them), and `shards`, a JSON list of shard numbers ([] when no test
7+ // is needed). Tests added to passing.txt run alone; a change to anything the
8+ // tests load runs them all.
89
910import { execFileSync } from "node:child_process" ;
1011import { readFileSync } from "node:fs" ;
11- import { join } from "node:path" ;
12+ import { dirname , join } from "node:path" ;
1213
1314const root = join ( import . meta. dirname , ".." , ".." ) ;
1415const passingFile = "test/jtreg/passing.txt" ;
1516
16- // first match wins; null runs no test
17- const areas : [ RegExp , string [ ] | null ] [ ] = [
18- [ / \. m d $ | ^ d o c s \/ | ^ L I C E N S E | ^ r e n o v a t e \. j s o n $ | ^ \. c o d e r a b b i t / , null ] ,
19- [ / ^ s r c \/ b r o w s e r \/ | ^ s r c \/ ( b r i d g e | l i b r a r y | i m a g e | h t t p - p r o x y ) \. t s $ | ^ t y p e s \/ | ^ s c r i p t s \/ ( b u i l d - w e b | s e r v e ) \. t s $ / , null ] ,
20- [ / ^ t e s t \/ (? ! j t r e g \/ ) / , null ] ,
21- [ / ^ s r c \/ n a t i v e s \/ z i p \. t s $ | ^ s r c \/ i n f l a t e \. t s $ / , [ "java/util/zip" , "java/util/jar" ] ] ,
22- [ / ^ s r c \/ n a t i v e s \/ ( i o | n i o ) \. t s $ | ^ s r c \/ f s \. t s $ / , [ "java/io" , "java/nio" , "java/util/zip" , "java/util/jar" ] ] ,
23- [ / ^ s r c \/ n a t i v e s \/ ( n e t | s o c k e t s ) \. t s $ | ^ s r c \/ ( s o c k e t s | n e t - n o d e ) \. t s $ | ^ s c r i p t s \/ t l s \/ / , [ "java/net" , "java/nio/channels" ] ] ,
24- [ / ^ s r c \/ n a t i v e s \/ ( f o n t | j a v a 2 d ) [ \w - ] * \. t s $ / , [ "java/awt" , "java/beans" ] ] ,
25- [ / ^ s r c \/ n a t i v e s \/ m a n a g e m e n t \. t s $ / , [ "java/lang/management" ] ] ,
26- ] ;
17+ // TypeScript the tests load: everything src/node.ts (the VM each test runs on),
18+ // the runner and this selection import, followed through their imports. Other .ts files under
19+ // src/ and scripts/ (the page API, the web build) cannot change a test's result.
20+ function loaded ( ) : Set < string > {
21+ const seen = new Set < string > ( ) ;
22+ const visit = ( file : string ) => {
23+ if ( seen . has ( file ) ) return ;
24+ seen . add ( file ) ;
25+ const text = readFileSync ( join ( root , file ) , "utf8" ) ;
26+ for ( const m of text . matchAll ( / (?: f r o m | i m p o r t ) \s * \( ? \s * [ " ' ] ( \. { 1 , 2 } \/ [ ^ " ' ] + \. t s ) [ " ' ] / g) ) visit ( join ( dirname ( file ) , m [ 1 ] ) ) ;
27+ } ;
28+ visit ( "src/node.ts" ) ;
29+ visit ( "scripts/jtreg/run.ts" ) ;
30+ visit ( "scripts/jtreg/select.ts" ) ;
31+ return seen ;
32+ }
33+ const notLoaded = / \. m d $ | ^ d o c s \/ | ^ L I C E N S E | ^ r e n o v a t e \. j s o n $ | ^ \. c o d e r a b b i t | ^ t y p e s \/ | ^ t e s t \/ (? ! j t r e g \/ ) / ;
2734
2835const shardsFor = ( n : number ) => Array . from ( { length : Math . min ( 4 , Math . ceil ( n / 400 ) ) } , ( _ , i ) => i + 1 ) ;
2936const listed = readFileSync ( join ( root , passingFile ) , "utf8" ) . split ( "\n" ) . map ( ( l ) => l . trim ( ) ) . filter ( ( l ) => l && ! l . startsWith ( "#" ) ) ;
@@ -33,6 +40,7 @@ function select(base: string | undefined): string[] | "all" {
3340 if ( ! base ) return "all" ;
3441 const git = ( ...args : string [ ] ) => execFileSync ( "git" , args , { cwd : root , encoding : "utf8" } ) ;
3542 const filters = new Set < string > ( ) ;
43+ let graph : Set < string > | undefined ;
3644 for ( const file of git ( "diff" , "--name-only" , "--no-renames" , `${ base } ...HEAD` ) . split ( "\n" ) . filter ( Boolean ) ) {
3745 if ( file === passingFile ) {
3846 // the tests it adds
@@ -41,9 +49,8 @@ function select(base: string | undefined): string[] | "all" {
4149 }
4250 continue ;
4351 }
44- const hit = areas . find ( ( [ re ] ) => re . test ( file ) ) ;
45- if ( ! hit ) return "all" ;
46- for ( const f of hit [ 1 ] ?? [ ] ) filters . add ( f ) ;
52+ const ts = / ^ ( s r c | s c r i p t s ) \/ .* \. t s $ / . test ( file ) ;
53+ if ( ts ? ( graph ??= loaded ( ) ) . has ( file ) : ! notLoaded . test ( file ) ) return "all" ;
4754 }
4855 return [ ...filters ] ;
4956}
0 commit comments