scrollbar-styles.client.spec.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. /**
  2. * Scrollbar stylesheet contract, asserted against the CSS text on disk: every
  3. * --dsw-alias-scrollbar-* token design-platform.css defines has a consumer,
  4. * scrollbar.css binds the base-surface pair through the rebindable
  5. * indirection, the width variable mirrors the ::-webkit-scrollbar rule for
  6. * consumers that align beside the bar, and elevated surfaces rebind that
  7. * indirection in complete pairs. The expected token set is scanned out of
  8. * design-platform.css, so adding, renaming, or dropping a scrollbar token
  9. * moves these assertions with it.
  10. */
  11. import { readFileSync } from 'node:fs'
  12. import { fileURLToPath } from 'node:url'
  13. import { describe, expect, it } from 'vitest'
  14. import { atRuleBlock, type CssRule, packageStylesheets, parseRules, varReferences } from './stylesheet-scan.ts'
  15. const STYLES = new URL('../src/styles/', import.meta.url)
  16. const read = (name: string): string => readFileSync(fileURLToPath(new URL(name, STYLES)), 'utf8')
  17. const platformCss = read('design-platform.css')
  18. const scrollbarCss = read('scrollbar.css')
  19. /** Body attribute selecting the dark palette; ui-layout's ThemePresenter sets it. */
  20. const DARK_ATTRIBUTE = '[data-ds-dark-theme]'
  21. /** Alias tokens under test: the prefix the elevation pairs share. */
  22. const TOKEN_PREFIX = '--dsw-alias-scrollbar-'
  23. /** Prefix of the rebindable indirection scrollbar.css owns. */
  24. const INDIRECTION_PREFIX = '--dsh-scrollbar-'
  25. /** The one non-token rebind value: a surface that draws no thumb at all. */
  26. const HIDDEN_THUMB = 'transparent'
  27. /** The elevation rebind, spelled per property: value-wholeness, not token shape. */
  28. const ELEVATED_REBIND = new Map([
  29. ['--dsh-scrollbar-thumb', '--dsw-alias-scrollbar-bg-l2'],
  30. ['--dsh-scrollbar-thumb-hover', '--dsw-alias-scrollbar-hover-l2'],
  31. ].map(([property, token]) => [property!, `var(${token!})`]))
  32. /**
  33. * Tokens a stylesheet reads through its rendering declarations, following its
  34. * own custom-property definitions transitively so a token reached only through
  35. * an indirection counts. The walk starts from the standard-property
  36. * declarations, so a defined-but-unread indirection contributes nothing.
  37. * @param rules - parsed rules of one stylesheet.
  38. * @returns every `--dsw-*` token the sheet's rendering declarations depend on.
  39. */
  40. function tokensRendered(rules: CssRule[]): Set<string> {
  41. const definitions = new Map<string, string>()
  42. const pending: string[] = []
  43. for (const rule of rules) {
  44. for (const [property, value] of rule.declarations) {
  45. if (property.startsWith('--')) definitions.set(property, value)
  46. else pending.push(value)
  47. }
  48. }
  49. const reached = new Set<string>()
  50. const visited = new Set<string>()
  51. while (pending.length > 0) {
  52. for (const name of varReferences(pending.pop()!)) {
  53. if (name.startsWith('--dsw-')) reached.add(name)
  54. if (visited.has(name)) continue
  55. visited.add(name)
  56. const definition = definitions.get(name)
  57. if (definition !== undefined) pending.push(definition)
  58. }
  59. }
  60. return reached
  61. }
  62. const platformRules = parseRules(platformCss)
  63. const scrollbarRules = parseRules(scrollbarCss)
  64. const sorted = (names: Iterable<string>): string[] => [...names].sort()
  65. /**
  66. * Scrollbar tokens defined by the rules whose selectors carry (or do not
  67. * carry) the dark palette attribute.
  68. * @param dark - true to scan the dark blocks, false to scan the light blocks.
  69. * @returns the scrollbar token names defined there.
  70. */
  71. function definedTokens(dark: boolean): Set<string> {
  72. const names = new Set<string>()
  73. for (const rule of platformRules) {
  74. if (rule.selectors.every(selector => selector.includes(DARK_ATTRIBUTE)) !== dark) continue
  75. for (const [property] of rule.declarations) {
  76. if (property.startsWith(TOKEN_PREFIX)) names.add(property)
  77. }
  78. }
  79. return names
  80. }
  81. const lightTokens = definedTokens(false)
  82. const darkTokens = definedTokens(true)
  83. const allTokens = new Set([...lightTokens, ...darkTokens])
  84. /** Every scrollbar token any package stylesheet references, mapped to the files referencing it. */
  85. const referencedTokens = new Map<string, string[]>()
  86. /** Every indirection property any package stylesheet outside ui-theme declares, mapped to its declaring rules. */
  87. const rebindRules: { file: string; rule: CssRule }[] = []
  88. /**
  89. * What one stylesheet contributes to the elevated-surface question: which
  90. * elevated surfaces it paints, whether any rule scrolls, and whether it
  91. * rebinds. Kept per file rather than per rule because the elevated card and the
  92. * descendant that actually scrolls are separate rules in the same sheet, and
  93. * CSS text does not express which contains which.
  94. */
  95. interface SheetSurfaces {
  96. /** Elevated surface tokens this sheet paints anywhere. */
  97. elevated: Set<string>
  98. /** True when some rule declares `overflow*: auto|scroll`. */
  99. scrolls: boolean
  100. /**
  101. * True when some rule rebinds the indirection to an ELEVATION. A rule that
  102. * only hides the bar (`transparent`) does not count: it states no elevation,
  103. * so a sheet that hides its bars and also scrolls on an elevated surface
  104. * still owes the l2 pair for whatever draws a thumb there.
  105. */
  106. rebindsElevation: boolean
  107. }
  108. const sheetSurfaces = new Map<string, SheetSurfaces>()
  109. /** Properties whose `auto`/`scroll` value makes a rule a scroll container. */
  110. const OVERFLOW_PROPERTIES = ['overflow', 'overflow-x', 'overflow-y']
  111. /** Properties that paint a surface, and so identify the elevation a rule sits on. */
  112. const SURFACE_PROPERTIES = ['background', 'background-color']
  113. /**
  114. * Token families that name a SURFACE — a background an element is drawn on, and
  115. * so something a scrollbar can sit against. `--dsw-alias-button-*`,
  116. * `--dsw-alias-interactive-*`, and `--dsw-alias-markdown-*` reach the same dark
  117. * elevation rungs while naming a control or an inline span, which no scroll
  118. * container renders its bar against (ChatView's floating `.toBottom` pill,
  119. * CodeBlock's banner). Family, not geometry: a floating button legitimately
  120. * carries a radius, a shadow, and a fixed size, so shape cannot separate them.
  121. */
  122. const SURFACE_TOKEN_PATTERN = /^--dsw-(?:alias-bg-|specific-)/
  123. /**
  124. * The palette's own dark elevation ladder, resolved from `design-platform.css`:
  125. * `bg-layer-2` and `bg-layer-3` are the rungs above the base surfaces, and the
  126. * l1/l2 scrollbar split encodes exactly that step. Reading it from the palette
  127. * rather than from the sheets that happen to rebind is what lets the check flag
  128. * a surface NOBODY has rebound yet.
  129. * @returns surface tokens whose dark value sits on an elevated rung.
  130. */
  131. function elevatedRungs(): Set<string> {
  132. const definitions = new Map<string, string>()
  133. for (const rule of platformRules) {
  134. // Dark declarations come later in the sheet and overwrite the light ones,
  135. // which is the palette this distinction exists in.
  136. for (const [property, value] of rule.declarations) definitions.set(property, value)
  137. }
  138. const resolve = (name: string): string => {
  139. const seen = new Set<string>()
  140. let current = name
  141. while (definitions.has(current) && !seen.has(current)) {
  142. seen.add(current)
  143. const value = definitions.get(current)!
  144. const [reference] = varReferences(value)
  145. if (reference === undefined) return value
  146. current = reference
  147. }
  148. return current
  149. }
  150. const rungs = new Set([resolve('--dsw-alias-bg-layer-2'), resolve('--dsw-alias-bg-layer-3')])
  151. const tokens = new Set<string>()
  152. for (const name of definitions.keys()) {
  153. if (SURFACE_TOKEN_PATTERN.test(name) && rungs.has(resolve(name))) tokens.add(name)
  154. }
  155. return tokens
  156. }
  157. const elevatedSurfaces = elevatedRungs()
  158. for (const file of packageStylesheets()) {
  159. const rules = parseRules(readFileSync(file, 'utf8'))
  160. const surfaces: SheetSurfaces = { elevated: new Set(), scrolls: false, rebindsElevation: false }
  161. for (const rule of rules) {
  162. let rebinds = false
  163. let rebindsElevation = false
  164. const ruleSurfaces: string[] = []
  165. for (const [property, value] of rule.declarations) {
  166. if (property.startsWith(INDIRECTION_PREFIX) && file !== fileURLToPath(new URL('scrollbar.css', STYLES))) {
  167. rebinds = true
  168. if (value !== HIDDEN_THUMB) rebindsElevation = true
  169. }
  170. if (OVERFLOW_PROPERTIES.includes(property) && /\b(?:auto|scroll)\b/.test(value)) surfaces.scrolls = true
  171. if (SURFACE_PROPERTIES.includes(property)) ruleSurfaces.push(...varReferences(value))
  172. for (const token of varReferences(value)) {
  173. if (!token.startsWith(TOKEN_PREFIX)) continue
  174. referencedTokens.set(token, [...referencedTokens.get(token) ?? [], file])
  175. }
  176. }
  177. for (const token of ruleSurfaces) {
  178. if (elevatedSurfaces.has(token)) surfaces.elevated.add(token)
  179. }
  180. if (rebinds) rebindRules.push({ file, rule })
  181. if (rebindsElevation) surfaces.rebindsElevation = true
  182. }
  183. sheetSurfaces.set(file, surfaces)
  184. }
  185. describe('design-platform.css scrollbar tokens', () => {
  186. it('defines the same scrollbar token set in the light and the dark block', () => {
  187. // A token present only in the light block silently keeps its light value
  188. // under the dark palette, since the dark block only overrides.
  189. expect(allTokens.size).toBeGreaterThan(0)
  190. expect(sorted(lightTokens)).toEqual(sorted(allTokens))
  191. expect(sorted(darkTokens)).toEqual(sorted(allTokens))
  192. })
  193. it('resolves every scrollbar token to a static scale value, not to another alias', () => {
  194. // The alias layer is the only indirection in the token sheet: an alias
  195. // pointing at a second alias makes the dark override order-dependent.
  196. for (const rule of platformRules) {
  197. for (const [property, value] of rule.declarations) {
  198. if (!property.startsWith(TOKEN_PREFIX)) continue
  199. for (const reference of varReferences(value)) {
  200. expect(reference, `${property}: ${value}`).toMatch(/^--dsw-static-/)
  201. }
  202. }
  203. }
  204. })
  205. })
  206. describe('scrollbar token consumers', () => {
  207. it('every defined scrollbar token is referenced by some package stylesheet', () => {
  208. // Before scrollbar.css existed these tokens had no consumer at all and
  209. // every scroll container rendered the unthemed UA bar. A fifth token, or a
  210. // rename on one side only, leaves the new name unreferenced here.
  211. expect(sorted(referencedTokens.keys())).toEqual(sorted(allTokens))
  212. })
  213. it('every referenced scrollbar token is defined in design-platform.css', () => {
  214. // A dangling var() renders the UA default instead of failing loudly, so a
  215. // rename has to move the reference and the definition together.
  216. for (const [token, files] of referencedTokens) {
  217. expect(allTokens, files.join(', ')).toContain(token)
  218. }
  219. })
  220. })
  221. describe('scrollbar.css base-surface binding', () => {
  222. const rendered = tokensRendered(scrollbarRules)
  223. it('renders the l1 pair through the rebindable indirection', () => {
  224. // l1 is the base-surface default the indirection resolves to; the
  225. // indirection only counts as bound when a rendering declaration reads it.
  226. expect(rendered).toContain(`${TOKEN_PREFIX}bg-l1`)
  227. expect(rendered).toContain(`${TOKEN_PREFIX}hover-l1`)
  228. })
  229. it('routes the standard property and the WebKit thumb through the same indirection', () => {
  230. // A rebind on an elevated container has to move the Firefox and the WebKit
  231. // rendering together, which only holds while both read the same variable.
  232. const declaration = (property: string, selectorPart: string): string | undefined => scrollbarRules
  233. .filter(rule => rule.selectors.includes(selectorPart))
  234. .flatMap(rule => rule.declarations)
  235. .findLast(([name]) => name === property)?.[1]
  236. const thumbColor = declaration('scrollbar-color', 'body')
  237. expect(thumbColor).toBeDefined()
  238. const indirection = varReferences(thumbColor!)[0]
  239. expect(indirection).toBe(`${INDIRECTION_PREFIX}thumb`)
  240. expect(varReferences(declaration('background', '::-webkit-scrollbar-thumb')!)).toEqual([indirection])
  241. })
  242. })
  243. describe('scrollbar.css width variable', () => {
  244. const WIDTH_VARIABLE = `${INDIRECTION_PREFIX}width`
  245. it('defines the width variable on body as a static length', () => {
  246. // The overlay seat compensation reads a fixed number, not a second
  247. // indirection: the mirror check below compares the WebKit rule against
  248. // this value, so a var()-to-var() chain would compare one indirection to
  249. // another instead of pinning the number.
  250. const value = scrollbarRules
  251. .filter(rule => rule.selectors.includes('body'))
  252. .flatMap(rule => rule.declarations)
  253. .findLast(([property]) => property === WIDTH_VARIABLE)?.[1]
  254. expect(value, WIDTH_VARIABLE).toBeDefined()
  255. expect(value, WIDTH_VARIABLE).toMatch(/^\d+(?:\.\d+)?px$/)
  256. })
  257. it('mirrors the ::-webkit-scrollbar width rule with the variable value', () => {
  258. // The compensation stays aligned with the WebKit bar only while both read
  259. // the same number. A change to one side without the other puts the overlay
  260. // seat a band off from Chat on WebKit engines.
  261. const variableValue = scrollbarRules
  262. .filter(rule => rule.selectors.includes('body'))
  263. .flatMap(rule => rule.declarations)
  264. .findLast(([property]) => property === WIDTH_VARIABLE)?.[1]
  265. const webkitWidth = scrollbarRules
  266. .filter(rule => rule.selectors.includes('::-webkit-scrollbar'))
  267. .flatMap(rule => rule.declarations)
  268. .findLast(([property]) => property === 'width')?.[1]
  269. expect(webkitWidth, '::-webkit-scrollbar width').toBeDefined()
  270. expect(webkitWidth).toBe(variableValue)
  271. })
  272. it('every reader of the width variable outside ui-theme references a defined variable', () => {
  273. // The consumer is ConversationRoot's overlay composer seat
  274. // (`right: var(--dsh-scrollbar-width)`); a rename in scrollbar.css without
  275. // the consumer, or a typo in the consumer, leaves the value
  276. // guaranteed-invalid and the seat loses the band. The equal-rectangle e2e
  277. // would catch it only on an engine that draws the bar, so the sheet
  278. // contract states it here.
  279. const defined = new Set(
  280. scrollbarRules
  281. .flatMap(rule => rule.declarations)
  282. .filter(([property]) => property.startsWith(INDIRECTION_PREFIX))
  283. .map(([property]) => property),
  284. )
  285. expect(defined).toContain(WIDTH_VARIABLE)
  286. const readers: string[] = []
  287. for (const file of packageStylesheets()) {
  288. if (file === fileURLToPath(new URL('scrollbar.css', STYLES))) continue
  289. for (const rule of parseRules(readFileSync(file, 'utf8'))) {
  290. for (const [property, value] of rule.declarations) {
  291. for (const name of varReferences(value)) {
  292. if (name === WIDTH_VARIABLE) readers.push(`${file} ${rule.selectors.join(', ')}: ${property}`)
  293. }
  294. }
  295. }
  296. }
  297. expect(readers.length, 'compensation consumer').toBeGreaterThan(0)
  298. })
  299. })
  300. describe('scrollbar.css selectors', () => {
  301. const scrollbarColorSelectors = scrollbarRules
  302. .filter(rule => rule.declarations.some(([property]) => property === 'scrollbar-color'))
  303. .flatMap(rule => rule.selectors)
  304. it('declares scrollbar-color only where the body-scoped tokens are visible', () => {
  305. // design-platform.css defines the alias tokens on `body`, and custom
  306. // properties inherit downward only: the same declaration on `html` or
  307. // `:root` resolves to the guaranteed-invalid value, which computes
  308. // scrollbar-color to `auto` and drops the theming entirely.
  309. expect(scrollbarColorSelectors.length).toBeGreaterThan(0)
  310. for (const selector of scrollbarColorSelectors) {
  311. expect(selector, selector).toMatch(/^body\b/)
  312. }
  313. })
  314. it('defines the indirection where the alias tokens are visible', () => {
  315. const definesIndirection = ([property, value]: [string, string]): boolean =>
  316. property.startsWith(INDIRECTION_PREFIX) && value.includes(TOKEN_PREFIX)
  317. const hosts = scrollbarRules
  318. .filter(rule => rule.declarations.some(definesIndirection))
  319. .flatMap(rule => rule.selectors)
  320. expect(hosts.length).toBeGreaterThan(0)
  321. for (const selector of hosts) expect(selector, selector).toMatch(/^body\b/)
  322. })
  323. it('re-declares the scrollbar properties per element rather than inheriting them', () => {
  324. // scrollbar-width is not an inherited property, and an inherited
  325. // scrollbar-color carries the colour already substituted at `body`, which
  326. // a descendant rebinding the indirection could no longer change.
  327. expect(scrollbarColorSelectors).toContain('body *')
  328. const widthSelectors = scrollbarRules
  329. .filter(rule => rule.declarations.some(([property]) => property === 'scrollbar-width'))
  330. .flatMap(rule => rule.selectors)
  331. expect(widthSelectors).toContain('body *')
  332. })
  333. })
  334. describe('scrollbar.css rendering paths', () => {
  335. /** The gate prelude, spelled exactly as the sheet must spell it for the split to exist. */
  336. const GATE = '@supports not selector(::-webkit-scrollbar)'
  337. const withoutComments = scrollbarCss.replace(/\/\*[\s\S]*?\*\//g, ' ')
  338. const gate = atRuleBlock(withoutComments, GATE)
  339. /** Standard scrollbar properties, the ones whose non-`auto` values suppress the pseudo-elements. */
  340. const STANDARD_PROPERTIES = ['scrollbar-width', 'scrollbar-color']
  341. it('gates the standard properties behind the absence of the WebKit pseudo-element', () => {
  342. // A non-`auto` scrollbar-width or scrollbar-color makes Chromium and
  343. // Safari discard every ::-webkit-scrollbar* rule for that element,
  344. // ::-webkit-scrollbar-thumb:hover included. Declaring both paths
  345. // unconditionally therefore renders the hover token nowhere: the engines
  346. // implementing the hover pseudo-element are exactly the ones the standard
  347. // properties silence, and Firefox has no hover pseudo-element at all.
  348. expect(gate, GATE).toBeDefined()
  349. for (const property of STANDARD_PROPERTIES) {
  350. const offsets = [...withoutComments.matchAll(new RegExp(String.raw`(^|[;{\s])${property}\s*:`, 'g'))]
  351. .map(match => match.index)
  352. expect(offsets.length, property).toBeGreaterThan(0)
  353. for (const offset of offsets) {
  354. expect(offset, `${property} outside ${GATE}`).toBeGreaterThan(gate!.start)
  355. expect(offset, `${property} outside ${GATE}`).toBeLessThan(gate!.end)
  356. }
  357. }
  358. })
  359. it('leaves the WebKit pseudo-element rules outside the gate', () => {
  360. // Gating these in turn would only restate selector matching: an engine
  361. // without the pseudo-elements drops the rules as unknown selectors. Inside
  362. // the gate they would be dropped by the engines that do implement them,
  363. // which is every engine that can render them.
  364. const offsets = [...withoutComments.matchAll(/::-webkit-scrollbar/g)]
  365. .map(match => match.index)
  366. .filter(offset => withoutComments.slice(offset).search(/^[\w:-]*\s*[,{]/) === 0)
  367. expect(offsets.length).toBeGreaterThan(0)
  368. for (const offset of offsets) {
  369. expect(offset > gate!.start && offset < gate!.end, `::-webkit-scrollbar rule inside ${GATE}`).toBe(false)
  370. }
  371. })
  372. it('renders the hover token only through the pseudo-element path', () => {
  373. // The standard path has no hover counterpart — scrollbar-color states one
  374. // thumb colour and the engine derives its own hover treatment — so the
  375. // hover indirection has to be read outside the gate or it renders nowhere.
  376. const hoverOffsets = [...withoutComments.matchAll(new RegExp(String.raw`var\(\s*${INDIRECTION_PREFIX}thumb-hover`, 'g'))]
  377. .map(match => match.index)
  378. expect(hoverOffsets.length).toBeGreaterThan(0)
  379. for (const offset of hoverOffsets) {
  380. expect(offset > gate!.start && offset < gate!.end, 'hover indirection read inside the gate').toBe(false)
  381. }
  382. })
  383. })
  384. describe('elevated surface rebinds', () => {
  385. it('at least one surface rebinds the indirection', () => {
  386. expect(rebindRules.length).toBeGreaterThan(0)
  387. })
  388. it('each rebinding rule sets the thumb and the hover variable together', () => {
  389. // A surface rebinding only the resting colour keeps the l1 hover colour,
  390. // so the elevation is wrong only while the pointer is over the thumb.
  391. for (const { file, rule } of rebindRules) {
  392. const properties = rule.declarations.map(([property]) => property).filter(property => property.startsWith(INDIRECTION_PREFIX))
  393. expect(sorted(properties), `${file} ${rule.selectors.join(', ')}`).toEqual([
  394. `${INDIRECTION_PREFIX}thumb-hover`, `${INDIRECTION_PREFIX}thumb`,
  395. ].sort())
  396. }
  397. })
  398. it('each rebinding rule binds the indirection names scrollbar.css renders', () => {
  399. // A misspelled property name declares an unused variable, and the surface
  400. // silently keeps the base-surface colour.
  401. const rendered = new Set(
  402. scrollbarRules
  403. .flatMap(rule => rule.declarations)
  404. .filter(([property]) => !property.startsWith('--'))
  405. .flatMap(([, value]) => varReferences(value))
  406. .filter(name => name.startsWith(INDIRECTION_PREFIX)),
  407. )
  408. for (const { file, rule } of rebindRules) {
  409. for (const [property] of rule.declarations) {
  410. if (property.startsWith(INDIRECTION_PREFIX)) expect(rendered, `${file}: ${property}`).toContain(property)
  411. }
  412. }
  413. })
  414. it('rebinds the pair to one target: the l2 elevation pair, or transparent', () => {
  415. // The rule as a whole, not each declaration on its own. Per-declaration
  416. // checking accepts a MIXED rule — `thumb: transparent` beside
  417. // `thumb-hover: var(--dsw-alias-scrollbar-hover-l2)` — which repaints the
  418. // bar the moment the pointer reaches it while passing a gate that claims
  419. // the two targets are exclusive.
  420. //
  421. // The elevation half compares the whole value against the pair's canonical
  422. // spelling rather than checking that every token it mentions ends in `-l2`.
  423. // A shape check admits `color-mix(…, var(--dsw-alias-scrollbar-bg-l2) 85%,
  424. // white)` and a crossed pair (the hover token bound to the resting
  425. // property); neither is what the contract says.
  426. for (const { file, rule } of rebindRules) {
  427. const rebinds = rule.declarations.filter(([property]) => property.startsWith(INDIRECTION_PREFIX))
  428. const where = `${file} ${rule.selectors.join(', ')}`
  429. if (rebinds.every(([, value]) => value === HIDDEN_THUMB)) continue
  430. expect(rebinds.some(([, value]) => value === HIDDEN_THUMB), `${where}: mixes ${HIDDEN_THUMB} with an elevation`).toBe(false)
  431. for (const [property, value] of rebinds) {
  432. expect(value, `${where}: ${property}`).toBe(ELEVATED_REBIND.get(property))
  433. }
  434. }
  435. })
  436. it('resolves the elevated surface set from the palette ladder', () => {
  437. // The set has to come from the palette, not from the sheets that happen to
  438. // rebind: derived from rebinds it can only confirm what someone already
  439. // remembered, and a surface nobody has rebound yet — the case the check
  440. // exists for — would define itself as unelevated. Anchoring it here means a
  441. // new palette token on an elevated rung is in scope the moment it is
  442. // defined. `--dsw-specific-tip` is the regression that proved the point: it
  443. // resolves to the same dark rung as the menu surface, and the Todo panel
  444. // scrolled on it unrebound while a rebind-derived set stayed green.
  445. expect(elevatedSurfaces).toContain('--dsw-alias-bg-layer-2')
  446. expect(elevatedSurfaces).toContain('--dsw-alias-bg-layer-3')
  447. expect(elevatedSurfaces).toContain('--dsw-specific-menu')
  448. expect(elevatedSurfaces).toContain('--dsw-specific-input-major')
  449. expect(elevatedSurfaces).toContain('--dsw-specific-tip')
  450. // Base surfaces stay out, or every scroll container would be in scope and
  451. // the check would say nothing.
  452. expect(elevatedSurfaces).not.toContain('--dsw-alias-bg-base')
  453. expect(elevatedSurfaces).not.toContain('--dsw-alias-bg-layer-1')
  454. })
  455. it('every sheet that scrolls on an elevated surface rebinds', () => {
  456. // The failure this closes: a scroll container on an elevated surface that
  457. // nobody remembered to rebind renders the l1 thumb, which differs from l2
  458. // only in the dark palette and only for that one surface — invisible both in
  459. // review and in a light-palette screenshot. Four sheets shipped that way
  460. // (ui-primitives Menu, InputBar, QuestionComposer, TodoPanel) and review
  461. // caught them by hand, which is what this replaces.
  462. //
  463. // Surface-level, not element-level: the elevated card and the descendant
  464. // that scrolls are separate rules, and CSS text does not say which contains
  465. // which. What keeps that from over-reporting is the token FAMILY: only
  466. // `--dsw-alias-bg-*` and `--dsw-specific-*` name a surface, so a floating
  467. // button or an inline code span reaching the same rung is out of scope
  468. // (ChatView's `.toBottom`, CodeBlock's banner). Geometry cannot make that
  469. // call — a floating button carries a radius, a shadow, and a fixed size.
  470. for (const [file, surfaces] of sheetSurfaces) {
  471. if (!surfaces.scrolls || surfaces.rebindsElevation) continue
  472. expect([...surfaces.elevated], `${file} scrolls on an elevated surface without rebinding`).toEqual([])
  473. }
  474. })
  475. })