@@ -9,8 +9,15 @@ import {
99
1010const COLLECTOR = 'packages/replay-port/src/source-discovery.ts' ;
1111
12+ /** Every denied module exists as a stub, so a case fails only on what it plants. */
1213function reach ( sources : Record < string , string > ) {
13- return checkDaemonProcessReach ( resolveImportEdges ( new Map ( Object . entries ( sources ) ) ) ) ;
14+ const tree = new Map < string , string > ( [
15+ ...DAEMON_PROCESS_DENIED_MODULES . map (
16+ ( module ) => [ module , 'export const collect = 1;\n' ] as const ,
17+ ) ,
18+ ...Object . entries ( sources ) ,
19+ ] ) ;
20+ return checkDaemonProcessReach ( [ ...tree . keys ( ) ] , resolveImportEdges ( tree ) ) ;
1421}
1522
1623test ( 'the denied set names replay-port caller-side collector modules' , ( ) => {
@@ -21,22 +28,38 @@ test('the denied set names replay-port caller-side collector modules', () => {
2128 ] ) ;
2229} ) ;
2330
24- test ( 'a root platform-runtime module behind a dynamic import cannot reach the collector' , ( ) => {
25- const found = reach ( {
26- 'src/daemon.ts' : "export const load = () => import('./daemon-composition.ts');\n" ,
27- 'src/daemon-composition.ts' : "import './platform-runtime-daemon-services.ts';\n" ,
28- 'src/platform-runtime-daemon-services.ts' :
29- "import '../packages/replay-port/src/source-discovery.ts';\n" ,
30- [ COLLECTOR ] : 'export const collect = () => [];\n' ,
31+ for ( const denied of DAEMON_PROCESS_DENIED_MODULES ) {
32+ test ( `a root platform-runtime module behind a dynamic import cannot reach ${ denied } ` , ( ) => {
33+ const found = reach ( {
34+ 'src/daemon.ts' : "export const load = () => import('./daemon-composition.ts');\n" ,
35+ 'src/daemon-composition.ts' : "import './platform-runtime-daemon-services.ts';\n" ,
36+ 'src/platform-runtime-daemon-services.ts' : `import '../${ denied } ';\n` ,
37+ } ) ;
38+ assert . equal ( found . length , 1 ) ;
39+ assert . equal ( found [ 0 ] ! . rule , DAEMON_PROCESS_REACH_RULE ) ;
40+ assert . equal ( found [ 0 ] ! . file , 'src/platform-runtime-daemon-services.ts' ) ;
41+ assert . ok (
42+ found [ 0 ] ! . message . includes (
43+ `Chain: src/daemon.ts -> src/daemon-composition.ts -> src/platform-runtime-daemon-services.ts -> ${ denied } .` ,
44+ ) ,
45+ found [ 0 ] ! . message ,
46+ ) ;
3147 } ) ;
32- assert . equal ( found . length , 1 ) ;
33- assert . equal ( found [ 0 ] ! . rule , DAEMON_PROCESS_REACH_RULE ) ;
34- assert . equal ( found [ 0 ] ! . file , 'src/platform-runtime-daemon-services.ts' ) ;
35- assert . match (
36- found [ 0 ] ! . message ,
37- / s r c \/ d a e m o n \. t s - > s r c \/ d a e m o n - c o m p o s i t i o n \. t s - > s r c \/ p l a t f o r m - r u n t i m e - d a e m o n - s e r v i c e s \. t s - > p a c k a g e s \/ r e p l a y - p o r t \/ s r c \/ s o u r c e - d i s c o v e r y \. t s / ,
38- ) ;
39- } ) ;
48+
49+ test ( `a static-only chain from the entry cannot reach ${ denied } ` , ( ) => {
50+ const found = reach ( {
51+ 'src/daemon.ts' : "import './daemon-server.ts';\n" ,
52+ 'src/daemon-server.ts' : `import '../${ denied } ';\n` ,
53+ } ) ;
54+ assert . equal ( found . length , 1 ) ;
55+ assert . equal ( found [ 0 ] ! . file , 'src/daemon-server.ts' ) ;
56+ assert . equal ( found [ 0 ] ! . line , 1 ) ;
57+ assert . ok (
58+ found [ 0 ] ! . message . includes ( `Chain: src/daemon.ts -> src/daemon-server.ts -> ${ denied } .` ) ,
59+ found [ 0 ] ! . message ,
60+ ) ;
61+ } ) ;
62+ }
4063
4164test ( 'a type-only edge loads nothing, and the client may import the collector' , ( ) => {
4265 assert . deepEqual (
@@ -50,3 +73,16 @@ test('a type-only edge loads nothing, and the client may import the collector',
5073 [ ] ,
5174 ) ;
5275} ) ;
76+
77+ test ( 'a renamed entry or denied module fails as stale instead of passing silently' , ( ) => {
78+ const found = checkDaemonProcessReach (
79+ [ 'src/daemon.ts' , 'packages/replay-port/src/script-source-bundle.ts' ] ,
80+ [ ] ,
81+ ) ;
82+ assert . deepEqual (
83+ found . map ( ( violation ) => violation . message . split ( ' is not' ) [ 0 ] ) ,
84+ [ `stale module: ${ COLLECTOR } ` ] ,
85+ ) ;
86+ assert . equal ( found [ 0 ] ! . rule , DAEMON_PROCESS_REACH_RULE ) ;
87+ assert . equal ( checkDaemonProcessReach ( [ COLLECTOR ] , [ ] , 'src/daemon.ts' , [ COLLECTOR ] ) . length , 1 ) ;
88+ } ) ;
0 commit comments