44import { readdirSync , readFileSync } from 'node:fs'
55import { describe , expect , it } from 'vitest'
66
7- /** Anchored to this file, not `process.cwd()`, which only resolves from `apps/sim`. */
8- const read = ( relativePath : string ) => readFileSync ( new URL ( relativePath , import . meta. url ) , 'utf8' )
7+ /** Raw file contents, anchored to this file rather than `process.cwd()`. */
8+ const readRaw = ( relativePath : string ) =>
9+ readFileSync ( new URL ( relativePath , import . meta. url ) , 'utf8' )
910
1011/**
1112 * Source with comments removed.
1213 *
13- * Every negative assertion here must run through this. These files document the shapes
14- * they deliberately avoid, so a bare `not.toContain('min-h-screen')` matches the prose
15- * explaining why `min-h-screen` is gone and fails on correct code. The mirror case is
16- * worse: prose containing a wanted token makes a positive assertion pass on broken code.
14+ * EVERY assertion here runs on stripped source — which is why {@link read} strips at the
15+ * point of reading rather than leaving it to each callsite. These files document the very
16+ * shapes they enforce, in both directions:
17+ *
18+ * - a negative like `not.toContain('min-h-screen')` matches the prose explaining why
19+ * `min-h-screen` is gone, and fails on correct code;
20+ * - a positive like `toContain('desktop-title-bar-page')` matches the TSDoc naming the
21+ * class, and passes even after the class is deleted from the markup.
22+ *
23+ * The second is the dangerous one, and stripping only negatives left it live.
1724 */
1825const stripComments = ( source : string ) =>
1926 source . replace ( / \/ \* [ \s \S ] * ?\* \/ / g, '' ) . replace ( / ^ \s * \/ \/ .* $ / gm, '' )
2027
28+ /** Every audit constant below reads through this, so no assertion can match prose. */
29+ const read = ( relativePath : string ) => stripComments ( readRaw ( relativePath ) )
30+
2131const authLayout = read ( '../(auth)/layout.tsx' )
2232const authShell = read ( '../(auth)/components/auth-shell.tsx' )
2333const workspaceChrome = read (
@@ -42,8 +52,8 @@ describe('desktop title-bar surface audit', () => {
4252 // `/invite/[id]` either, so the shell owns the lane unconditionally.
4353 expect ( authShell ) . toContain ( 'desktop-title-bar-page' )
4454 expect ( authShell ) . toContain ( '<DesktopTitleBarLane />' )
45- expect ( stripComments ( authShell ) ) . not . toContain ( 'reserveDesktopTitleBar' )
46- expect ( stripComments ( authShell ) ) . not . toContain ( 'min-h-screen' )
55+ expect ( authShell ) . not . toContain ( 'reserveDesktopTitleBar' )
56+ expect ( authShell ) . not . toContain ( 'min-h-screen' )
4757 expect ( authLayout ) . toContain ( '<AuthShell>' )
4858 } )
4959
@@ -109,15 +119,15 @@ describe('desktop title-bar surface audit', () => {
109119 // tall empty slab over the content. It now hugs its content and caps at the pane
110120 // height less the lane and the bottom gutter, so a long list still scrolls.
111121 expect ( workspaceChrome ) . toContain ( 'max-h-[calc(100%-var(--desktop-title-bar-height)-8px)]' )
112- expect ( stripComments ( workspaceChrome ) ) . not . toMatch ( / P E E K _ C A R D _ C H R O M E [ \s \S ] { 0 , 240 } ?b o t t o m - 2 / )
122+ expect ( workspaceChrome ) . not . toMatch ( / P E E K _ C A R D _ C H R O M E [ \s \S ] { 0 , 240 } ?b o t t o m - 2 / )
113123 } )
114124
115125 it ( 'reserves the login lane inside the box, never as a collapsing margin' , ( ) => {
116126 // `body` carries `min-height: 100vh`, and a `margin-top` here collapses through it
117127 // (body is a plain block box, so it opens no BFC) and displaces body itself. The
118128 // document then measured one full lane taller than the viewport, which is what made
119129 // the desktop login page scroll. Verified live: 40px of overflow, now 0.
120- const rule = stripComments ( globalStyles . match ( / \. d e s k t o p - t i t l e - b a r - p a g e \{ [ ^ } ] * \} / ) ?. [ 0 ] ?? '' )
130+ const rule = globalStyles . match ( / \. d e s k t o p - t i t l e - b a r - p a g e \{ [ ^ } ] * \} / ) ?. [ 0 ] ?? ''
121131 expect ( rule ) . toContain ( 'padding-top: var(--desktop-title-bar-height)' )
122132 expect ( rule ) . toContain ( 'min-height: 100vh' )
123133 expect ( rule ) . not . toContain ( 'margin-top' )
@@ -188,7 +198,7 @@ describe('desktop traffic-light lane coverage', () => {
188198 . map ( ( f ) => `app/${ f } ` )
189199
190200 const unaccounted = files . filter ( ( file ) => {
191- const source = stripComments ( read ( `../${ file . slice ( 'app/' . length ) } ` ) )
201+ const source = read ( `../${ file . slice ( 'app/' . length ) } ` )
192202 const fillsViewport = / \b ( m i n - h - s c r e e n | h - s c r e e n ) \b / . test ( source )
193203 if ( ! fillsViewport ) return false
194204 // Composition counts: a surface is covered if it wears a shell that reserves the
@@ -209,7 +219,7 @@ describe('desktop traffic-light lane coverage', () => {
209219 . filter ( ( f ) => f . endsWith ( '.tsx' ) )
210220 . map ( ( f ) => `app/${ f } ` )
211221 . filter ( ( file ) => {
212- const source = stripComments ( read ( `../${ file . slice ( 'app/' . length ) } ` ) )
222+ const source = read ( `../${ file . slice ( 'app/' . length ) } ` )
213223 // The class alone clears the lights but leaves the strip undraggable, so the
214224 // window loses its title bar on that page. Shipped that way twice in this PR.
215225 return source . includes ( 'desktop-title-bar-page' ) && ! / < D e s k t o p T i t l e B a r L a n e \b / . test ( source )
0 commit comments