@@ -34,10 +34,13 @@ let tmpRoot: string
3434
3535beforeEach ( ( ) => {
3636 tmpRoot = mkdtempSync ( path . join ( os . tmpdir ( ) , 'paths-mts-inherit-guard-' ) )
37- // Repo-root scripts/fleet/paths.mts — ancestor exists for sub-packages.
38- mkdirSync ( path . join ( tmpRoot , 'scripts' ) , { recursive : true } )
37+ // Repo-root scripts/fleet/paths.mts — the canonical ancestor after the
38+ // scripts/{fleet,repo} segmentation. findAncestorPathsMts must discover this
39+ // (not just the pre-segmentation scripts/paths.mts) so sub-packages stay
40+ // enforced.
41+ mkdirSync ( path . join ( tmpRoot , 'scripts' , 'fleet' ) , { recursive : true } )
3942 writeFileSync (
40- path . join ( tmpRoot , 'scripts' , 'paths.mts' ) ,
43+ path . join ( tmpRoot , 'scripts' , 'fleet' , ' paths.mts') ,
4144 "export const REPO_ROOT = '/tmp/fake'\n" ,
4245 )
4346} )
@@ -70,7 +73,7 @@ describe('paths-mts-inherit-guard', () => {
7073 const r = runHook ( {
7174 tool_name : 'Write' ,
7275 tool_input : {
73- file_path : path . join ( tmpRoot , 'scripts' , 'paths.mts' ) ,
76+ file_path : path . join ( tmpRoot , 'scripts' , 'fleet' , ' paths.mts') ,
7477 content : "export const X = 'no inheritance needed at root'\n" ,
7578 } ,
7679 } )
@@ -99,6 +102,32 @@ describe('paths-mts-inherit-guard', () => {
99102 assert . match ( r . stderr , / e x p o r t \* f r o m / )
100103 } )
101104
105+ test ( 'discovers the ancestor at scripts/fleet/paths.mts (post-segmentation)' , ( ) => {
106+ // Regression: before findAncestorPathsMts learned the scripts/fleet/
107+ // location, a sub-package whose only ancestor lives at
108+ // scripts/fleet/paths.mts (the segmented repo-root module) was wrongly
109+ // treated as having NO ancestor → silently exempt. The block must fire,
110+ // and the suggested re-export must point at the fleet location.
111+ mkdirSync ( path . join ( tmpRoot , 'packages' , 'seg' , 'scripts' ) , {
112+ recursive : true ,
113+ } )
114+ const r = runHook ( {
115+ tool_name : 'Write' ,
116+ tool_input : {
117+ file_path : path . join (
118+ tmpRoot ,
119+ 'packages' ,
120+ 'seg' ,
121+ 'scripts' ,
122+ 'paths.mts' ,
123+ ) ,
124+ content : "export const REDERIVED = 'wrong'\n" ,
125+ } ,
126+ } )
127+ assert . equal ( r . code , 2 )
128+ assert . match ( r . stderr , / s c r i p t s \/ f l e e t \/ p a t h s \. m t s / )
129+ } )
130+
102131 test ( 'allows sub-package paths.mts WITH export *' , ( ) => {
103132 mkdirSync ( path . join ( tmpRoot , 'packages' , 'foo' , 'scripts' ) , {
104133 recursive : true ,
@@ -114,7 +143,7 @@ describe('paths-mts-inherit-guard', () => {
114143 'paths.mts' ,
115144 ) ,
116145 content :
117- "export * from '../../../scripts/paths.mts'\nexport const FOO_DIST = '/x'\n" ,
146+ "export * from '../../../scripts/fleet/ paths.mts'\nexport const FOO_DIST = '/x'\n" ,
118147 } ,
119148 } )
120149 assert . equal ( r . code , 0 )
@@ -133,7 +162,7 @@ describe('paths-mts-inherit-guard', () => {
133162 )
134163 writeFileSync (
135164 subPath ,
136- "export * from '../../../scripts/paths.mts'\nexport const OLD = '/x'\n" ,
165+ "export * from '../../../scripts/fleet/ paths.mts'\nexport const OLD = '/x'\n" ,
137166 )
138167 const r = runHook ( {
139168 tool_name : 'Edit' ,
@@ -147,7 +176,11 @@ describe('paths-mts-inherit-guard', () => {
147176 assert . equal ( r . code , 0 )
148177 } )
149178
150- test ( 'allows paths.cts variant' , ( ) => {
179+ test ( 'allows paths.cts variant (and the pre-segmentation export * target)' , ( ) => {
180+ // The guard checks the textual export * line; it does NOT resolve the
181+ // target to disk. So a sub-package re-exporting the OLD pre-segmentation
182+ // path string still satisfies inheritance — un-migrated repos aren't
183+ // suddenly blocked. (The on-disk ancestor here is scripts/fleet/paths.mts.)
151184 mkdirSync ( path . join ( tmpRoot , 'packages' , 'cjs' , 'scripts' ) , {
152185 recursive : true ,
153186 } )
0 commit comments