sidebar-right.e2e.ts 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. // Keyless assembled-browser coverage for the shipped right Sidebar: the official
  2. // roster row, the real plugin graph, and one Chromium. No overlay is applied —
  3. // this scenario proves the surface is in the product's own composition.
  4. //
  5. // The frame owns the right column as a track; the Sidebar anchors its panel to
  6. // the column's edge and slides it in and out. Which of the two presentations
  7. // draws the panel is a recorded, reversible choice, so this file asserts against
  8. // the frame's track as much as against the panel itself. The way back in while
  9. // collapsed is not in the column at all: it is one button in the conversation
  10. // header, and it leaves when the panel opens.
  11. //
  12. // Ordering is the product's own: the hero comes before any session, so the
  13. // empty right edge is asserted first and the session-bound cases follow in a
  14. // nested block that seeds one turn.
  15. //
  16. // Copy is asserted in English because this page advertises English, which is
  17. // itself the point: every string in this column now comes from the dictionary,
  18. // so an English page renders English. The Chinese draft the product ships is
  19. // asserted, and captured for review, on its own page at the end.
  20. import { mkdirSync, writeFileSync } from 'node:fs'
  21. import { join } from 'node:path'
  22. import { fileURLToPath } from 'node:url'
  23. import type { Browser, ConsoleMessage, Locator, Page } from 'playwright'
  24. import { chromium } from 'playwright'
  25. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  26. import { createMessage, createUserMessage } from '@deepseek-ai/dsh-llm'
  27. import { launchWebScaffold, watchConsole, type WebScaffold } from './scaffold.ts'
  28. import {
  29. connectFreshWorkspace, newEnglishPage, saveFailureShot, ZH_BROWSER_LOCALE,
  30. } from './support.ts'
  31. /** The produced file the seeded turn writes, and what the preview should show. */
  32. const SAMPLE_NAME = 'notes.txt'
  33. const SAMPLE_TEXT = 'produced by the seeded turn\nsecond line\n'
  34. /** Where this batch's accepted product forms are archived. */
  35. const SHOT_DIR = fileURLToPath(new URL('../../../.artifacts/screenshots/0907-sidebar-rules', import.meta.url))
  36. /** Archive one accepted product form; the batch receipt cites these by name. */
  37. async function shot(page: Page, name: string): Promise<void> {
  38. mkdirSync(SHOT_DIR, { recursive: true })
  39. await page.screenshot({ path: `${SHOT_DIR}/${name}.png`, fullPage: true })
  40. }
  41. /** Centre of a rendered element, in viewport coordinates. */
  42. async function centre(locator: Locator): Promise<{ x: number; y: number }> {
  43. const box = await locator.boundingBox()
  44. if (box === null) throw new Error('element is not rendered')
  45. return { x: box.x + box.width / 2, y: box.y + box.height / 2 }
  46. }
  47. /**
  48. * Press a tab chip and release it over a point.
  49. *
  50. * The press stays left of the chip's nested close control. An optional preview
  51. * verifies the browser recognized the drop target before the release.
  52. */
  53. async function dragTo(page: Page, tab: Locator, to: { x: number; y: number }, preview?: Locator): Promise<void> {
  54. const box = await tab.boundingBox()
  55. if (box === null) throw new Error('tab is not rendered')
  56. const from = { x: box.x + 6, y: box.y + box.height / 2 }
  57. await page.mouse.move(from.x, from.y)
  58. await page.mouse.down()
  59. try {
  60. await page.mouse.move(to.x, to.y, { steps: 8 })
  61. await preview?.waitFor({ state: 'visible' })
  62. } finally {
  63. await page.mouse.up()
  64. }
  65. }
  66. /** Press an element itself and release over a point (no tab-title indirection). */
  67. async function dragElement(page: Page, handle: Locator, to: { x: number; y: number }): Promise<void> {
  68. const from = await centre(handle)
  69. await page.mouse.move(from.x, from.y)
  70. await page.mouse.down()
  71. await page.mouse.move(to.x, to.y, { steps: 8 })
  72. await page.mouse.up()
  73. }
  74. /** A point inside `locator`, offset by fractions of its own box. */
  75. async function pointIn(locator: Locator, fx: number, fy: number): Promise<{ x: number; y: number }> {
  76. const box = await locator.boundingBox()
  77. if (box === null) throw new Error('element is not rendered')
  78. return { x: box.x + box.width * fx, y: box.y + box.height * fy }
  79. }
  80. /** Pause the panel's next real transform transition after observing its initial frame geometry. */
  81. async function holdPanelSlide(panel: Locator) {
  82. return await panel.evaluateHandle((node) => {
  83. const controller = new AbortController()
  84. const state = { animation: null as Animation | null, columnsAtStart: '', dispose: () => { controller.abort() } }
  85. node.addEventListener('transitionrun', (event) => {
  86. if (event.target !== node || (event as TransitionEvent).propertyName !== 'transform') return
  87. const frame = node.closest('[style*="grid-template-columns"]')
  88. if (frame === null) throw new Error('panel frame is unavailable')
  89. state.columnsAtStart = getComputedStyle(frame).gridTemplateColumns
  90. const slide = node.getAnimations().find(animation =>
  91. 'transitionProperty' in animation && animation.transitionProperty === 'transform')
  92. if (slide === undefined || slide.effect === null) throw new Error('panel transform transition is unavailable')
  93. slide.pause()
  94. slide.currentTime = Number(slide.effect.getComputedTiming().endTime) / 2
  95. state.animation = slide
  96. controller.abort()
  97. }, { signal: controller.signal })
  98. return state
  99. })
  100. }
  101. /** The expand button in the conversation header, present only while collapsed. */
  102. function expandOf(page: Page): Locator {
  103. return page.locator('[data-sidebar-right-expand]')
  104. }
  105. /**
  106. * Make sure the panel is open.
  107. *
  108. * These cases share one page and run in order, so an earlier one may have left
  109. * the panel collapsed; a case that needs tabs says so rather than inheriting
  110. * whatever the previous one happened to leave. The way in while collapsed is the
  111. * header's expand button, which lives in the conversation, not the column.
  112. */
  113. async function ensureExpanded(page: Page, column: Locator): Promise<void> {
  114. if (await column.locator('[data-sidebar-right-open]').count() > 0) return
  115. await expandOf(page).click()
  116. await column.locator('[data-sidebar-right-open]').waitFor({ timeout: 10_000 })
  117. }
  118. /** Reload the session's transient sidebar state before an independent gesture case. */
  119. async function resetSidebar(page: Page): Promise<Locator> {
  120. await page.reload({ waitUntil: 'load' })
  121. const column = page.locator('[data-rightbar-col]')
  122. await expandOf(page).waitFor({ timeout: 15_000 })
  123. await ensureExpanded(page, column)
  124. await column.locator('[data-sidebar-right-guide-entry="files"]').click()
  125. await expect.poll(async () => await tabTitles(column)).toEqual(['Files'])
  126. await width(column)
  127. return column
  128. }
  129. /** Whether the element at the centre of `locator` is the locator's own element or a descendant. */
  130. async function hitsItself(locator: Locator): Promise<boolean> {
  131. const point = await centre(locator)
  132. return await locator.evaluate((node, at) => {
  133. const hit = document.elementFromPoint(at.x, at.y)
  134. return hit !== null && node.contains(hit)
  135. }, point)
  136. }
  137. /**
  138. * Float a docked tab the way a user does: drag its chip clear of the docked
  139. * surface and release over the conversation.
  140. */
  141. async function floatByDrag(page: Page, tab: Locator): Promise<void> {
  142. const surface = page.locator('[data-dockkit-surface]').first()
  143. const box = await surface.boundingBox()
  144. if (box === null) throw new Error('surface is not rendered')
  145. await dragTo(page, tab, { x: box.x - 240, y: box.y + box.height / 2 })
  146. }
  147. /**
  148. * Drag the frame's rightbar handle until the panel is `target` px wide (the
  149. * frame clamps to its own range). The handle sits on the panel's left edge, so
  150. * widening is a drag to the left.
  151. */
  152. async function setPanelWidth(page: Page, target: number): Promise<void> {
  153. const panel = page.locator('[data-sidebar-right-panel]')
  154. const handle = page.locator('[data-side="rightbar"]').first()
  155. for (let attempt = 0; attempt < 3; attempt += 1) {
  156. const box = await panel.boundingBox()
  157. if (box === null) throw new Error('panel is not rendered')
  158. const delta = target - box.width
  159. if (Math.abs(delta) < 2) return
  160. const grip = await centre(handle)
  161. await page.mouse.move(grip.x, grip.y)
  162. await page.mouse.down()
  163. await page.mouse.move(grip.x - delta, grip.y, { steps: 8 })
  164. await page.mouse.up()
  165. await page.waitForTimeout(300)
  166. }
  167. }
  168. /** Tab titles inside one container, in strip order. */
  169. async function tabTitles(root: Locator): Promise<string[]> {
  170. return await root.locator('[data-dockkit-tab-title]').allInnerTexts()
  171. }
  172. /**
  173. * A rendered width, read once the frame's track transition has settled.
  174. *
  175. * The frame eases its grid tracks, so a single sample taken right after a
  176. * gesture reports a frame of the animation. Column arithmetic is only exact at
  177. * rest, so this samples until three consecutive readings agree.
  178. */
  179. async function width(locator: Locator): Promise<number> {
  180. let last = Number.NaN
  181. let steady = 0
  182. for (let attempt = 0; attempt < 80; attempt += 1) {
  183. // Layout width, not the visible box: a zero-width track is still an answer.
  184. const now = Math.round(await locator.evaluate(node => node.getBoundingClientRect().width))
  185. steady = now === last ? steady + 1 : 0
  186. if (steady === 2) return now
  187. last = now
  188. await locator.page().waitForTimeout(50)
  189. }
  190. throw new Error(`width never settled (last ${last}px)`)
  191. }
  192. describe('web e2e: shipped right Sidebar', () => {
  193. let scaffold: WebScaffold
  194. let browser: Browser
  195. let page: Page
  196. let tripwire: ReturnType<typeof watchConsole>
  197. beforeAll(async () => {
  198. scaffold = await launchWebScaffold()
  199. browser = await chromium.launch()
  200. page = await newEnglishPage(browser)
  201. tripwire = watchConsole(page)
  202. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  203. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  204. }, 180_000)
  205. afterAll(async () => {
  206. await browser?.close()
  207. await scaffold?.close()
  208. })
  209. it('shows nothing on the right while no session keys a surface', async () => {
  210. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-hero'))
  211. const frame = page.locator('[class*="frame"]').first()
  212. const column = page.locator('[data-rightbar-col]')
  213. await column.waitFor({ state: 'attached', timeout: 15_000 })
  214. // With no session there is no surface: no panel in the column, no expand
  215. // button in the header, and no track — the conversation reaches the frame's edge.
  216. expect(await frame.getAttribute('data-rightbar-collapsed')).toBe('true')
  217. expect(await column.locator('[data-sidebar-right-panel]').count()).toBe(0)
  218. expect(await expandOf(page).count()).toBe(0)
  219. expect(await width(column)).toBe(0)
  220. await shot(page, '01-hero-no-sidebar')
  221. expect(tripwire.pageErrors).toEqual([])
  222. expect(tripwire.warnings).toEqual([])
  223. })
  224. describe('with a settled session', () => {
  225. beforeAll(async () => {
  226. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  227. // A settled session is what keys the surface; seed one turn through the
  228. // real append path so the Chat surface is live before the Sidebar is driven.
  229. const agent = scaffold.ctx.agents.list()[0]
  230. if (agent === undefined) throw new Error('connected workspace did not create an Agent')
  231. // The wire parameter is `agentId`; the client passes a session id. If the
  232. // scaffold's Agent and Session carry different ids, that mismatch is the
  233. // silent lookup failure.
  234. expect(String(agent.id)).toBe(String(agent.session.id))
  235. agent.session.append('turn/start', { turn: 1 })
  236. agent.session.append('user/message', createUserMessage({
  237. content: [{ type: 'text', text: 'Show the right sidebar.' }],
  238. source: { kind: 'user' },
  239. }), { surfaceOp: 'append' })
  240. agent.session.append('step/start', { turn: 1, step: 1 })
  241. // A successful mutation is what makes the turn tail offer a produced-file
  242. // chip — the product's own way into the Sidebar. The file is written for
  243. // real because the preview reads it through the workspace endpoint.
  244. //
  245. // It goes in the SESSION's cwd, not the scaffold's: the endpoint resolves
  246. // relative paths against `sandboxPolicy.resolve({session}).workspaceRoot`,
  247. // which is the session header's cwd. Writing anywhere else makes the read
  248. // fail with workspace-file/not-found, which is the endpoint being right.
  249. writeFileSync(join(agent.session.header.cwd ?? scaffold.workspaceCwd, SAMPLE_NAME), SAMPLE_TEXT, 'utf8')
  250. agent.session.append('tool/call', {
  251. turn: 1,
  252. step: 1,
  253. callId: 'call-write-1',
  254. name: 'write',
  255. arguments: JSON.stringify({ file_path: SAMPLE_NAME, content: SAMPLE_TEXT }),
  256. } as never)
  257. agent.session.append('tool/result', {
  258. turn: 1,
  259. step: 1,
  260. message: {
  261. id: 'result-call-write-1',
  262. role: 'user',
  263. source: { kind: 'tool', callId: 'call-write-1' },
  264. content: [{ type: 'tool-result', toolCallId: 'call-write-1', content: [{ type: 'text', text: 'ok' }] }],
  265. },
  266. } as never, { surfaceOp: 'append' })
  267. agent.session.append('assistant/message', {
  268. stream: [],
  269. turn: 1,
  270. step: 1,
  271. message: createMessage({
  272. role: 'assistant',
  273. content: [{ type: 'text', text: 'Ready.' }],
  274. source: { kind: 'model', provider: 'fixture', model: 'fixture' },
  275. }),
  276. }, { surfaceOp: 'append' })
  277. agent.session.append('step/end', { turn: 1, step: 1 })
  278. agent.session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
  279. await scaffold.ctx.sessions.flush(agent.session)
  280. await page.getByText('Ready.').waitFor({ timeout: 10_000 })
  281. }, 120_000)
  282. it('CONTROL: the old fileReferences namespace answers over the same wire', async () => {
  283. const composer = page.locator('textarea, [contenteditable="true"]').first()
  284. await composer.click()
  285. await composer.pressSequentially('@')
  286. // Any candidate list means the agent-scoped lookup and the gateway route
  287. // both work in this scaffold; nothing rendered means the wire is the fault.
  288. const answered = await page.locator('[data-input-trigger], [role="listbox"], [data-reference-list]')
  289. .first().waitFor({ timeout: 10_000 }).then(() => true, () => false)
  290. await page.keyboard.press('Escape')
  291. // Leave the composer as it was found: these cases share one page, and a
  292. // stray '@' rides into every later assertion and screenshot. `fill('')`
  293. // does NOT clear this editor — it reported success while the character
  294. // stayed — so the reset is a real keystroke, and it is asserted rather
  295. // than assumed.
  296. await composer.click()
  297. await page.keyboard.press('ControlOrMeta+a')
  298. await page.keyboard.press('Backspace')
  299. await expect.poll(async () => (await composer.innerText()).trim()).toBe('')
  300. expect(answered).toBe(true)
  301. })
  302. it('starts collapsed behind a header button and squeezes the conversation when opened', async () => {
  303. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right'))
  304. const frame = page.locator('[class*="frame"]').first()
  305. const column = page.locator('[data-rightbar-col]')
  306. const conversation = page.locator('[class*="centerCol"]').first()
  307. const expand = expandOf(page)
  308. // Collapsed default: no track, the panel sits off the frame's edge, and
  309. // the only way in is the header button — on the same row as the other
  310. // header utilities, at its far right.
  311. await expand.waitFor({ timeout: 15_000 })
  312. expect(await frame.getAttribute('data-rightbar-collapsed')).toBe('true')
  313. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  314. const utilities = page.locator('[class*="headerUtilities"]')
  315. const expandBox = await expand.boundingBox()
  316. const rowBox = await utilities.boundingBox()
  317. if (expandBox === null || rowBox === null) throw new Error('header utilities are not rendered')
  318. expect(Math.round(expandBox.y + expandBox.height / 2)).toBe(Math.round(rowBox.y + rowBox.height / 2))
  319. // Its own corner seat, past the utilities' right edge — not a utility.
  320. expect(expandBox.x).toBeGreaterThan(rowBox.x + rowBox.width)
  321. const conversationBoxBefore = await conversation.boundingBox()
  322. if (conversationBoxBefore === null) throw new Error('conversation is not rendered')
  323. // How far the utilities' right edge sits from the conversation's own.
  324. const gapBefore = (conversationBoxBefore.x + conversationBoxBefore.width) - (rowBox.x + rowBox.width)
  325. const centerBefore = await width(conversation)
  326. await shot(page, '02a-collapsed-header-button')
  327. // Opening squeezes by default: the column takes a track of the panel's
  328. // width, the conversation gives up exactly that much room, and the header
  329. // button leaves with the panel's arrival.
  330. await expand.click()
  331. await expect.poll(async () => await frame.getAttribute('data-rightbar-collapsed')).toBe(null)
  332. await expect.poll(async () => await column.locator('[data-sidebar-right-open]').count()).toBe(1)
  333. const panelWidth = await width(column)
  334. expect(panelWidth).toBeGreaterThan(0)
  335. expect(await width(conversation)).toBe(centerBefore - panelWidth)
  336. await expect.poll(async () => await expand.count()).toBe(0)
  337. // The corner seat collapses with its button, so the utilities' right edge
  338. // moves out toward the conversation's own.
  339. const utilitiesAfter = await utilities.boundingBox()
  340. const conversationAfter = await conversation.boundingBox()
  341. if (utilitiesAfter === null || conversationAfter === null) throw new Error('header is not rendered')
  342. const gapAfter = (conversationAfter.x + conversationAfter.width) - (utilitiesAfter.x + utilitiesAfter.width)
  343. expect(gapAfter).toBeLessThan(gapBefore)
  344. // The panel is in the column, not over it, and carries the seeded tab —
  345. // whose body arrives through the Files type's keyed registration, not from
  346. // any dispatch inside the seat. Its two controls sit at the end of the
  347. // top-right pane's strip: the panel has no header row of its own.
  348. expect(await column.locator('[data-sidebar-right-panel="push"]').count()).toBe(1)
  349. const chrome = column.locator('[data-dockkit-strip-chrome]')
  350. expect(await chrome.count()).toBe(1)
  351. expect(await chrome.locator('[data-sidebar-right-mode]').count()).toBe(1)
  352. expect(await chrome.locator('[data-sidebar-right-toggle]').count()).toBe(1)
  353. // One centre line across the strip: chip text, split, and the two panel
  354. // controls all sit at the same height. The add control joins the check below.
  355. const centreY = async (selector: string): Promise<number> => {
  356. const box = await column.locator(selector).first().boundingBox()
  357. if (box === null) throw new Error(`${selector} is not rendered`)
  358. return Math.round(box.y + box.height / 2)
  359. }
  360. const textLine = await centreY('[data-dockkit-tab-title]')
  361. for (const selector of ['[data-dockkit-split-button]', '[data-sidebar-right-mode]', '[data-sidebar-right-toggle]']) {
  362. expect(await centreY(selector), selector).toBe(textLine)
  363. }
  364. await expect.poll(async () => await tabTitles(column)).toEqual(['Start'])
  365. await expect.poll(async () => await column.locator('[data-sidebar-right-guide-entry]').count()).toBe(2)
  366. await column.locator('[data-sidebar-right-guide-entry="files"]').click()
  367. // A manual guide is closable beside Files and suppresses another add
  368. // control in its pane until it is closed.
  369. const addTab = column.locator('[data-dockkit-add-tab]')
  370. const filesTab = column.locator('[data-dockkit-tab]').filter({ hasText: 'Files' })
  371. await expect.poll(async () => await tabTitles(column)).toEqual(['Files'])
  372. await column.locator('[data-files-state="tree"]').waitFor({ state: 'visible' })
  373. expect(await filesTab.locator('[data-dockkit-tab-close]').count()).toBe(1)
  374. await expect.poll(async () => await addTab.count()).toBe(1)
  375. expect(await centreY('[data-dockkit-add-tab]')).toBe(textLine)
  376. await addTab.click()
  377. await expect.poll(async () => await tabTitles(column)).toEqual(['Files', 'Start'])
  378. await expect.poll(async () => await column.locator('[data-sidebar-right-guide]').count()).toBe(1)
  379. await expect.poll(async () => await addTab.count()).toBe(0)
  380. expect(await filesTab.locator('[data-dockkit-tab-close]').count()).toBe(1)
  381. const guideTab = column.locator('[data-dockkit-tab]').filter({ hasText: 'Start' })
  382. expect(await guideTab.locator('[data-dockkit-tab-close]').count()).toBe(1)
  383. // Back to the seeded shape the cases below start from.
  384. await guideTab.hover()
  385. await guideTab.locator('[data-dockkit-tab-close]').click()
  386. await expect.poll(async () => await tabTitles(column)).toEqual(['Files'])
  387. await expect.poll(async () => await addTab.count()).toBe(1)
  388. await shot(page, '02-squeezed-panel')
  389. expect(tripwire.pageErrors).toEqual([])
  390. expect(tripwire.warnings).toEqual([])
  391. })
  392. it('covers the viewport in fullscreen without changing the underlying columns', async () => {
  393. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-mode'))
  394. const frame = page.locator('[class*="frame"]').first()
  395. const column = page.locator('[data-rightbar-col]')
  396. const panel = column.locator('[data-sidebar-right-panel]')
  397. const conversation = page.locator('[class*="centerCol"]').first()
  398. const squeezed = await width(conversation)
  399. const before = await panel.boundingBox()
  400. const trackWidth = await width(column)
  401. await column.locator('[data-sidebar-right-mode="fullscreen"]').click()
  402. await expect.poll(async () => await panel.getAttribute('data-sidebar-right-panel')).toBe('fullscreen')
  403. expect(await frame.getAttribute('data-rightbar-collapsed')).toBe(null)
  404. expect(await width(conversation)).toBe(squeezed)
  405. expect(await width(column)).toBe(trackWidth)
  406. const viewport = page.viewportSize()
  407. if (viewport === null) throw new Error('expected a fixed viewport')
  408. await expect.poll(async () => await panel.boundingBox()).toEqual({ x: 0, y: 0, ...viewport })
  409. expect(await expandOf(page).count()).toBe(0)
  410. expect(await frame.locator('[data-side="rightbar"]').count()).toBe(0)
  411. await shot(page, '03-fullscreen-panel')
  412. await column.locator('[data-sidebar-right-mode="push"]').click()
  413. await expect.poll(async () => await panel.getAttribute('data-sidebar-right-panel')).toBe('push')
  414. expect(await width(conversation)).toBe(squeezed)
  415. expect(await panel.boundingBox()).toEqual(before)
  416. expect(tripwire.pageErrors).toEqual([])
  417. expect(tripwire.warnings).toEqual([])
  418. })
  419. it('keeps the conversation still during fullscreen entry and installs the hidden track without animation', async () => {
  420. onTestFailed(() => saveFailureShot(page, 'screenshots/0907-sidebar-rules/sidebar-right-fullscreen-entry'))
  421. mkdirSync(SHOT_DIR, { recursive: true })
  422. const column = await resetSidebar(page)
  423. const frame = page.locator('[class*="frame"]').first()
  424. const panel = column.locator('[data-sidebar-right-panel]')
  425. const viewport = page.viewportSize()
  426. if (viewport === null) throw new Error('expected a fixed viewport')
  427. const geometry = () => frame.evaluate(node => ({
  428. columns: getComputedStyle(node).gridTemplateColumns,
  429. transition: getComputedStyle(node).transitionProperty,
  430. handles: [...node.querySelectorAll('[data-side="sidebar"], [data-side="rightbar"]')]
  431. .map(handle => getComputedStyle(handle).transitionProperty),
  432. animatingGrid: node.getAnimations().some(animation =>
  433. 'transitionProperty' in animation && animation.transitionProperty === 'grid-template-columns'
  434. && animation.playState !== 'finished' && animation.playState !== 'idle'),
  435. }))
  436. await frame.evaluate(async (node) => { await Promise.allSettled(node.getAnimations().map(animation => animation.finished)) })
  437. const normalColumns = (await geometry()).columns
  438. await column.locator('[data-sidebar-right-mode="fullscreen"]').click()
  439. await expect.poll(() => panel.boundingBox()).toEqual({ x: 0, y: 0, ...viewport })
  440. await column.locator('[data-sidebar-right-toggle]').click()
  441. await Promise.all([
  442. panel.evaluate(async (node) => { await Promise.allSettled(node.getAnimations().map(animation => animation.finished)) }),
  443. frame.evaluate(async (node) => { await Promise.allSettled(node.getAnimations().map(animation => animation.finished)) }),
  444. ])
  445. const closedColumns = (await geometry()).columns
  446. expect(closedColumns).not.toBe(normalColumns)
  447. await page.emulateMedia({ reducedMotion: 'no-preference' })
  448. // Pause the real CSS transition at its midpoint so host scheduling cannot
  449. // skip the partly covered frame whose underlying width is under test.
  450. const held = await holdPanelSlide(panel)
  451. try {
  452. await expandOf(page).click()
  453. await expect.poll(() => held.evaluate(state => state.animation?.playState)).toBe('paused')
  454. const entering = await panel.boundingBox()
  455. if (entering === null) throw new Error('entering panel is not rendered')
  456. expect(entering.x).toBeGreaterThan(0)
  457. expect(entering.x).toBeLessThan(viewport.width)
  458. expect((await geometry()).columns).toBe(closedColumns)
  459. expect((await geometry()).animatingGrid).toBe(false)
  460. expect(await frame.getAttribute('data-rightbar-fullscreen')).toBeNull()
  461. await held.evaluate((state) => { (state.animation as Animation).finish() })
  462. await expect.poll(() => frame.getAttribute('data-rightbar-fullscreen')).toBe('true')
  463. expect(await panel.boundingBox()).toEqual({ x: 0, y: 0, ...viewport })
  464. expect(await geometry()).toEqual({ columns: normalColumns, transition: 'none', handles: ['none'], animatingGrid: false })
  465. const exit = await holdPanelSlide(panel)
  466. try {
  467. await column.locator('[data-sidebar-right-toggle]').click()
  468. await expect.poll(() => exit.evaluate(state => state.animation?.playState)).toBe('paused')
  469. expect(await exit.evaluate(state => state.columnsAtStart)).toBe(closedColumns)
  470. const leaving = await panel.boundingBox()
  471. if (leaving === null) throw new Error('leaving panel is not rendered')
  472. expect(leaving.x).toBeGreaterThan(0)
  473. expect(leaving.x).toBeLessThan(viewport.width)
  474. expect(await geometry()).toEqual({ columns: closedColumns, transition: 'none', handles: ['none'], animatingGrid: false })
  475. await exit.evaluate((state) => { (state.animation as Animation).finish() })
  476. expect((await geometry()).columns).toBe(closedColumns)
  477. } finally {
  478. await exit.evaluate((state) => {
  479. state.dispose()
  480. if (state.animation?.playState === 'paused') state.animation.finish()
  481. })
  482. await exit.dispose()
  483. }
  484. await expandOf(page).click()
  485. await expect.poll(() => frame.getAttribute('data-rightbar-fullscreen')).toBe('true')
  486. await column.locator('[data-sidebar-right-mode="push"]').click()
  487. expect((await geometry()).columns).toBe(normalColumns)
  488. expect((await geometry()).animatingGrid).toBe(false)
  489. await page.emulateMedia({ reducedMotion: 'reduce' })
  490. await column.locator('[data-sidebar-right-mode="fullscreen"]').click()
  491. await column.locator('[data-sidebar-right-toggle]').click()
  492. await expect.poll(() => frame.getAttribute('data-rightbar-fullscreen')).toBeNull()
  493. await expandOf(page).click()
  494. await expect.poll(() => frame.getAttribute('data-rightbar-fullscreen')).toBe('true')
  495. expect(await panel.boundingBox()).toEqual({ x: 0, y: 0, ...viewport })
  496. expect((await geometry()).columns).toBe(normalColumns)
  497. expect((await geometry()).animatingGrid).toBe(false)
  498. } finally {
  499. await held.evaluate((state) => {
  500. state.dispose()
  501. if (state.animation?.playState === 'paused') state.animation.finish()
  502. })
  503. await held.dispose()
  504. try {
  505. if (await panel.getAttribute('data-sidebar-right-panel') === 'fullscreen'
  506. && await panel.getAttribute('data-sidebar-right-open') !== null) {
  507. await column.locator('[data-sidebar-right-mode="push"]').click()
  508. }
  509. } finally {
  510. await page.emulateMedia({ reducedMotion: null })
  511. }
  512. }
  513. expect(tripwire.pageErrors).toEqual([])
  514. expect(tripwire.warnings).toEqual([])
  515. })
  516. it('keeps a capacity-closed panel closed after widening and uses fullscreen on a narrow viewport', async () => {
  517. const viewport = page.viewportSize()
  518. if (viewport === null) throw new Error('expected a fixed viewport')
  519. const frame = page.locator('[class*="frame"]').first()
  520. const column = page.locator('[data-rightbar-col]')
  521. const sidebar = page.locator('[class*="sidebarCol"]').first()
  522. const panel = column.locator('[data-sidebar-right-panel]')
  523. try {
  524. await page.setViewportSize({ width: 1024, height: viewport.height })
  525. const leftGrip = frame.locator('[data-side="sidebar"]')
  526. const grip = await centre(leftGrip)
  527. await dragElement(page, leftGrip, { x: 420, y: grip.y })
  528. await expect.poll(async () => await width(sidebar)).toBe(420)
  529. await expect.poll(async () => await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  530. await page.setViewportSize(viewport)
  531. await expect.poll(async () => await width(sidebar)).toBe(420)
  532. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  533. await expandOf(page).click()
  534. await expect.poll(async () => await column.locator('[data-sidebar-right-open]').count()).toBe(1)
  535. await page.setViewportSize({ width: 767, height: viewport.height })
  536. await expect.poll(async () => await panel.getAttribute('data-sidebar-right-panel')).toBe('fullscreen')
  537. await expect.poll(async () => await width(panel)).toBe(767)
  538. await expect.poll(() => frame.getAttribute('data-rightbar-fullscreen')).toBe('true')
  539. expect(await frame.locator('[data-side="rightbar"]').count()).toBe(0)
  540. await column.locator('[data-sidebar-right-mode="push"]').click()
  541. await expect.poll(async () => await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  542. await page.setViewportSize(viewport)
  543. await expect.poll(async () => await width(sidebar)).toBe(420)
  544. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  545. } finally {
  546. await page.setViewportSize(viewport)
  547. const grip = await centre(frame.locator('[data-side="sidebar"]'))
  548. await dragElement(page, frame.locator('[data-side="sidebar"]'), { x: 280, y: grip.y })
  549. await expect.poll(async () => await width(sidebar)).toBe(280)
  550. await ensureExpanded(page, column)
  551. }
  552. expect(tripwire.pageErrors).toEqual([])
  553. expect(tripwire.warnings).toEqual([])
  554. })
  555. it('survives grip drags past both clamps on a squeezed viewport', async () => {
  556. // Regression: an overshoot drag swept the panel through widths where a
  557. // width-blocked split control hid itself, which changed the very strip
  558. // measurement that had blocked it — a layout-effect feedback loop that
  559. // crashed the pane (React error #185) and unmounted the rightbar slot
  560. // entry while the column still believed it was expanded, so neither the
  561. // panel nor the header's expand button remained. The crash surfaces only
  562. // as a console error, which the scaffold tripwire does not watch, so this
  563. // case collects console errors itself.
  564. const viewport = page.viewportSize()
  565. if (viewport === null) throw new Error('expected a fixed viewport')
  566. const column = await resetSidebar(page)
  567. const frame = page.locator('[class*="frame"]').first()
  568. const panel = column.locator('[data-sidebar-right-panel]')
  569. const consoleErrors: string[] = []
  570. const collect = (message: ConsoleMessage): void => {
  571. if (message.type() === 'error') consoleErrors.push(message.text().slice(0, 600))
  572. }
  573. page.on('console', collect)
  574. try {
  575. await page.setViewportSize({ width: 1000, height: viewport.height })
  576. await ensureExpanded(page, column)
  577. await width(column)
  578. const grip = frame.locator('[data-side="rightbar"]')
  579. // The frame reads the new viewport through a throttled ResizeObserver,
  580. // a couple of frames after the resize; until then the grip sits at the
  581. // old frame's coordinates. Press only a grip aligned with the panel's
  582. // left edge (the handle is 8px wide, centred on the seam).
  583. await expect.poll(async () => {
  584. const gripBox = await grip.boundingBox()
  585. const panelBox = await panel.boundingBox()
  586. if (gripBox === null || panelBox === null) return Number.NaN
  587. return Math.abs(gripBox.x + 4 - panelBox.x)
  588. }).toBeLessThanOrEqual(1)
  589. // Narrow with overshoot: drag the grip far right past the clamp floor.
  590. const from = await centre(grip)
  591. await page.mouse.move(from.x, from.y)
  592. await page.mouse.down()
  593. await page.mouse.move(980, from.y, { steps: 30 })
  594. await page.mouse.up()
  595. // The panel holds its floor, still open, with its grip still rendered.
  596. await expect.poll(async () => await width(panel)).toBeLessThanOrEqual(302)
  597. expect(await width(panel)).toBeGreaterThanOrEqual(300)
  598. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(1)
  599. expect(await grip.count()).toBe(1)
  600. // Widen with overshoot to the far left: clamped by the frame's range.
  601. const back = await centre(grip)
  602. await page.mouse.move(back.x, back.y)
  603. await page.mouse.down()
  604. await page.mouse.move(20, back.y, { steps: 30 })
  605. await page.mouse.up()
  606. const widened = await width(panel)
  607. expect(widened).toBeGreaterThan(302)
  608. expect(widened).toBeLessThan(1000)
  609. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(1)
  610. expect(await grip.count()).toBe(1)
  611. expect(consoleErrors).toEqual([])
  612. expect(tripwire.pageErrors).toEqual([])
  613. expect(tripwire.warnings).toEqual([])
  614. } finally {
  615. page.off('console', collect)
  616. await page.setViewportSize(viewport)
  617. await ensureExpanded(page, column)
  618. await setPanelWidth(page, Math.round(viewport.width * 0.45))
  619. }
  620. }, 60_000)
  621. it('CONTROL: the host endpoint answers when called directly, bypassing the wire', async () => {
  622. const files = (scaffold.ctx as unknown as {
  623. get(name: string): {
  624. read(agent: unknown, path: string, range: object, signal: AbortSignal): Promise<{ text: string; eof: boolean }>
  625. } | undefined
  626. }).get('workspaceFiles')
  627. if (files === undefined) throw new Error('host endpoint is not provided')
  628. const agent = scaffold.ctx.agents.list()[0]
  629. if (agent === undefined) throw new Error('no Agent to read for')
  630. // Raced against a timer so a hang reports a verdict instead of stalling
  631. // the suite: this case exists to tell host logic apart from the wire.
  632. // A page is the file's lines joined by `\n`, without the final terminator.
  633. const verdict = await Promise.race([
  634. files.read(agent, SAMPLE_NAME, {}, new AbortController().signal)
  635. .then(value => ({ kind: 'settled' as const, text: value.text, eof: value.eof }))
  636. .catch((error: unknown) => ({ kind: 'threw' as const, text: String(error), eof: false })),
  637. new Promise<{ kind: 'hung'; text: string; eof: boolean }>((resolve) => {
  638. setTimeout(() => { resolve({ kind: 'hung', text: 'no settlement in 10s', eof: false }) }, 10_000)
  639. }),
  640. ])
  641. expect(verdict).toEqual({ kind: 'settled', text: SAMPLE_TEXT.replace(/\n$/u, ''), eof: true })
  642. }, 30_000)
  643. it('opens content once, splits, and floats it outside the column', async () => {
  644. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-content'))
  645. const column = page.locator('[data-rightbar-col]')
  646. const panes = column.locator('[data-dockkit-pane]')
  647. const floats = page.locator('[data-sidebar-right-float-host] [data-dockkit-float]')
  648. // Observation before action: does the read ever leave the browser? The
  649. // assertion states the healthy answer so a failure prints the real one.
  650. //
  651. // CAVEAT: `sent` is trustworthy — a request frame carries the endpoint
  652. // name. `received` is NOT: a response frame carries only its rpc id, so a
  653. // zero here means "my filter saw nothing", not "the host never answered".
  654. // Correlate by rpc id before drawing any conclusion from it.
  655. const wire = { sent: 0, received: 0 }
  656. const watch = (payload: string): void => {
  657. if (!payload.includes('workspaceFiles')) return
  658. wire.sent += 1
  659. }
  660. page.on('websocket', (ws) => {
  661. ws.on('framesent', (frame) => { watch(String(frame.payload)) })
  662. ws.on('framereceived', (frame) => {
  663. if (String(frame.payload).includes('workspaceFiles')) wire.received += 1
  664. })
  665. })
  666. page.on('request', (request) => {
  667. if (request.url().includes('workspaceFiles')) wire.sent += 1
  668. })
  669. // The product's own entry point: the turn tail's produced-file chip. It
  670. // reaches the Sidebar through openFile → ctx.sidebarRight.openResource, and the
  671. // text type claims the address.
  672. const chip = page.getByRole('button', { name: `Open ${SAMPLE_NAME}` })
  673. await chip.click()
  674. await expect.poll(async () => await tabTitles(column)).toEqual(['Files', SAMPLE_NAME])
  675. // Opening the same content again focuses rather than duplicating.
  676. await panes.first().locator('[data-dockkit-tab]').first().click()
  677. await chip.click()
  678. await expect.poll(async () => await tabTitles(column)).toEqual(['Files', SAMPLE_NAME])
  679. // The body arrives through the text type's keyed registration, and its
  680. // content came over the wire from the real file.
  681. // A real Remote round-trip settles well after the default poll window.
  682. await column.locator('[data-textpreview-state="text"]')
  683. .waitFor({ timeout: 15_000 })
  684. .catch(() => { throw new Error(`preview never settled; wire=${JSON.stringify(wire)}`) })
  685. expect(await column.locator('pre').first().innerText()).toContain('produced by the seeded turn')
  686. // The whole batch-E chain in one frame: a produced-file chip in the
  687. // conversation, the tab it opened, and the file's real content read over
  688. // the workspace endpoint.
  689. await shot(page, '06-produced-chip-to-preview')
  690. // The directory scenario's V1 behaviour, asserted in the shipped product:
  691. // there is no folder affordance at all. `openFile('.')` would name a
  692. // directory, which a text preview correctly refuses, and the native opener
  693. // it used to reach is gone — so the row offers nothing rather than a
  694. // button that always fails.
  695. expect(await page.getByRole('button', { name: /folder/i }).count()).toBe(0)
  696. // Split, then dock-drag: the kit's gestures drive the store's actions.
  697. await panes.first().locator('[data-dockkit-split-button]').click()
  698. await expect.poll(async () => await panes.count()).toBe(2)
  699. await dragTo(
  700. page,
  701. column.locator('[data-dockkit-tab]').filter({ hasText: SAMPLE_NAME }).first(),
  702. await pointIn(panes.nth(1), 0.5, 0.94),
  703. )
  704. await expect.poll(async () => await panes.count()).toBe(2)
  705. const splitGuide = panes.nth(1).locator('[data-dockkit-tab]').filter({ hasText: 'Start' })
  706. expect(await splitGuide.locator('[data-dockkit-tab-close]').count()).toBe(1)
  707. await dragTo(page, splitGuide, await pointIn(panes.first(), 0.5, 0.5))
  708. await expect.poll(async () => await tabTitles(panes.nth(1))).toEqual([SAMPLE_NAME])
  709. const movedGuide = panes.first().locator('[data-dockkit-tab]').filter({ hasText: 'Start' })
  710. await movedGuide.hover()
  711. await movedGuide.locator('[data-dockkit-tab-close]').click()
  712. // Neither pane holds a guide, so both offer an add control.
  713. const filePane = panes.filter({ has: page.locator('[data-dockkit-tab-title]', { hasText: SAMPLE_NAME }) })
  714. await expect.poll(async () => await filePane.locator('[data-dockkit-add-tab]').count()).toBe(1)
  715. expect(await column.locator('[data-dockkit-add-tab]').count()).toBe(2)
  716. // Floating leaves the column entirely, and survives collapsing it. The
  717. // pane the tab was alone in goes with it: an emptied pane never stays.
  718. const tab = column.locator('[data-dockkit-tab]').filter({ hasText: SAMPLE_NAME }).first()
  719. await floatByDrag(page, tab)
  720. await expect.poll(async () => await floats.count()).toBe(1)
  721. expect(await column.locator('[data-dockkit-float]').count()).toBe(0)
  722. await expect.poll(async () => await panes.count()).toBe(1)
  723. await shot(page, '04-split-and-float')
  724. await column.locator('[data-sidebar-right-toggle]').click()
  725. await expect.poll(async () => await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  726. expect(await floats.count()).toBe(1)
  727. expect(tripwire.pageErrors).toEqual([])
  728. expect(tripwire.warnings).toEqual([])
  729. })
  730. // §9.2 (an explicit second copy of the same content) has no control on the
  731. // panel by product decision, and copy has no service method yet:
  732. // `duplicateTab` is a store/kit intent only, which service.client.spec.ts covers.
  733. it('keeps each session\'s surface to itself, and restores it on return', async () => {
  734. const fx = await newEnglishPage(browser)
  735. const fxTripwire = watchConsole(fx)
  736. onTestFailed(() => saveFailureShot(fx, 'web-e2e-sidebar-right-sessions'))
  737. try {
  738. await fx.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  739. const settled = fx.getByRole('treeitem', { name: /Show the right sidebar\./u }).first()
  740. await settled.click()
  741. await expect.poll(async () => await settled.getAttribute('aria-selected')).toBe('true')
  742. const frame = fx.locator('[class*="frame"]').first()
  743. const column = fx.locator('[data-rightbar-col]')
  744. await ensureExpanded(fx, column)
  745. await width(column)
  746. await fx.getByRole('button', { name: `Open ${SAMPLE_NAME}` }).click()
  747. await column.locator('[data-textpreview-state="text"]').waitFor({ timeout: 15_000 })
  748. const wrap = column.locator('[data-textpreview-tool="wrap"]')
  749. expect(await wrap.getAttribute('aria-pressed')).toBe('true')
  750. await wrap.click()
  751. await expect.poll(async () => await wrap.getAttribute('aria-pressed')).toBe('false')
  752. await column.locator('[data-dockkit-split-button]').first().click()
  753. const panes = column.locator('[data-dockkit-pane]')
  754. await expect.poll(async () => await panes.count()).toBe(2)
  755. const records = async (): Promise<{ panes: string[]; tabs: string[]; titles: string[] }> => ({
  756. panes: await panes.evaluateAll(nodes => nodes.map(node => node.getAttribute('data-dockkit-pane')!)),
  757. tabs: await column.locator('[data-dockkit-tab]').evaluateAll(nodes => nodes.map(node => node.getAttribute('data-dockkit-tab')!)),
  758. titles: await tabTitles(column),
  759. })
  760. const before = await records()
  761. // The real New Session action selects a distinct blank Session; its
  762. // collapsed surface must not inherit the settled Session's tabs.
  763. await fx.getByRole('button', { name: 'New session', exact: true }).last().click()
  764. await expect.poll(async () => await settled.getAttribute('aria-selected')).toBe('false')
  765. await expect.poll(async () => await frame.getAttribute('data-rightbar-collapsed')).toBe('true')
  766. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  767. expect(await column.locator('[data-textpreview-state="text"]').count()).toBe(0)
  768. await settled.click()
  769. await expect.poll(async () => await settled.getAttribute('aria-selected')).toBe('true')
  770. await expect.poll(records, { timeout: 15_000 }).toEqual(before)
  771. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(1)
  772. expect(await wrap.getAttribute('aria-pressed')).toBe('false')
  773. expect(await column.locator('pre').first().innerText()).toContain('produced by the seeded turn')
  774. expect(fxTripwire.pageErrors).toEqual([])
  775. expect(fxTripwire.warnings).toEqual([])
  776. } finally {
  777. await fx.close()
  778. }
  779. }, 120_000)
  780. it('§9.3/§9.4 runs the whole pointer chain in a real browser', async () => {
  781. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-gestures'))
  782. const column = await resetSidebar(page)
  783. const panes = column.locator('[data-dockkit-pane]')
  784. const floats = page.locator('[data-sidebar-right-float-host] [data-dockkit-float]')
  785. // Chromium cancels pointer capture if a render replaces the pressed
  786. // element; jsdom cannot establish that the whole gesture survives.
  787. // 1. Reorder inside one strip: drop the last tab left of its neighbours.
  788. // The first pane needs two tabs for this — and for the move below to
  789. // leave it standing, since a pane emptied by a move is dropped.
  790. const first = panes.first()
  791. const strip = first.locator('[data-dockkit-strip]')
  792. await page.getByRole('button', { name: `Open ${SAMPLE_NAME}` }).click()
  793. await expect.poll(async () => await tabTitles(first)).toEqual(['Files', SAMPLE_NAME])
  794. const order = await tabTitles(first)
  795. // The insertion index is measured against chip midpoints, not strip width.
  796. await dragTo(page, first.locator('[data-dockkit-tab]').last(),
  797. await pointIn(first.locator('[data-dockkit-tab]').first(), 0.25, 0.5),
  798. strip.locator('[data-dockkit-caret="0"]'))
  799. await expect.poll(async () => await tabTitles(first)).toEqual([...order].reverse())
  800. // 2. Cross-pane move into a second pane: the tab leaves one pane's strip
  801. // for another's.
  802. if (await panes.count() < 2) {
  803. await first.locator('[data-dockkit-split-button]').click()
  804. await expect.poll(async () => await panes.count()).toBe(2)
  805. }
  806. const moving = first.locator('[data-dockkit-tab]').first()
  807. const title = await moving.locator('[data-dockkit-tab-title]').innerText()
  808. await dragTo(page, moving, await pointIn(panes.nth(1), 0.5, 0.5))
  809. await expect.poll(async () => await tabTitles(panes.nth(1))).toContain(title)
  810. const splitButtons = column.locator('[data-dockkit-split-button]')
  811. await expect.poll(async () => await splitButtons.count()).toBe(0)
  812. expect(await panes.count()).toBe(2)
  813. await setPanelWidth(page, 560)
  814. await expect.poll(async () => await splitButtons.count()).toBe(0)
  815. const outer = column.locator('[data-dockkit-divider]').first()
  816. const before = await width(panes.last())
  817. const grip = await centre(outer)
  818. await dragElement(page, outer, { x: grip.x - 100, y: grip.y })
  819. await expect.poll(async () => await width(panes.last())).toBeGreaterThan(before)
  820. await dragElement(page, outer, { x: 0, y: grip.y })
  821. const ratio = async (): Promise<number> => {
  822. const left = await width(panes.first())
  823. const right = await width(panes.last())
  824. return left / (left + right)
  825. }
  826. await expect.poll(ratio).toBeCloseTo(0.2, 2)
  827. const surfaceBox = await column.locator('[data-dockkit-surface]').boundingBox()
  828. if (surfaceBox === null) throw new Error('surface is not rendered')
  829. await dragElement(page, outer, { x: surfaceBox.x + surfaceBox.width / 2, y: grip.y })
  830. await expect.poll(ratio).toBeCloseTo(0.5, 2)
  831. expect(await panes.count()).toBe(2)
  832. expect(await splitButtons.count()).toBe(0)
  833. // 5. The split's guide and the document float while Files stays docked.
  834. const floatOne = panes.last().locator('[data-dockkit-tab]').filter({ hasText: SAMPLE_NAME })
  835. await floatByDrag(page, floatOne)
  836. await expect.poll(async () => await floats.count()).toBe(1)
  837. const box = await floats.first().boundingBox()
  838. if (box === null) throw new Error('float is not rendered')
  839. await dragElement(page, floats.first().locator('[data-dockkit-float-grip]'), { x: box.x + 140, y: box.y + 90 })
  840. await expect.poll(async () => (await floats.first().boundingBox())?.x ?? box.x).not.toBe(box.x)
  841. await expect.poll(async () => await tabTitles(panes.last())).toEqual(['Start'])
  842. const second = panes.last().locator('[data-dockkit-tab]').filter({ hasText: 'Start' })
  843. await floatByDrag(page, second)
  844. await expect.poll(async () => await floats.count()).toBe(2)
  845. // 6. Dock one back: the docked tree takes it, the other float stays. Dock
  846. // the TOPMOST float — floats render bottom-to-top, so the newest one
  847. // covers the older one's controls and would intercept the click.
  848. await floats.last().locator('[data-dockkit-float-dock]').click()
  849. await expect.poll(async () => await floats.count()).toBe(1)
  850. expect(tripwire.pageErrors).toEqual([])
  851. expect(tripwire.warnings).toEqual([])
  852. }, 90_000)
  853. it('drops a pane whose last tab closes, and follows the last-tab rule on the surface', async () => {
  854. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-settle'))
  855. const column = await resetSidebar(page)
  856. const panes = column.locator('[data-dockkit-pane]')
  857. expect(await column.locator('[data-dockkit-tab-close]').count()).toBe(1)
  858. await page.getByRole('button', { name: `Open ${SAMPLE_NAME}` }).click()
  859. await expect.poll(async () => await tabTitles(panes.first())).toEqual(['Files', SAMPLE_NAME])
  860. await panes.first().locator('[data-dockkit-split-button]').click()
  861. await expect.poll(async () => await panes.count()).toBe(2)
  862. // Closing a pane's last tab drops the pane: there is no separate
  863. // "close pane" gesture, and none is needed.
  864. await panes.nth(1).locator('[data-dockkit-tab]').first().hover()
  865. await panes.nth(1).locator('[data-dockkit-tab-close]').first().click()
  866. await expect.poll(async () => await panes.count()).toBe(1)
  867. await expect.poll(async () => await tabTitles(column)).toEqual(['Files', SAMPLE_NAME])
  868. // Leave a guide as the sole docked tab.
  869. const files = column.locator('[data-dockkit-tab]').filter({ hasText: 'Files' })
  870. await files.hover()
  871. await files.locator('[data-dockkit-tab-close]').click()
  872. await column.locator('[data-dockkit-add-tab]').click()
  873. await expect.poll(async () => await tabTitles(column)).toEqual([SAMPLE_NAME, 'Start'])
  874. const sample = column.locator('[data-dockkit-tab]').filter({ hasText: SAMPLE_NAME })
  875. await sample.hover()
  876. await sample.locator('[data-dockkit-tab-close]').click()
  877. await expect.poll(async () => await tabTitles(column)).toEqual(['Start'])
  878. // The guide standing as the docked surface's only tab draws no close
  879. // control, sits quiet (no capsule, no hover fill), and a secondary press
  880. // opens no menu: an empty menu never shows.
  881. expect(await column.locator('[data-dockkit-tab-close]').count()).toBe(0)
  882. expect(await column.locator('[data-dockkit-tab-quiet]').count()).toBe(1)
  883. await column.locator('[data-dockkit-tab]').first().click({ button: 'right' })
  884. expect(await page.locator('[data-dockkit-tab-menu]').isVisible()).toBe(false)
  885. expect(await page.getByRole('menu').count()).toBe(0)
  886. // Any other tab standing alone closes together with the column. Open the
  887. // sample file, close the guide (an ordinary close with two tabs), then
  888. // close the file: the column collapses in the same gesture, and the
  889. // settle rule reseeds the current default, so reopening shows Start.
  890. await page.getByRole('button', { name: `Open ${SAMPLE_NAME}` }).click()
  891. await expect.poll(async () => await tabTitles(column)).toEqual(['Start', SAMPLE_NAME])
  892. await column.locator('[data-dockkit-tab]').first().hover()
  893. await column.locator('[data-dockkit-tab-close]').first().click()
  894. await expect.poll(async () => await tabTitles(column)).toEqual([SAMPLE_NAME])
  895. await column.locator('[data-dockkit-tab]').first().hover()
  896. await column.locator('[data-dockkit-tab-close]').first().click()
  897. await expect.poll(async () => await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  898. await expandOf(page).click()
  899. await expect.poll(async () => await tabTitles(column)).toEqual(['Start'])
  900. expect(await column.locator('[data-sidebar-right-guide]').count()).toBe(1)
  901. expect(tripwire.pageErrors).toEqual([])
  902. expect(tripwire.warnings).toEqual([])
  903. }, 90_000)
  904. it('§9.7 returns to the default surface after a reload', async () => {
  905. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-reload'))
  906. await page.reload({ waitUntil: 'load' })
  907. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  908. const frame = page.locator('[class*="frame"]').first()
  909. const column = page.locator('[data-rightbar-col]')
  910. await column.waitFor({ state: 'attached', timeout: 15_000 })
  911. // The surface is view state, not durable session data: a reload zeroes it
  912. // back to the collapsed default. Expected behaviour, not a defect.
  913. await expect.poll(async () => await frame.getAttribute('data-rightbar-collapsed')).toBe('true')
  914. await expect.poll(async () => await expandOf(page).count()).toBe(1)
  915. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  916. })
  917. it('opens a context menu on right-click that the strip cannot clip', async () => {
  918. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-menu'))
  919. const column = page.locator('[data-rightbar-col]')
  920. await ensureExpanded(page, column)
  921. await expect.poll(async () => await column.locator('[data-dockkit-tab]').count()).toBeGreaterThan(0)
  922. await column.locator('[data-sidebar-right-guide-entry="files"]').click()
  923. await column.locator('[data-dockkit-add-tab]').click()
  924. await expect.poll(async () => await tabTitles(column)).toEqual(['Files', 'Start'])
  925. // No "more" control on the chip: the chip carries its close, and the menu
  926. // is the secondary press.
  927. expect(await column.locator('[data-dockkit-tab-more]').count()).toBe(0)
  928. await column.locator('[data-dockkit-tab]').filter({ hasText: 'Start' }).click({ button: 'right' })
  929. const menu = page.locator('[data-dockkit-tab-menu]')
  930. await expect.poll(async () => await menu.count()).toBe(1)
  931. // The kit's one item; the extension seat is declared and rendered, and
  932. // with no registrant it contributes nothing, which is what "declared, not
  933. // speculative" looks like from the outside.
  934. await expect.poll(async () => await menu.getByRole('menuitem').allInnerTexts()).toEqual(['Close'])
  935. // The menu hangs below the strip that clips its overflow. Its pixels are
  936. // its own: a hit test at its centre lands on it, not on whatever the
  937. // strip would have shown through a clipped box.
  938. expect(await hitsItself(menu)).toBe(true)
  939. const box = await menu.boundingBox()
  940. const viewport = page.viewportSize()
  941. if (box === null || viewport === null) throw new Error('menu or viewport is not measurable')
  942. expect(box.x).toBeGreaterThanOrEqual(0)
  943. expect(box.x + box.width).toBeLessThanOrEqual(viewport.width)
  944. await page.keyboard.press('Escape')
  945. expect(tripwire.pageErrors).toEqual([])
  946. expect(tripwire.warnings).toEqual([])
  947. })
  948. // The product ships Chinese; the cases above advertise English so their role
  949. // locators stay stable. This is the other half of the same seam, and the
  950. // screenshot it takes is what the copy draft gets reviewed from. It lives in
  951. // this block because a settled session is its precondition too — a case that
  952. // depends on a sibling block's setup passes only in the right order.
  953. it('renders the shipped Chinese copy on a Chinese page', async () => {
  954. const zhPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
  955. const zhTripwire = watchConsole(zhPage)
  956. onTestFailed(() => saveFailureShot(zhPage, 'web-e2e-sidebar-right-zh'))
  957. try {
  958. await zhPage.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  959. await zhPage.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  960. // A fresh page opens the workspace on a blank session's hero, which has
  961. // no session header and so no expand button. The settled session is the
  962. // second row of the tree; pick it the way a user would.
  963. await zhPage.getByRole('treeitem', { name: /Show the right sidebar\./u }).first().click()
  964. const column = zhPage.locator('[data-rightbar-col]')
  965. await expandOf(zhPage).waitFor({ timeout: 20_000 })
  966. await expandOf(zhPage).click()
  967. await expect.poll(async () => await tabTitles(column)).toEqual(['开始'])
  968. await column.locator('[data-sidebar-right-guide-entry="files"]').click()
  969. await expect.poll(async () => await tabTitles(column)).toEqual(['文件'])
  970. await column.locator('[data-dockkit-add-tab]').click()
  971. const guide = column.locator('[data-sidebar-right-guide]')
  972. await expect.poll(async () => await guide.count()).toBe(1)
  973. // Wait for the track, not just the panel: the copy is only legible once
  974. // the column has the width, and a screenshot taken mid-transition reads
  975. // as a layout defect that is not there.
  976. expect(await width(column)).toBeGreaterThan(300)
  977. await expect.poll(async () => await tabTitles(column)).toEqual(['文件', '开始'])
  978. await expect.poll(async () => await guide.locator('[data-sidebar-right-guide-entry="files"]').innerText())
  979. .toBe('工作区文件')
  980. await shot(zhPage, '05-guide-copy-zh')
  981. expect(zhTripwire.pageErrors).toEqual([])
  982. expect(zhTripwire.warnings).toEqual([])
  983. } finally {
  984. await zhPage.close()
  985. }
  986. }, 120_000)
  987. })
  988. })