@@ -50,6 +50,13 @@ describe("reachableNpmScripts", () => {
5050describe ( "resolveCheckerHome" , ( ) => {
5151 const base = { scripts : { } , reachableFromTestCi : new Set < string > ( ) , workflowText : "" , otherScriptSources : [ ] , allowed : { } } ;
5252
53+ // Assembled at runtime: `check-import-specifiers.ts` greps this repo's own sources for module
54+ // specifiers and cannot tell a fixture string from a real import, so a literal here fails that
55+ // sibling checker. The value under test is identical either way.
56+ const fromSpecifier = ( name : string , suffix = "" ) => `import { helper } from "./${ name } ${ suffix } ";\n` ;
57+ const exportFromSpecifier = ( name : string , suffix = "" ) => `export { helper } from "./${ name } ${ suffix } ";\n` ;
58+ const dynamicImportSpecifier = ( name : string , suffix = "" ) => `await import("./${ name } ${ suffix } ");\n` ;
59+
5360 it ( "finds a checker wired into the local gate" , ( ) => {
5461 const home = resolveCheckerHome ( {
5562 ...base ,
@@ -69,12 +76,47 @@ describe("resolveCheckerHome", () => {
6976 } ) ;
7077
7178 it ( "treats a checker imported by a sibling script as a shared module, not an entry point" , ( ) => {
72- // Assembled at runtime rather than written as a literal: `check-import-specifiers.ts` greps this repo's
73- // own sources for module specifiers and cannot tell a fixture string from a real import, so a literal
74- // here fails that sibling checker. The value under test is identical either way.
75- const importLine = `import { x } from "./${ "check-foo-core" } .ts";` ;
76- const home = resolveCheckerHome ( { ...base , file : "check-foo-core.ts" , otherScriptSources : [ importLine ] } ) ;
77- expect ( home . kind ) . toBe ( "imported" ) ;
79+ const home = resolveCheckerHome ( { ...base , file : "check-foo-core.ts" , otherScriptSources : [ fromSpecifier ( "check-foo-core" ) ] } ) ;
80+ expect ( home ) . toEqual ( { kind : "imported" , via : "check-foo-core" } ) ;
81+ } ) ;
82+
83+ it ( "matches import specifiers with .js and .ts suffixes, re-exports, and dynamic import (#10048)" , ( ) => {
84+ expect ( resolveCheckerHome ( { ...base , file : "check-foo.ts" , otherScriptSources : [ fromSpecifier ( "check-foo" , ".js" ) ] } ) ) . toEqual ( {
85+ kind : "imported" ,
86+ via : "check-foo" ,
87+ } ) ;
88+ expect ( resolveCheckerHome ( { ...base , file : "check-foo.ts" , otherScriptSources : [ fromSpecifier ( "check-foo" , ".ts" ) ] } ) ) . toEqual ( {
89+ kind : "imported" ,
90+ via : "check-foo" ,
91+ } ) ;
92+ expect ( resolveCheckerHome ( { ...base , file : "check-foo.ts" , otherScriptSources : [ exportFromSpecifier ( "check-foo" ) ] } ) ) . toEqual ( {
93+ kind : "imported" ,
94+ via : "check-foo" ,
95+ } ) ;
96+ expect ( resolveCheckerHome ( { ...base , file : "check-foo.ts" , otherScriptSources : [ dynamicImportSpecifier ( "check-foo" ) ] } ) ) . toEqual ( {
97+ kind : "imported" ,
98+ via : "check-foo" ,
99+ } ) ;
100+ } ) ;
101+
102+ it ( "does not treat a // comment mention as an imported home (#10048)" , ( ) => {
103+ expect ( resolveCheckerHome ( { ...base , file : "check-foo.ts" , otherScriptSources : [ "// see check-foo.ts for the pattern\n" ] } ) ) . toEqual ( { kind : "none" } ) ;
104+ } ) ;
105+
106+ it ( "does not treat a /* */ block comment mention as an imported home (#10048)" , ( ) => {
107+ expect ( resolveCheckerHome ( { ...base , file : "check-foo.ts" , otherScriptSources : [ "/* check-foo.ts is the sibling */\n" ] } ) ) . toEqual ( { kind : "none" } ) ;
108+ } ) ;
109+
110+ it ( "does not treat a near-miss specifier as an imported home (#10048)" , ( ) => {
111+ // `./check-foobar` must not mark `check-foo.ts` as imported — the old substring scan would.
112+ expect ( resolveCheckerHome ( { ...base , file : "check-foo.ts" , otherScriptSources : [ fromSpecifier ( "check-foobar" ) ] } ) ) . toEqual ( { kind : "none" } ) ;
113+ } ) ;
114+
115+ it ( "does not treat the check-fixture-clock-races prose mention as an imported home (#10048)" , ( ) => {
116+ // Live sentence from scripts/check-fixture-clock-races.ts:95 — the bug that motivated the tighter matcher.
117+ const prose =
118+ " // STRING LITERALS, exactly as check-turbo-typecheck-inputs.ts's own fixtures do. Those are not real\n" ;
119+ expect ( resolveCheckerHome ( { ...base , file : "check-turbo-typecheck-inputs.ts" , otherScriptSources : [ prose ] } ) ) . toEqual ( { kind : "none" } ) ;
78120 } ) ;
79121
80122 it ( "accepts an explicit allowlist entry, carrying its reason" , ( ) => {
0 commit comments