sidebar-right.e2e.ts 59 KB

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