sidebar-right.e2e.ts 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  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 the header-derived workspace root. Writing
  247. // anywhere else makes the read fail with workspace-file/not-found, which
  248. // 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(
  625. scope: { sessionId: string; workspaceRoot: string },
  626. path: string,
  627. range: object,
  628. signal: AbortSignal,
  629. ): Promise<{ text: string; eof: boolean }>
  630. } | undefined
  631. }).get('workspaceFiles')
  632. if (files === undefined) throw new Error('host endpoint is not provided')
  633. const agent = scaffold.ctx.agents.list()[0]
  634. if (agent === undefined) throw new Error('no Agent to read for')
  635. const scope = {
  636. sessionId: agent.session.id,
  637. workspaceRoot: agent.session.header.cwd ?? scaffold.workspaceCwd,
  638. }
  639. // Raced against a timer so a hang reports a verdict instead of stalling
  640. // the suite: this case exists to tell host logic apart from the wire.
  641. // A page is the file's lines joined by `\n`, without the final terminator.
  642. const verdict = await Promise.race([
  643. files.read(scope, SAMPLE_NAME, {}, new AbortController().signal)
  644. .then(value => ({ kind: 'settled' as const, text: value.text, eof: value.eof }))
  645. .catch((error: unknown) => ({ kind: 'threw' as const, text: String(error), eof: false })),
  646. new Promise<{ kind: 'hung'; text: string; eof: boolean }>((resolve) => {
  647. setTimeout(() => { resolve({ kind: 'hung', text: 'no settlement in 10s', eof: false }) }, 10_000)
  648. }),
  649. ])
  650. expect(verdict).toEqual({ kind: 'settled', text: SAMPLE_TEXT.replace(/\n$/u, ''), eof: true })
  651. }, 30_000)
  652. it('opens content once, splits, and floats it outside the column', async () => {
  653. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-content'))
  654. const column = page.locator('[data-rightbar-col]')
  655. const panes = column.locator('[data-dockkit-pane]')
  656. const floats = page.locator('[data-sidebar-right-float-host] [data-dockkit-float]')
  657. // Observation before action: does the read ever leave the browser? The
  658. // assertion states the healthy answer so a failure prints the real one.
  659. //
  660. // CAVEAT: `sent` is trustworthy — a request frame carries the endpoint
  661. // name. `received` is NOT: a response frame carries only its rpc id, so a
  662. // zero here means "my filter saw nothing", not "the host never answered".
  663. // Correlate by rpc id before drawing any conclusion from it.
  664. const wire = { sent: 0, received: 0 }
  665. const watch = (payload: string): void => {
  666. if (!payload.includes('workspaceFiles')) return
  667. wire.sent += 1
  668. }
  669. page.on('websocket', (ws) => {
  670. ws.on('framesent', (frame) => { watch(String(frame.payload)) })
  671. ws.on('framereceived', (frame) => {
  672. if (String(frame.payload).includes('workspaceFiles')) wire.received += 1
  673. })
  674. })
  675. page.on('request', (request) => {
  676. if (request.url().includes('workspaceFiles')) wire.sent += 1
  677. })
  678. // The product's own entry point: the turn tail's produced-file chip. It
  679. // reaches the Sidebar through openFile → ctx.sidebarRight.openResource, and the
  680. // text type claims the address.
  681. const chip = page.getByRole('button', { name: `Open ${SAMPLE_NAME}` })
  682. await chip.click()
  683. await expect.poll(async () => await tabTitles(column)).toEqual(['Files', SAMPLE_NAME])
  684. // Opening the same content again focuses rather than duplicating.
  685. await panes.first().locator('[data-dockkit-tab]').first().click()
  686. await chip.click()
  687. await expect.poll(async () => await tabTitles(column)).toEqual(['Files', SAMPLE_NAME])
  688. // The body arrives through the text type's keyed registration, and its
  689. // content came over the wire from the real file.
  690. // A real Remote round-trip settles well after the default poll window.
  691. await column.locator('[data-textpreview-state="text"]')
  692. .waitFor({ timeout: 15_000 })
  693. .catch(() => { throw new Error(`preview never settled; wire=${JSON.stringify(wire)}`) })
  694. expect(await column.locator('pre').first().innerText()).toContain('produced by the seeded turn')
  695. // The whole batch-E chain in one frame: a produced-file chip in the
  696. // conversation, the tab it opened, and the file's real content read over
  697. // the workspace endpoint.
  698. await shot(page, '06-produced-chip-to-preview')
  699. // The directory scenario's V1 behaviour, asserted in the shipped product:
  700. // there is no folder affordance at all. `openFile('.')` would name a
  701. // directory, which a text preview correctly refuses, and the native opener
  702. // it used to reach is gone — so the row offers nothing rather than a
  703. // button that always fails.
  704. expect(await page.getByRole('button', { name: /folder/i }).count()).toBe(0)
  705. // Split, then dock-drag: the kit's gestures drive the store's actions.
  706. await panes.first().locator('[data-dockkit-split-button]').click()
  707. await expect.poll(async () => await panes.count()).toBe(2)
  708. await dragTo(
  709. page,
  710. column.locator('[data-dockkit-tab]').filter({ hasText: SAMPLE_NAME }).first(),
  711. await pointIn(panes.nth(1), 0.5, 0.94),
  712. )
  713. await expect.poll(async () => await panes.count()).toBe(2)
  714. const splitGuide = panes.nth(1).locator('[data-dockkit-tab]').filter({ hasText: 'Start' })
  715. expect(await splitGuide.locator('[data-dockkit-tab-close]').count()).toBe(1)
  716. await dragTo(page, splitGuide, await pointIn(panes.first(), 0.5, 0.5))
  717. await expect.poll(async () => await tabTitles(panes.nth(1))).toEqual([SAMPLE_NAME])
  718. const movedGuide = panes.first().locator('[data-dockkit-tab]').filter({ hasText: 'Start' })
  719. await movedGuide.hover()
  720. await movedGuide.locator('[data-dockkit-tab-close]').click()
  721. // Neither pane holds a guide, so both offer an add control.
  722. const filePane = panes.filter({ has: page.locator('[data-dockkit-tab-title]', { hasText: SAMPLE_NAME }) })
  723. await expect.poll(async () => await filePane.locator('[data-dockkit-add-tab]').count()).toBe(1)
  724. expect(await column.locator('[data-dockkit-add-tab]').count()).toBe(2)
  725. // Floating leaves the column entirely, and survives collapsing it. The
  726. // pane the tab was alone in goes with it: an emptied pane never stays.
  727. const tab = column.locator('[data-dockkit-tab]').filter({ hasText: SAMPLE_NAME }).first()
  728. await floatByDrag(page, tab)
  729. await expect.poll(async () => await floats.count()).toBe(1)
  730. expect(await column.locator('[data-dockkit-float]').count()).toBe(0)
  731. await expect.poll(async () => await panes.count()).toBe(1)
  732. await shot(page, '04-split-and-float')
  733. await column.locator('[data-sidebar-right-toggle]').click()
  734. await expect.poll(async () => await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  735. expect(await floats.count()).toBe(1)
  736. expect(tripwire.pageErrors).toEqual([])
  737. expect(tripwire.warnings).toEqual([])
  738. })
  739. // §9.2 (an explicit second copy of the same content) has no control on the
  740. // panel by product decision, and copy has no service method yet:
  741. // `duplicateTab` is a store/kit intent only, which service.client.spec.ts covers.
  742. it('keeps each session\'s surface to itself, and restores it on return', async () => {
  743. const fx = await newEnglishPage(browser)
  744. const fxTripwire = watchConsole(fx)
  745. onTestFailed(() => saveFailureShot(fx, 'web-e2e-sidebar-right-sessions'))
  746. try {
  747. await fx.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  748. const settled = fx.getByRole('treeitem', { name: /Show the right sidebar\./u }).first()
  749. await settled.click()
  750. await expect.poll(async () => await settled.getAttribute('aria-selected')).toBe('true')
  751. const frame = fx.locator('[class*="frame"]').first()
  752. const column = fx.locator('[data-rightbar-col]')
  753. await ensureExpanded(fx, column)
  754. await width(column)
  755. await fx.getByRole('button', { name: `Open ${SAMPLE_NAME}` }).click()
  756. await column.locator('[data-textpreview-state="text"]').waitFor({ timeout: 15_000 })
  757. const wrap = column.locator('[data-textpreview-tool="wrap"]')
  758. expect(await wrap.getAttribute('aria-pressed')).toBe('true')
  759. await wrap.click()
  760. await expect.poll(async () => await wrap.getAttribute('aria-pressed')).toBe('false')
  761. await column.locator('[data-dockkit-split-button]').first().click()
  762. const panes = column.locator('[data-dockkit-pane]')
  763. await expect.poll(async () => await panes.count()).toBe(2)
  764. const records = async (): Promise<{ panes: string[]; tabs: string[]; titles: string[] }> => ({
  765. panes: await panes.evaluateAll(nodes => nodes.map(node => node.getAttribute('data-dockkit-pane')!)),
  766. tabs: await column.locator('[data-dockkit-tab]').evaluateAll(nodes => nodes.map(node => node.getAttribute('data-dockkit-tab')!)),
  767. titles: await tabTitles(column),
  768. })
  769. const before = await records()
  770. // The real New Session action selects a distinct blank Session; its
  771. // collapsed surface must not inherit the settled Session's tabs.
  772. await fx.getByRole('button', { name: 'New session', exact: true }).last().click()
  773. await expect.poll(async () => await settled.getAttribute('aria-selected')).toBe('false')
  774. await expect.poll(async () => await frame.getAttribute('data-rightbar-collapsed')).toBe('true')
  775. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  776. expect(await column.locator('[data-textpreview-state="text"]').count()).toBe(0)
  777. await settled.click()
  778. await expect.poll(async () => await settled.getAttribute('aria-selected')).toBe('true')
  779. await expect.poll(records, { timeout: 15_000 }).toEqual(before)
  780. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(1)
  781. expect(await wrap.getAttribute('aria-pressed')).toBe('false')
  782. expect(await column.locator('pre').first().innerText()).toContain('produced by the seeded turn')
  783. expect(fxTripwire.pageErrors).toEqual([])
  784. expect(fxTripwire.warnings).toEqual([])
  785. } finally {
  786. await fx.close()
  787. }
  788. }, 120_000)
  789. it('§9.3/§9.4 runs the whole pointer chain in a real browser', async () => {
  790. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-gestures'))
  791. const column = await resetSidebar(page)
  792. const panes = column.locator('[data-dockkit-pane]')
  793. const floats = page.locator('[data-sidebar-right-float-host] [data-dockkit-float]')
  794. // Chromium cancels pointer capture if a render replaces the pressed
  795. // element; jsdom cannot establish that the whole gesture survives.
  796. // 1. Reorder inside one strip: drop the last tab left of its neighbours.
  797. // The first pane needs two tabs for this — and for the move below to
  798. // leave it standing, since a pane emptied by a move is dropped.
  799. const first = panes.first()
  800. const strip = first.locator('[data-dockkit-strip]')
  801. await page.getByRole('button', { name: `Open ${SAMPLE_NAME}` }).click()
  802. await expect.poll(async () => await tabTitles(first)).toEqual(['Files', SAMPLE_NAME])
  803. const order = await tabTitles(first)
  804. // The insertion index is measured against chip midpoints, not strip width.
  805. await dragTo(page, first.locator('[data-dockkit-tab]').last(),
  806. await pointIn(first.locator('[data-dockkit-tab]').first(), 0.25, 0.5),
  807. strip.locator('[data-dockkit-caret="0"]'))
  808. await expect.poll(async () => await tabTitles(first)).toEqual([...order].reverse())
  809. // 2. Cross-pane move into a second pane: the tab leaves one pane's strip
  810. // for another's.
  811. if (await panes.count() < 2) {
  812. await first.locator('[data-dockkit-split-button]').click()
  813. await expect.poll(async () => await panes.count()).toBe(2)
  814. }
  815. const moving = first.locator('[data-dockkit-tab]').first()
  816. const title = await moving.locator('[data-dockkit-tab-title]').innerText()
  817. await dragTo(page, moving, await pointIn(panes.nth(1), 0.5, 0.5))
  818. await expect.poll(async () => await tabTitles(panes.nth(1))).toContain(title)
  819. const splitButtons = column.locator('[data-dockkit-split-button]')
  820. await expect.poll(async () => await splitButtons.count()).toBe(0)
  821. expect(await panes.count()).toBe(2)
  822. await setPanelWidth(page, 560)
  823. await expect.poll(async () => await splitButtons.count()).toBe(0)
  824. const outer = column.locator('[data-dockkit-divider]').first()
  825. const before = await width(panes.last())
  826. const grip = await centre(outer)
  827. await dragElement(page, outer, { x: grip.x - 100, y: grip.y })
  828. await expect.poll(async () => await width(panes.last())).toBeGreaterThan(before)
  829. await dragElement(page, outer, { x: 0, y: grip.y })
  830. const ratio = async (): Promise<number> => {
  831. const left = await width(panes.first())
  832. const right = await width(panes.last())
  833. return left / (left + right)
  834. }
  835. await expect.poll(ratio).toBeCloseTo(0.2, 2)
  836. const surfaceBox = await column.locator('[data-dockkit-surface]').boundingBox()
  837. if (surfaceBox === null) throw new Error('surface is not rendered')
  838. await dragElement(page, outer, { x: surfaceBox.x + surfaceBox.width / 2, y: grip.y })
  839. await expect.poll(ratio).toBeCloseTo(0.5, 2)
  840. expect(await panes.count()).toBe(2)
  841. expect(await splitButtons.count()).toBe(0)
  842. // 5. The split's guide and the document float while Files stays docked.
  843. const floatOne = panes.last().locator('[data-dockkit-tab]').filter({ hasText: SAMPLE_NAME })
  844. await floatByDrag(page, floatOne)
  845. await expect.poll(async () => await floats.count()).toBe(1)
  846. const box = await floats.first().boundingBox()
  847. if (box === null) throw new Error('float is not rendered')
  848. await dragElement(page, floats.first().locator('[data-dockkit-float-grip]'), { x: box.x + 140, y: box.y + 90 })
  849. await expect.poll(async () => (await floats.first().boundingBox())?.x ?? box.x).not.toBe(box.x)
  850. await expect.poll(async () => await tabTitles(panes.last())).toEqual(['Start'])
  851. const second = panes.last().locator('[data-dockkit-tab]').filter({ hasText: 'Start' })
  852. await floatByDrag(page, second)
  853. await expect.poll(async () => await floats.count()).toBe(2)
  854. // 6. Dock one back: the docked tree takes it, the other float stays. Dock
  855. // the TOPMOST float — floats render bottom-to-top, so the newest one
  856. // covers the older one's controls and would intercept the click.
  857. await floats.last().locator('[data-dockkit-float-dock]').click()
  858. await expect.poll(async () => await floats.count()).toBe(1)
  859. expect(tripwire.pageErrors).toEqual([])
  860. expect(tripwire.warnings).toEqual([])
  861. }, 90_000)
  862. it('drops a pane whose last tab closes, and follows the last-tab rule on the surface', async () => {
  863. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-settle'))
  864. const column = await resetSidebar(page)
  865. const panes = column.locator('[data-dockkit-pane]')
  866. expect(await column.locator('[data-dockkit-tab-close]').count()).toBe(1)
  867. await page.getByRole('button', { name: `Open ${SAMPLE_NAME}` }).click()
  868. await expect.poll(async () => await tabTitles(panes.first())).toEqual(['Files', SAMPLE_NAME])
  869. await panes.first().locator('[data-dockkit-split-button]').click()
  870. await expect.poll(async () => await panes.count()).toBe(2)
  871. // Closing a pane's last tab drops the pane: there is no separate
  872. // "close pane" gesture, and none is needed.
  873. await panes.nth(1).locator('[data-dockkit-tab]').first().hover()
  874. await panes.nth(1).locator('[data-dockkit-tab-close]').first().click()
  875. await expect.poll(async () => await panes.count()).toBe(1)
  876. await expect.poll(async () => await tabTitles(column)).toEqual(['Files', SAMPLE_NAME])
  877. // Leave a guide as the sole docked tab.
  878. const files = column.locator('[data-dockkit-tab]').filter({ hasText: 'Files' })
  879. await files.hover()
  880. await files.locator('[data-dockkit-tab-close]').click()
  881. await column.locator('[data-dockkit-add-tab]').click()
  882. await expect.poll(async () => await tabTitles(column)).toEqual([SAMPLE_NAME, 'Start'])
  883. const sample = column.locator('[data-dockkit-tab]').filter({ hasText: SAMPLE_NAME })
  884. await sample.hover()
  885. await sample.locator('[data-dockkit-tab-close]').click()
  886. await expect.poll(async () => await tabTitles(column)).toEqual(['Start'])
  887. // The guide standing as the docked surface's only tab draws no close
  888. // control, sits quiet (no capsule, no hover fill), and a secondary press
  889. // opens no menu: an empty menu never shows.
  890. expect(await column.locator('[data-dockkit-tab-close]').count()).toBe(0)
  891. expect(await column.locator('[data-dockkit-tab-quiet]').count()).toBe(1)
  892. await column.locator('[data-dockkit-tab]').first().click({ button: 'right' })
  893. expect(await page.locator('[data-dockkit-tab-menu]').isVisible()).toBe(false)
  894. expect(await page.getByRole('menu').count()).toBe(0)
  895. // Any other tab standing alone closes together with the column. Open the
  896. // sample file, close the guide (an ordinary close with two tabs), then
  897. // close the file: the column collapses in the same gesture, and the
  898. // settle rule reseeds the current default, so reopening shows Start.
  899. await page.getByRole('button', { name: `Open ${SAMPLE_NAME}` }).click()
  900. await expect.poll(async () => await tabTitles(column)).toEqual(['Start', SAMPLE_NAME])
  901. await column.locator('[data-dockkit-tab]').first().hover()
  902. await column.locator('[data-dockkit-tab-close]').first().click()
  903. await expect.poll(async () => await tabTitles(column)).toEqual([SAMPLE_NAME])
  904. await column.locator('[data-dockkit-tab]').first().hover()
  905. await column.locator('[data-dockkit-tab-close]').first().click()
  906. await expect.poll(async () => await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  907. await expandOf(page).click()
  908. await expect.poll(async () => await tabTitles(column)).toEqual(['Start'])
  909. expect(await column.locator('[data-sidebar-right-guide]').count()).toBe(1)
  910. expect(tripwire.pageErrors).toEqual([])
  911. expect(tripwire.warnings).toEqual([])
  912. }, 90_000)
  913. it('§9.7 returns to the default surface after a reload', async () => {
  914. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-reload'))
  915. await page.reload({ waitUntil: 'load' })
  916. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  917. const frame = page.locator('[class*="frame"]').first()
  918. const column = page.locator('[data-rightbar-col]')
  919. await column.waitFor({ state: 'attached', timeout: 15_000 })
  920. // The surface is view state, not durable session data: a reload zeroes it
  921. // back to the collapsed default. Expected behaviour, not a defect.
  922. await expect.poll(async () => await frame.getAttribute('data-rightbar-collapsed')).toBe('true')
  923. await expect.poll(async () => await expandOf(page).count()).toBe(1)
  924. expect(await column.locator('[data-sidebar-right-open]').count()).toBe(0)
  925. })
  926. it('opens a context menu on right-click that the strip cannot clip', async () => {
  927. onTestFailed(() => saveFailureShot(page, 'web-e2e-sidebar-right-menu'))
  928. const column = page.locator('[data-rightbar-col]')
  929. await ensureExpanded(page, column)
  930. await expect.poll(async () => await column.locator('[data-dockkit-tab]').count()).toBeGreaterThan(0)
  931. await column.locator('[data-sidebar-right-guide-entry="files"]').click()
  932. await column.locator('[data-dockkit-add-tab]').click()
  933. await expect.poll(async () => await tabTitles(column)).toEqual(['Files', 'Start'])
  934. // No "more" control on the chip: the chip carries its close, and the menu
  935. // is the secondary press.
  936. expect(await column.locator('[data-dockkit-tab-more]').count()).toBe(0)
  937. await column.locator('[data-dockkit-tab]').filter({ hasText: 'Start' }).click({ button: 'right' })
  938. const menu = page.locator('[data-dockkit-tab-menu]')
  939. await expect.poll(async () => await menu.count()).toBe(1)
  940. // The kit's one item; the extension seat is declared and rendered, and
  941. // with no registrant it contributes nothing, which is what "declared, not
  942. // speculative" looks like from the outside.
  943. await expect.poll(async () => await menu.getByRole('menuitem').allInnerTexts()).toEqual(['Close'])
  944. // The menu hangs below the strip that clips its overflow. Its pixels are
  945. // its own: a hit test at its centre lands on it, not on whatever the
  946. // strip would have shown through a clipped box.
  947. expect(await hitsItself(menu)).toBe(true)
  948. const box = await menu.boundingBox()
  949. const viewport = page.viewportSize()
  950. if (box === null || viewport === null) throw new Error('menu or viewport is not measurable')
  951. expect(box.x).toBeGreaterThanOrEqual(0)
  952. expect(box.x + box.width).toBeLessThanOrEqual(viewport.width)
  953. await page.keyboard.press('Escape')
  954. expect(tripwire.pageErrors).toEqual([])
  955. expect(tripwire.warnings).toEqual([])
  956. })
  957. // The product ships Chinese; the cases above advertise English so their role
  958. // locators stay stable. This is the other half of the same seam, and the
  959. // screenshot it takes is what the copy draft gets reviewed from. It lives in
  960. // this block because a settled session is its precondition too — a case that
  961. // depends on a sibling block's setup passes only in the right order.
  962. it('renders the shipped Chinese copy on a Chinese page', async () => {
  963. const zhPage = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
  964. const zhTripwire = watchConsole(zhPage)
  965. onTestFailed(() => saveFailureShot(zhPage, 'web-e2e-sidebar-right-zh'))
  966. try {
  967. await zhPage.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  968. await zhPage.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  969. // A fresh page opens the workspace on a blank session's hero, which has
  970. // no session header and so no expand button. The settled session is the
  971. // second row of the tree; pick it the way a user would.
  972. await zhPage.getByRole('treeitem', { name: /Show the right sidebar\./u }).first().click()
  973. const column = zhPage.locator('[data-rightbar-col]')
  974. await expandOf(zhPage).waitFor({ timeout: 20_000 })
  975. await expandOf(zhPage).click()
  976. await expect.poll(async () => await tabTitles(column)).toEqual(['开始'])
  977. await column.locator('[data-sidebar-right-guide-entry="files"]').click()
  978. await expect.poll(async () => await tabTitles(column)).toEqual(['文件'])
  979. await column.locator('[data-dockkit-add-tab]').click()
  980. const guide = column.locator('[data-sidebar-right-guide]')
  981. await expect.poll(async () => await guide.count()).toBe(1)
  982. // Wait for the track, not just the panel: the copy is only legible once
  983. // the column has the width, and a screenshot taken mid-transition reads
  984. // as a layout defect that is not there.
  985. expect(await width(column)).toBeGreaterThan(300)
  986. await expect.poll(async () => await tabTitles(column)).toEqual(['文件', '开始'])
  987. await expect.poll(async () => await guide.locator('[data-sidebar-right-guide-entry="files"]').innerText())
  988. .toBe('工作区文件\n浏览会话工作区的文件')
  989. await shot(zhPage, '05-guide-copy-zh')
  990. expect(zhTripwire.pageErrors).toEqual([])
  991. expect(zhTripwire.warnings).toEqual([])
  992. } finally {
  993. await zhPage.close()
  994. }
  995. }, 120_000)
  996. })
  997. })