Skip to content

Commit 8035a14

Browse files
committed
test(desktop): strip comments at read time so positive assertions can fail
Cursor caught the mirror of a trap this file already documents. `stripComments` was applied to negative assertions only, so a positive like `toContain('desktop-title-bar-page')` still ran on raw source — and `AuthShell`'s TSDoc names that class, so deleting it from the markup left the assertion passing on a broken lane reservation. Stripping now happens in `read`, so every audit constant is comment-free and no assertion in either direction can match prose. Verified: deleting the class from the markup while leaving the TSDoc intact now fails two tests, where it previously failed none.
1 parent 89415b1 commit 8035a14

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

apps/sim/app/_shell/desktop-title-bar-surfaces.test.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,30 @@
44
import { readdirSync, readFileSync } from 'node:fs'
55
import { 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
*/
1825
const 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+
2131
const authLayout = read('../(auth)/layout.tsx')
2232
const authShell = read('../(auth)/components/auth-shell.tsx')
2333
const 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(/PEEK_CARD_CHROME[\s\S]{0,240}?bottom-2/)
122+
expect(workspaceChrome).not.toMatch(/PEEK_CARD_CHROME[\s\S]{0,240}?bottom-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(/\.desktop-title-bar-page \{[^}]*\}/)?.[0] ?? '')
130+
const rule = globalStyles.match(/\.desktop-title-bar-page \{[^}]*\}/)?.[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(min-h-screen|h-screen)\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') && !/<DesktopTitleBarLane\b/.test(source)

0 commit comments

Comments
 (0)