sidebar-scrollbar.e2e.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. // Web e2e scenario: the sidebar session list's scrollbar as the browser
  2. // actually lays it out — the observable half of the themed-scrollbar change
  3. // (packages/client/ui-theme/src/styles/scrollbar.css plus the
  4. // `scrollbar-gutter: stable` reservation on WorkspaceBrowser's `.list`). The
  5. // ui-theme/ui-workspace unit specs read the CSS text; only a real engine
  6. // reports the reserved gutter width and the substituted `scrollbar-color`, so
  7. // those two facts live here.
  8. //
  9. // Zero model calls: the list only has to overflow, so the scenario seeds many
  10. // cold sessions from another spec's committed fixture (seeded-history's
  11. // seed.jsonl, reused read-only — this spec needs row count, not new recorded
  12. // content) and never launches a replay row. A stray stream would fail loud
  13. // with NO_ADAPTER.
  14. //
  15. // Headless-chromium caveats, load-bearing for what is asserted below.
  16. //
  17. // Headless chromium defaults to an OVERLAY scrollbar: one drawn on top of the
  18. // content, consuming no layout width unless something reserves space. That is
  19. // the mode in which the reported symptom exists at all, so this environment
  20. // reproduces it rather than merely approximating it — measured against clean
  21. // master, where the list's band is 0 and the bar covers 7px of the relative
  22. // time. (Under a classic space-consuming bar, `clientWidth` already excludes
  23. // the bar and nothing can be covered; a headed run under xvfb behaves that way
  24. // and cannot show the symptom.)
  25. //
  26. // The consequence for assertions: comparing the time element's right edge
  27. // against the list's CLIENT-area right edge holds in both states and proves
  28. // nothing, because with an overlay bar the client edge is the border edge. The
  29. // two signals that do separate the states are the reserved band width and
  30. // `timeCoveredBy`, which measures the overlap against the bar's own width.
  31. //
  32. // Both the `scrollbar-gutter: stable` reservation and the sheet's
  33. // `::-webkit-scrollbar` width are needed for that band, and neither suffices:
  34. // measured on the running app, deleting either one takes the band from 8 to 0
  35. // while the other stays in force. The gutter states that space be reserved; the
  36. // pseudo-element width is what makes chromium treat the bar as occupying layout
  37. // space in the first place.
  38. //
  39. // That conjunction is why `band` and `timeCoveredBy` are both asserted and
  40. // neither replaces the other. Removing only the gutter leaves `timeCoveredBy` at
  41. // 0, because the bar is then 8px wide and the row's right padding is also 8px,
  42. // so it abuts the timestamp without covering it; `band` catches that case.
  43. // Removing both — the actual master state — is what produces the reported
  44. // overlap, and `timeCoveredBy` measures it at 7. Each was mutation-checked with
  45. // the other assertions in its test silenced.
  46. //
  47. // The thumb is a pointer affordance (ui-sidebar rebinds the indirection pair
  48. // to `transparent` while the pointer is outside the column), so every
  49. // measurement below states which pointer position it was taken at: the
  50. // scenario parks the pointer over the sidebar before asserting a colour, and
  51. // the quiet state and its linger get their own test.
  52. //
  53. // Chromium also takes the `::-webkit-scrollbar*` path, not the standard
  54. // properties: scrollbar.css gates `scrollbar-width`/`scrollbar-color` behind
  55. // `@supports not selector(::-webkit-scrollbar)`, which is false here. The
  56. // resolved standard properties therefore read `auto`, and that reading is
  57. // asserted — a concrete value would mean the gate leaked and silenced the
  58. // pseudo-element rules. What the theme test measures instead is the pair the
  59. // pseudo-element rules read: the indirection variables as they resolve ON the
  60. // list, plus the `::-webkit-scrollbar-thumb:hover` declaration as it stands in
  61. // the cascade. The hover thumb colour is not observable any other way —
  62. // chromium folds the `:hover` rule into `getComputedStyle(el,
  63. // '::-webkit-scrollbar-thumb')`, so that query reports the hover colour at
  64. // rest and cannot pin either state (measured by deleting the hover rule live:
  65. // the same query flipped from the hover colour to the resting one).
  66. import { readFile } from 'node:fs/promises'
  67. import { fileURLToPath } from 'node:url'
  68. import { join } from 'node:path'
  69. import type { Browser, Page } from 'playwright'
  70. import { chromium } from 'playwright'
  71. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  72. import {
  73. assertFixtureInventory, compareOrRefreshGolden, launchWebScaffold, seedSession, watchConsole,
  74. webSnapshotMode, type WebScaffold,
  75. } from './scaffold.ts'
  76. import { newEnglishPage, saveFailureShot } from './support.ts'
  77. const SEED = fileURLToPath(new URL('./snapshots/seeded-history/seed.jsonl', import.meta.url))
  78. const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/sidebar-scrollbar', import.meta.url))
  79. /**
  80. * Committed golden of the resolved scrollbar style and geometry, in both
  81. * palettes. The aria goldens the other scenarios commit cannot carry this
  82. * change: it alters no DOM and no accessible name, so their normalized trees are
  83. * byte-identical with and without it. This one records the values instead, which
  84. * makes an unintended shift in thumb colour, band width, or rendering path a
  85. * reviewable diff rather than an assertion someone has to think about.
  86. */
  87. const GEOMETRY_EXPECTED = join(SNAPSHOT_DIR, 'geometry.expected.md')
  88. const MODE = webSnapshotMode()
  89. /** Enough rows that the list overflows the 800px-tall viewport's sidebar; the scenario asserts the overflow rather than trusting it. */
  90. const SEED_COUNT = 24
  91. /** Geometry and resolved scrollbar style of one scroll container, measured in the page. */
  92. interface ListMetrics {
  93. /** Resolved `scrollbar-gutter`. */
  94. gutter: string
  95. /** Resolved `::-webkit-scrollbar` width: the pseudo-element path's own sizing. */
  96. width: string
  97. /** Resolved `::-webkit-scrollbar-track` background. */
  98. track: string
  99. /** Resolved `scrollbar-width`, expected `auto` because the gate excludes chromium. */
  100. standardWidth: string
  101. /** Resolved `scrollbar-color`, expected `auto` for the same reason. */
  102. standardColor: string
  103. /** `::-webkit-scrollbar-thumb:hover` background declarations found in the cascade, in sheet order. */
  104. hoverRules: string[]
  105. /** `--dsh-scrollbar-thumb` resolved on the list, serialized as a colour. */
  106. token: string
  107. /** `--dsh-scrollbar-thumb-hover` resolved on the list, serialized the same way. */
  108. hoverToken: string
  109. /** True when the list actually scrolls. */
  110. overflows: boolean
  111. /** Border-box width minus client width: the space the scrollbar takes out of the content area. */
  112. band: number
  113. /** Distance from the scrollbar's right edge to the sidebar edge. */
  114. scrollbarEdgeOffset: number
  115. /** Distance from the first row background's right edge to the sidebar edge. */
  116. rowEdgeInset: number
  117. /** Client-area right edge in viewport coordinates (`clientWidth` excludes the scrollbar band). */
  118. clientRight: number
  119. /** Border-box right edge in viewport coordinates. */
  120. borderRight: number
  121. /** Right edge of the first row's relative-time element, the content the unreserved bar covered. */
  122. timeRight: number
  123. /**
  124. * Pixels of the relative time the scrollbar paints over: how far its right
  125. * edge reaches into the band the bar occupies, `[borderRight - barWidth,
  126. * borderRight]`. This is the reported symptom as a number, and it is the one
  127. * geometric signal that separates the two states in this environment — see
  128. * the file header on why `clientWidth` comparisons cannot.
  129. */
  130. timeCoveredBy: number
  131. }
  132. /**
  133. * Measure the sidebar list in the page.
  134. * @param page - the page under test.
  135. * @returns the list's resolved scrollbar style and the geometry the fix changes.
  136. */
  137. function measureList(page: Page): Promise<ListMetrics> {
  138. return page.evaluate(() => {
  139. const list = document.querySelector<HTMLElement>('[role="tree"][aria-label="Sessions"]')
  140. if (list === null) throw new Error('sidebar session list not in the DOM')
  141. const time = list.querySelector<HTMLElement>('[class*="time"]')
  142. if (time === null) throw new Error('no row relative-time element in the sidebar list')
  143. const row = list.querySelector<HTMLElement>('[role="treeitem"]')
  144. if (row === null) throw new Error('no row in the sidebar list')
  145. // Each indirection variable is resolved through its own throwaway probe
  146. // appended to the list: `var()` substitution then happens where the list
  147. // sits in the cascade, which is the claim, and `color` normalizes whatever
  148. // notation the palette sheet chose into one comparable serialization. A
  149. // REUSED probe would report only the last value read — `getComputedStyle`
  150. // returns a live declaration, so reassigning `style.color` retroactively
  151. // changes every earlier read.
  152. const resolve = (name: string): string => {
  153. const probe = document.createElement('span')
  154. probe.style.color = `var(${name})`
  155. list.append(probe)
  156. const value = getComputedStyle(probe).color
  157. probe.remove()
  158. return value
  159. }
  160. // The hover colour is read out of the cascade rather than computed:
  161. // chromium reports the `:hover` background for the resting pseudo-element
  162. // too (see the file header), so no computed query separates the states.
  163. // Cross-origin sheets throw on `cssRules`; none is expected, and skipping
  164. // them cannot mask the rule under test, which ships in the app's own CSS.
  165. const hoverRules = [...document.styleSheets]
  166. .flatMap((sheet) => {
  167. try {
  168. return [...sheet.cssRules]
  169. } catch {
  170. return []
  171. }
  172. })
  173. .filter((rule): rule is CSSStyleRule => rule instanceof CSSStyleRule)
  174. .filter(rule => rule.selectorText === '::-webkit-scrollbar-thumb:hover')
  175. .map(rule => rule.style.getPropertyValue('background'))
  176. const style = getComputedStyle(list)
  177. const pseudoWidth = getComputedStyle(list, '::-webkit-scrollbar').width
  178. const barWidth = pseudoWidth === 'auto' ? 15 : Number.parseFloat(pseudoWidth)
  179. const listRect = list.getBoundingClientRect()
  180. const sidebarEdge = list.parentElement?.getBoundingClientRect().right
  181. if (sidebarEdge === undefined) throw new Error('sidebar session list has no layout parent')
  182. return {
  183. gutter: style.scrollbarGutter,
  184. width: pseudoWidth,
  185. track: getComputedStyle(list, '::-webkit-scrollbar-track').backgroundColor,
  186. standardWidth: style.scrollbarWidth,
  187. standardColor: style.scrollbarColor,
  188. hoverRules,
  189. token: resolve('--dsh-scrollbar-thumb'),
  190. hoverToken: resolve('--dsh-scrollbar-thumb-hover'),
  191. overflows: list.scrollHeight > list.clientHeight,
  192. band: listRect.width - list.clientWidth,
  193. scrollbarEdgeOffset: sidebarEdge - listRect.right,
  194. rowEdgeInset: sidebarEdge - row.getBoundingClientRect().right,
  195. clientRight: listRect.left + list.clientWidth,
  196. borderRight: listRect.right,
  197. timeRight: time.getBoundingClientRect().right,
  198. // The bar is drawn in the rightmost `barWidth` of the border box, whether
  199. // or not that space was reserved. Its width comes from the sheet where the
  200. // sheet applies, and from the UA's own overlay bar otherwise — 15px is
  201. // what this chromium paints, measured against master where the rule is
  202. // absent. Taking the UA width as the fallback is what keeps the assertion
  203. // honest: assuming 0 there would report no occlusion precisely in the
  204. // state that has it.
  205. timeCoveredBy: Math.max(0, time.getBoundingClientRect().right - (listRect.right - barWidth)),
  206. }
  207. })
  208. }
  209. /**
  210. * Measure only overflow and row inset, which remain observable when every
  211. * session is hidden under a collapsed workspace group.
  212. * @param page - the page under test.
  213. * @returns the list overflow state and first row's trailing inset.
  214. */
  215. function measureRowInset(page: Page): Promise<Pick<ListMetrics, 'overflows' | 'rowEdgeInset'>> {
  216. return page.evaluate(() => {
  217. const list = document.querySelector<HTMLElement>('[role="tree"][aria-label="Sessions"]')
  218. if (list === null) throw new Error('sidebar session list not in the DOM')
  219. const row = list.querySelector<HTMLElement>('[role="treeitem"]')
  220. if (row === null) throw new Error('no row in the sidebar list')
  221. const sidebarEdge = list.parentElement?.getBoundingClientRect().right
  222. if (sidebarEdge === undefined) throw new Error('sidebar session list has no layout parent')
  223. return {
  224. overflows: list.scrollHeight > list.clientHeight,
  225. rowEdgeInset: sidebarEdge - row.getBoundingClientRect().right,
  226. }
  227. })
  228. }
  229. /** One palette's readings, taken at both pointer positions. */
  230. interface PaletteMetrics {
  231. /** Everything measured with the pointer over the list, which is when a thumb exists. */
  232. hovered: ListMetrics
  233. /** `--dsh-scrollbar-thumb` with the pointer parked outside the column. */
  234. quietThumb: string
  235. }
  236. /**
  237. * Read one palette at both pointer positions, ending with the pointer back
  238. * over the list so a caller measuring further leaves it revealed.
  239. * @param page - the page under test.
  240. * @returns the palette's quiet thumb and its hovered metrics.
  241. */
  242. async function measurePalette(page: Page): Promise<PaletteMetrics> {
  243. await pointAt(page, 'away')
  244. // Poll rather than sleep the linger out: the wait is the column's, and a
  245. // fixed sleep would either race it or pad every palette.
  246. await expect.poll(async () => resolveThumb(page), { timeout: 10_000 }).toBe(NO_THUMB)
  247. const quietThumb = await resolveThumb(page)
  248. await pointAt(page, 'list')
  249. // Poll the reveal too: the reading below is a colour, and taking it in the
  250. // same tick as the pointer move would race React's flush and land a
  251. // transparent thumb in the golden.
  252. await expect.poll(async () => resolveThumb(page), { timeout: 10_000 }).not.toBe(NO_THUMB)
  253. return { hovered: await measureList(page), quietThumb }
  254. }
  255. /**
  256. * Render the golden body: the resolved scrollbar style of the list in each
  257. * palette, plus the geometric relations the fix establishes.
  258. *
  259. * Absolute coordinates are deliberately absent. `timeRight`, `clientRight`, and
  260. * `borderRight` depend on the sidebar's laid-out width and on font metrics, so
  261. * committing them would make the golden fail on a machine whose fonts measure
  262. * differently — a fixture that has to be re-recorded per platform documents the
  263. * platform, not the change. What is recorded instead is the band, the overlap,
  264. * and the two orderings, each of which is a difference or a comparison and so
  265. * survives any layout that keeps the reservation.
  266. * @param light - metrics measured under the light palette.
  267. * @param dark - metrics measured under the dark palette.
  268. * @returns the golden body, without a trailing newline.
  269. */
  270. function renderGeometry(light: PaletteMetrics, dark: PaletteMetrics): string {
  271. const palette = (name: string, { hovered: metrics, quietThumb }: PaletteMetrics): string[] => [
  272. `## ${name}`,
  273. '',
  274. `- --dsh-scrollbar-thumb, pointer outside the sidebar: ${quietThumb}`,
  275. `- scrollbar-gutter: ${metrics.gutter}`,
  276. `- ::-webkit-scrollbar width: ${metrics.width}`,
  277. `- ::-webkit-scrollbar-track background: ${metrics.track}`,
  278. `- scrollbar-width: ${metrics.standardWidth}`,
  279. `- scrollbar-color: ${metrics.standardColor}`,
  280. `- ::-webkit-scrollbar-thumb:hover declarations: ${metrics.hoverRules.join(' | ')}`,
  281. `- --dsh-scrollbar-thumb, pointer over the list: ${metrics.token}`,
  282. `- --dsh-scrollbar-thumb-hover, pointer over the list: ${metrics.hoverToken}`,
  283. `- list overflows: ${String(metrics.overflows)}`,
  284. `- reserved band: ${String(metrics.band)}px`,
  285. `- scrollbar inset from the sidebar edge: ${String(metrics.scrollbarEdgeOffset)}px`,
  286. `- row background inset from the sidebar edge: ${String(metrics.rowEdgeInset)}px`,
  287. `- relative time covered by the bar: ${String(metrics.timeCoveredBy)}px`,
  288. `- relative time ends inside the content area: ${String(metrics.timeRight <= metrics.clientRight)}`,
  289. `- content area ends before the border box: ${String(metrics.clientRight < metrics.borderRight)}`,
  290. '',
  291. ]
  292. return [
  293. '# Sidebar session list scrollbar',
  294. '',
  295. ...palette('Light palette', light),
  296. ...palette('Dark palette', dark),
  297. ].join('\n').trimEnd()
  298. }
  299. /**
  300. * Resolve `--dsh-scrollbar-thumb` as the list sees it, without the rest of the
  301. * geometry. Own probe element for the same reason {@link measureList} uses
  302. * one: `getComputedStyle` returns a live declaration.
  303. * @param page - the page under test.
  304. * @returns the resolved thumb colour, serialized as `rgb`/`rgba`.
  305. */
  306. function resolveThumb(page: Page): Promise<string> {
  307. return page.evaluate(() => {
  308. const list = document.querySelector<HTMLElement>('[role="tree"][aria-label="Sessions"]')
  309. if (list === null) throw new Error('sidebar session list not in the DOM')
  310. const probe = document.createElement('span')
  311. probe.style.color = 'var(--dsh-scrollbar-thumb)'
  312. list.append(probe)
  313. const value = getComputedStyle(probe).color
  314. probe.remove()
  315. return value
  316. })
  317. }
  318. /** Fully transparent, which is how the quiet column spells "no thumb". */
  319. const NO_THUMB = 'rgba(0, 0, 0, 0)'
  320. /**
  321. * Park the pointer over the session list or outside the sidebar entirely. The
  322. * column reveals its scrollbars from real pointer movement, so a scenario that
  323. * never moves the mouse measures the quiet state whatever it intended to.
  324. * @param page - the page under test.
  325. * @param where - `list` to point at the session list, `away` for the far side
  326. * of the viewport (the conversation column).
  327. */
  328. async function pointAt(page: Page, where: 'list' | 'away'): Promise<void> {
  329. const box = await page.locator('[role="tree"][aria-label="Sessions"]').boundingBox()
  330. if (box === null) throw new Error('sidebar session list has no layout box')
  331. const viewport = page.viewportSize()
  332. if (viewport === null) throw new Error('page has no viewport')
  333. const target = where === 'list'
  334. ? { x: box.x + box.width / 2, y: box.y + box.height / 2 }
  335. : { x: viewport.width - 5, y: box.y + box.height / 2 }
  336. await page.mouse.move(target.x, target.y)
  337. }
  338. /**
  339. * Reveal the seeded rows: every seeded session is unattached, so they all sit
  340. * in the collapsed Ungrouped bucket. Converges on expanded rather than
  341. * clicking once — startup auto-selection can expand the bucket first, and a
  342. * second click would collapse it again. Hand-rolled polling because
  343. * `expect.poll` is test-scoped and this runs in `beforeAll`.
  344. * @param page - the page under test.
  345. */
  346. async function expandSeededSessions(page: Page): Promise<void> {
  347. const bucket = page.getByText('Ungrouped', { exact: true }).locator('..').locator('..')
  348. await bucket.waitFor({ timeout: 15_000 })
  349. const rows = page.locator('[role="tree"][aria-label="Sessions"] [role="treeitem"]')
  350. const deadline = Date.now() + 30_000
  351. for (;;) {
  352. if (await bucket.getAttribute('aria-expanded') !== 'true') {
  353. await page.getByText('Ungrouped', { exact: true }).click()
  354. }
  355. if (await bucket.getAttribute('aria-expanded') === 'true' && await rows.count() > SEED_COUNT / 2) return
  356. if (Date.now() > deadline) {
  357. throw new Error(`Ungrouped bucket never revealed more than ${SEED_COUNT / 2} rows`)
  358. }
  359. await page.waitForTimeout(200)
  360. }
  361. }
  362. describe('web e2e: sidebar session list scrollbar (reserved gutter / themed thumb)', () => {
  363. let scaffold: WebScaffold
  364. let browser: Browser
  365. let page: Page
  366. let tripwire: ReturnType<typeof watchConsole>
  367. beforeAll(async () => {
  368. scaffold = await launchWebScaffold({})
  369. const fixture = await readFile(SEED, 'utf8')
  370. for (let index = 0; index < SEED_COUNT; index += 1) {
  371. await seedSession(scaffold, fixture, `sidebar-scrollbar-web-e2e-${String(index).padStart(2, '0')}`)
  372. }
  373. browser = await chromium.launch()
  374. // Shorter than the other scenarios' 1000px so SEED_COUNT rows overflow
  375. // the list with room to spare.
  376. page = await newEnglishPage(browser, 800)
  377. tripwire = watchConsole(page)
  378. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  379. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  380. await expandSeededSessions(page)
  381. // Every assertion about a thumb colour needs a drawn thumb, and the column
  382. // only draws one under the pointer; the quiet state is asserted where it is
  383. // the subject rather than left as an ambient condition of the whole file.
  384. await pointAt(page, 'list')
  385. }, 180_000)
  386. afterAll(async () => {
  387. await browser?.close()
  388. await scaffold?.close()
  389. })
  390. it('reserves a scrollbar gutter on the overflowing session list', async () => {
  391. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-scrollbar-gutter'))
  392. // Vacuity guard: with a non-overflowing list `stable` still reserves, but
  393. // the scenario would no longer be reproducing the reported situation.
  394. await expect.poll(async () => (await measureList(page)).overflows, { timeout: 10_000 }).toBe(true)
  395. const metrics = await measureList(page)
  396. expect(metrics.gutter).toBe('stable')
  397. // The control. `band > 0` is the whole observable effect of the
  398. // reservation: the scrollbar is taken out of the content area instead of
  399. // drawn over it. Removing the declaration makes it exactly 0. The value
  400. // itself is not pinned — it tracks `scrollbar-width` and the platform.
  401. expect(metrics.band).toBeGreaterThan(0)
  402. expect(metrics.scrollbarEdgeOffset).toBe(2)
  403. expect(metrics.rowEdgeInset).toBe(12)
  404. // The reported symptom, stated directly: no part of the row's relative time
  405. // lies under the bar. Measures 7 on clean master — the `h` of `1h` is the
  406. // covered part. Unlike the client-edge comparison below it does not go
  407. // vacuous under an overlay scrollbar, because it measures against the bar's
  408. // own width rather than against a content edge the overlay bar does not
  409. // move. It is not a replacement for the band assertion above; see the file
  410. // header for which regression each one catches.
  411. expect(metrics.timeCoveredBy).toBe(0)
  412. // Corollaries of the reservation, kept because they pin where the band sits
  413. // rather than only that it exists: the time ends inside the content area,
  414. // and the content area ends before the border box. Each holds in both
  415. // states on its own (see the file header) and is meaningful only alongside
  416. // the two assertions above.
  417. expect(metrics.timeRight).toBeLessThanOrEqual(metrics.clientRight)
  418. expect(metrics.clientRight).toBeLessThan(metrics.borderRight)
  419. expect(tripwire.pageErrors).toEqual([])
  420. }, 60_000)
  421. it('draws no thumb until the pointer is over the column, and lingers on the way out', async () => {
  422. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-scrollbar-pointer'))
  423. const revealed = await resolveThumb(page)
  424. expect(revealed).not.toBe(NO_THUMB)
  425. await pointAt(page, 'away')
  426. // The linger, measured as a state rather than a duration: the thumb is
  427. // still drawn on the leave itself, and gone once the window has passed. A
  428. // tighter timing assertion would pin the wall clock of a CI machine.
  429. expect(await resolveThumb(page)).toBe(revealed)
  430. await expect.poll(async () => resolveThumb(page), { timeout: 10_000 }).toBe(NO_THUMB)
  431. // The reservation is unconditional, so nothing moved while the bar was
  432. // hidden — this is what buys `transparent` over hiding the bar itself.
  433. const quiet = await measureList(page)
  434. expect(quiet.gutter).toBe('stable')
  435. expect(quiet.band).toBeGreaterThan(0)
  436. expect(quiet.timeCoveredBy).toBe(0)
  437. // Scrolling without a pointer — what a keyboard or a touch drag does —
  438. // leaves the column quiet. This is the change's one deliberate loss, and
  439. // it is pinned here rather than only described, so making a scroll
  440. // re-reveal the bar has to be a decision rather than a side effect.
  441. await page.locator('[role="tree"][aria-label="Sessions"]').evaluate((el) => { el.scrollTop += 200 })
  442. await page.waitForTimeout(500)
  443. expect(await resolveThumb(page)).toBe(NO_THUMB)
  444. await pointAt(page, 'list')
  445. await expect.poll(async () => resolveThumb(page), { timeout: 10_000 }).toBe(revealed)
  446. expect(tripwire.pageErrors).toEqual([])
  447. }, 60_000)
  448. it('keeps the row background inset when overflow disappears', async () => {
  449. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-scrollbar-stable-inset'))
  450. expect(await measureRowInset(page)).toEqual({ overflows: true, rowEdgeInset: 12 })
  451. const bucket = page.getByText('Ungrouped', { exact: true }).locator('..').locator('..')
  452. await bucket.click()
  453. try {
  454. await expect.poll(async () => (await measureRowInset(page)).overflows, { timeout: 10_000 }).toBe(false)
  455. expect(await measureRowInset(page)).toEqual({ overflows: false, rowEdgeInset: 12 })
  456. } finally {
  457. await expandSeededSessions(page)
  458. }
  459. expect(tripwire.pageErrors).toEqual([])
  460. }, 60_000)
  461. it('renders the themed thumb through the WebKit path in both palettes', async () => {
  462. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-scrollbar-theme'))
  463. const light = await measureList(page)
  464. // The gate's signature on this engine, and the reason it exists: chromium
  465. // implements `::-webkit-scrollbar`, so the standard properties stay at
  466. // their initial `auto`. A concrete value here would mean the gate leaked,
  467. // which is exactly what makes chromium discard the pseudo-element rules —
  468. // the hover token included.
  469. expect(light.standardWidth).toBe('auto')
  470. expect(light.standardColor).toBe('auto')
  471. // The pseudo-element path is the one in force: the sheet's own 8px sizing
  472. // and transparent track reached a container it never names.
  473. expect(light.width).toBe('8px')
  474. expect(light.track).toBe('rgba(0, 0, 0, 0)')
  475. // The resting and the hover rule each read the rebindable indirection, and
  476. // the two resolve to DIFFERENT colours on this list: the l1 pair arrived
  477. // here intact rather than collapsing to one value or falling back.
  478. expect(light.hoverRules).toEqual(['var(--dsh-scrollbar-thumb-hover)'])
  479. expect(light.token).toMatch(/^rgba?\(/)
  480. expect(light.hoverToken).not.toBe(light.token)
  481. // The dark palette declares different scrollbar tokens; driving the body
  482. // attribute pins the cascade the way lifecycle-chrome does (the Settings
  483. // gesture that sets it is owned there).
  484. await page.evaluate(() => { document.body.setAttribute('data-ds-dark-theme', '') })
  485. const dark = await measureList(page)
  486. expect(dark.token).not.toBe(light.token)
  487. expect(dark.hoverToken).not.toBe(dark.token)
  488. expect(dark.hoverToken).not.toBe(light.hoverToken)
  489. await page.evaluate(() => { document.body.removeAttribute('data-ds-dark-theme') })
  490. const restored = await measureList(page)
  491. expect(restored.token).toBe(light.token)
  492. expect(restored.hoverToken).toBe(light.hoverToken)
  493. expect(tripwire.pageErrors).toEqual([])
  494. }, 60_000)
  495. it('matches the committed scrollbar geometry golden in both palettes', async () => {
  496. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-scrollbar-golden'))
  497. const light = await measurePalette(page)
  498. await page.evaluate(() => { document.body.setAttribute('data-ds-dark-theme', '') })
  499. const dark = await measurePalette(page)
  500. await page.evaluate(() => { document.body.removeAttribute('data-ds-dark-theme') })
  501. await compareOrRefreshGolden(GEOMETRY_EXPECTED, renderGeometry(light, dark), MODE)
  502. expect(tripwire.pageErrors).toEqual([])
  503. }, 60_000)
  504. it('commits exactly the fixtures it reads', async () => {
  505. // The scenario borrows seeded-history's seed.jsonl rather than committing a
  506. // second copy, so this directory holds the golden alone.
  507. await assertFixtureInventory(SNAPSHOT_DIR, ['geometry.expected.md'])
  508. })
  509. it.skipIf(MODE === 'record')('issued zero model calls and stayed clean', () => {
  510. expect(tripwire.warnings).toEqual([])
  511. expect(tripwire.pageErrors).toEqual([])
  512. })
  513. })