@@ -177,6 +177,67 @@ describe('package boundary command', () => {
177177 } )
178178 } )
179179
180+ it ( 'keeps platform/lib from importing a route, even for a type' , ( ) => {
181+ withFixture ( ( fixture , audit ) => {
182+ const cases = [
183+ [ "import { Row } from '@/app/o/[organizationId]/row'" , false ] ,
184+ [ "import type { Row } from '@/app/o/[organizationId]/model'" , false ] ,
185+ [ "export { Row } from '../../../app/o/[organizationId]/row'" , false ] ,
186+ [ "const row = import('@/app/o/[organizationId]/row')" , false ] ,
187+ [ "import { value } from '@/app/other/value'" , true ] ,
188+ [ "import { value } from '@/lib/organizations/value'" , true ] ,
189+ ] as const
190+ for ( const [ source , allowed ] of cases ) {
191+ writeFileSync ( path . join ( fixture , LIB_FILE ) , `${ source } \n` )
192+ const result = audit ( )
193+ expect . soft ( result . status , `${ source } \n${ result . stderr } ` ) . toBe ( allowed ? 0 : 1 )
194+ if ( ! allowed ) expect . soft ( result . stderr ) . toContain ( `${ LIB_FILE } :1` )
195+ }
196+ writeFileSync ( path . join ( fixture , LIB_FILE ) , "import { Row } from '@/app/o/row'\n" )
197+ audit ( '--update' , '--init' )
198+ expect ( audit ( ) . status ) . toBe ( 1 )
199+ } )
200+ } )
201+
202+ it ( 'keeps the rest of platform from importing a route, even for a type' , ( ) => {
203+ withFixture ( ( fixture , audit ) => {
204+ const designFile = 'apps/sim/platform/design-system/widget.tsx'
205+ mkdirSync ( path . join ( fixture , 'apps/sim/platform/design-system' ) , { recursive : true } )
206+ for ( const file of [ VIEW_FILE , designFile ] ) {
207+ const cases = [
208+ [ "import { Row } from '@/app/o/[organizationId]/row'" , false ] ,
209+ [ "import type { Row } from '@/app/o/[organizationId]/model'" , false ] ,
210+ [ "const row = import('@/app/o/[organizationId]/row')" , false ] ,
211+ [ "import { Row } from '@/app/workspace/[workspaceId]/row'" , true ] ,
212+ ] as const
213+ for ( const [ source , allowed ] of cases ) {
214+ writeFileSync ( path . join ( fixture , file ) , `${ source } \n` )
215+ const result = audit ( )
216+ expect . soft ( result . status , `${ source } \n${ result . stderr } ` ) . toBe ( allowed ? 0 : 1 )
217+ if ( ! allowed ) expect . soft ( result . stderr ) . toContain ( `${ file } :1` )
218+ }
219+ rmSync ( path . join ( fixture , file ) )
220+ }
221+ } )
222+ } )
223+
224+ it ( 'keeps platform/lib from importing the workspace surface, even for a type' , ( ) => {
225+ withFixture ( ( fixture , audit ) => {
226+ const cases = [
227+ [ "import { Row } from '@/app/workspace/[workspaceId]/row'" , false ] ,
228+ [ "import type { Row } from '@/app/workspace/[workspaceId]/model'" , false ] ,
229+ [ "const row = import('@/app/workspace/providers/row')" , false ] ,
230+ [ "import { value } from '@/hooks/use-value'" , true ] ,
231+ ] as const
232+ for ( const [ source , allowed ] of cases ) {
233+ writeFileSync ( path . join ( fixture , LIB_FILE ) , `${ source } \n` )
234+ const result = audit ( )
235+ expect . soft ( result . status , `${ source } \n${ result . stderr } ` ) . toBe ( allowed ? 0 : 1 )
236+ if ( ! allowed ) expect . soft ( result . stderr ) . toContain ( `${ LIB_FILE } :1` )
237+ }
238+ } )
239+ } )
240+
180241 it ( 'keeps a view from reading data around platform/lib/data' , ( ) => {
181242 withFixture ( ( fixture , audit ) => {
182243 const cases = [
@@ -213,7 +274,9 @@ describe('package boundary command', () => {
213274 writeFileSync ( path . join ( fixture , VIEW_FILE ) , two )
214275 expect ( audit ( '--update' ) . status ) . toBe ( 1 )
215276 expect ( audit ( '--update' , '--init' ) . status ) . toBe ( 0 )
216- expect ( JSON . parse ( readFileSync ( baselinePath , 'utf8' ) ) ) . toEqual ( { [ VIEW_FILE ] : 2 } )
277+ expect ( JSON . parse ( readFileSync ( baselinePath , 'utf8' ) ) . viewDataHooks ) . toEqual ( {
278+ [ VIEW_FILE ] : 2 ,
279+ } )
217280 expect ( audit ( ) . status ) . toBe ( 0 )
218281
219282 writeFileSync (
@@ -222,12 +285,44 @@ describe('package boundary command', () => {
222285 )
223286 expect ( audit ( ) . status ) . toBe ( 1 )
224287 expect ( audit ( '--update' ) . status ) . toBe ( 1 )
225- expect ( JSON . parse ( readFileSync ( baselinePath , 'utf8' ) ) ) . toEqual ( { [ VIEW_FILE ] : 2 } )
288+ expect ( JSON . parse ( readFileSync ( baselinePath , 'utf8' ) ) . viewDataHooks ) . toEqual ( {
289+ [ VIEW_FILE ] : 2 ,
290+ } )
226291
227292 writeFileSync ( path . join ( fixture , VIEW_FILE ) , one )
228293 expect ( audit ( ) . status ) . toBe ( 1 )
229294 expect ( audit ( '--update' ) . status ) . toBe ( 0 )
230- expect ( JSON . parse ( readFileSync ( baselinePath , 'utf8' ) ) ) . toEqual ( { [ VIEW_FILE ] : 1 } )
295+ expect ( JSON . parse ( readFileSync ( baselinePath , 'utf8' ) ) . viewDataHooks ) . toEqual ( {
296+ [ VIEW_FILE ] : 1 ,
297+ } )
298+ expect ( audit ( ) . status ) . toBe ( 0 )
299+ } )
300+ } )
301+
302+ it . each ( [
303+ [ 'platformToRoutes' , VIEW_FILE , '@/app/o/[organizationId]/row' ] ,
304+ [ 'platformLibToWorkspace' , LIB_FILE , '@/app/workspace/[workspaceId]/row' ] ,
305+ ] ) ( 'ratchets %s: a new edge fails, and the baseline only shrinks' , ( ratchet , file , target ) => {
306+ withFixture ( ( fixture , audit ) => {
307+ const baselinePath = path . join ( fixture , 'scripts/check-monorepo-boundaries.baseline.json' )
308+ const counts = ( ) => JSON . parse ( readFileSync ( baselinePath , 'utf8' ) ) [ ratchet ]
309+ const one = `import { a } from '${ target } '\n`
310+ const two = `${ one } import type { b } from '${ target } '\n`
311+
312+ writeFileSync ( path . join ( fixture , file ) , two )
313+ expect ( audit ( '--update' , '--init' ) . status ) . toBe ( 0 )
314+ expect ( counts ( ) ) . toEqual ( { [ file ] : 2 } )
315+ expect ( audit ( ) . status ) . toBe ( 0 )
316+
317+ writeFileSync ( path . join ( fixture , file ) , `${ two } import { c } from '${ target } '\n` )
318+ expect ( audit ( ) . status ) . toBe ( 1 )
319+ expect ( audit ( '--update' ) . status ) . toBe ( 1 )
320+ expect ( counts ( ) ) . toEqual ( { [ file ] : 2 } )
321+
322+ writeFileSync ( path . join ( fixture , file ) , one )
323+ expect ( audit ( ) . status ) . toBe ( 1 )
324+ expect ( audit ( '--update' ) . status ) . toBe ( 0 )
325+ expect ( counts ( ) ) . toEqual ( { [ file ] : 1 } )
231326 expect ( audit ( ) . status ) . toBe ( 0 )
232327 } )
233328 } )
0 commit comments