workspace-management.e2e.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. // Web e2e scenarios: workspace management — the create-by-name dialog, the
  2. // rename round trip over the real wire (workspace.rename RPC + durable
  3. // registry), duplicate-name pre-check, the flat "In one list" view with its
  4. // persisted group-by preference, and the session hover card. Zero model
  5. // calls: workspace.create/rename are host RPCs with no model involvement,
  6. // and the one session row the flat/hover scenarios need comes from a seeded
  7. // fixture (the seeded-history seed reused verbatim — no new recording).
  8. import { mkdir, readFile, stat, writeFile } from 'node:fs/promises'
  9. import { fileURLToPath } from 'node:url'
  10. import { join } from 'node:path'
  11. import type { Browser, Page } from 'playwright'
  12. import { chromium } from 'playwright'
  13. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  14. import { SessionId } from '@deepseek-ai/dsh-session'
  15. import {
  16. acknowledgeReloadConnectionLoss, assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
  17. launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold,
  18. } from './scaffold.ts'
  19. import { saveFailureShot } from './support.ts'
  20. const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/workspace-management', import.meta.url))
  21. // The seed is another scenario's committed fixture, reused read-only: this
  22. // spec needs any one cold session row, not new recorded content.
  23. const SEED = fileURLToPath(new URL('./snapshots/seeded-history/seed.jsonl', import.meta.url))
  24. const MODE = webSnapshotMode()
  25. const BROWSER_EXPECTED = join(SNAPSHOT_DIR, 'directory-browser.expected.md')
  26. const SEED_ID = 'workspace-management-web-e2e'
  27. describe('web e2e: workspace management (create / rename / flat view / hover card)', () => {
  28. let scaffold: WebScaffold
  29. let browser: Browser
  30. let page: Page
  31. let tripwire: ReturnType<typeof watchConsole>
  32. /**
  33. * Drive the in-app browser to a directory via its path-edit affordance,
  34. * confirm it, and wait for the adoption to settle host-side (workspace
  35. * registered + the flow's New-Session agent up), so later test steps can't
  36. * race the in-flight blank-session attach.
  37. */
  38. async function openLocalFolder(path: string, options: { waitForAgent?: boolean } = {}): Promise<void> {
  39. const agentsBefore = scaffold.ctx.agents.list().length
  40. await page.getByRole('button', { name: 'Create workspace' }).click()
  41. await page.getByRole('menuitem', { name: 'Open local folder…' }).click()
  42. const dialog = page.getByRole('dialog', { name: '选择工作区目录' })
  43. await dialog.waitFor({ timeout: 10_000 })
  44. await dialog.getByRole('button', { name: '编辑路径' }).click()
  45. await dialog.getByLabel('编辑路径').fill(path)
  46. await dialog.getByLabel('编辑路径').press('Enter')
  47. await dialog.getByRole('button', { name: '打开' }).click()
  48. await dialog.waitFor({ state: 'hidden', timeout: 10_000 })
  49. await expect.poll(
  50. () => scaffold.ctx.workspace.resolveByPath(path),
  51. { timeout: 10_000 },
  52. ).not.toBeUndefined()
  53. // First adoption births a blank Session+Agent whose workspace attach must
  54. // settle before a test may delete the registration; the reuse path (same
  55. // canonical cwd already has a blank session) creates no agent, so callers
  56. // opt in only where a fresh attach is possible.
  57. if (options.waitForAgent === true) {
  58. await expect.poll(() => scaffold.ctx.agents.list().length, { timeout: 10_000 })
  59. .toBeGreaterThan(agentsBefore)
  60. }
  61. }
  62. beforeAll(async () => {
  63. scaffold = await launchWebScaffold({})
  64. // Seed one cold session (Ungrouped bucket) for the flat view + hover card.
  65. const sessionCwd = join(scaffold.workspaceCwd, 'workspace')
  66. await mkdir(sessionCwd, { recursive: true })
  67. await writeFile(join(sessionCwd, 'a.txt'), 'alpha\n')
  68. await writeFile(join(sessionCwd, 'b.txt'), 'beta\n')
  69. await seedSession(scaffold, await readFile(SEED, 'utf8'), SEED_ID)
  70. browser = await chromium.launch()
  71. page = await browser.newPage({ viewport: { width: 1680, height: 1000 } })
  72. tripwire = watchConsole(page)
  73. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  74. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  75. }, 120_000)
  76. afterAll(async () => {
  77. await browser?.close()
  78. await scaffold?.close()
  79. })
  80. it('creates two workspaces by name through the region-header dialog', async () => {
  81. onTestFailed(() => saveFailureShot(page, 'web-e2e-ws-create'))
  82. const createByName = async (name: string): Promise<void> => {
  83. await page.getByRole('button', { name: 'Create workspace' }).click()
  84. await page.getByRole('menuitem', { name: 'Create a new workspace' }).click()
  85. const dialog = page.getByRole('dialog', { name: 'Create a new workspace' })
  86. await dialog.waitFor({ timeout: 10_000 })
  87. await dialog.getByLabel('New workspace name').fill(name)
  88. await dialog.getByRole('button', { name: 'Create workspace' }).click()
  89. await expect.poll(() => page.getByRole('dialog', { name: 'Create a new workspace' }).count(), { timeout: 10_000 }).toBe(0)
  90. // The real workspace materializes in the tree as a group row.
  91. await expect.poll(() => page.getByText(name, { exact: true }).count(), { timeout: 10_000 }).toBeGreaterThanOrEqual(1)
  92. }
  93. await createByName('alpha-ws')
  94. await createByName('beta-ws')
  95. // Durable on the host: both registered, newest first (create prepends).
  96. const titles = scaffold.ctx.workspace.list().map(workspace => workspace.title)
  97. expect(titles.slice(0, 2)).toEqual(['beta-ws', 'alpha-ws'])
  98. expect(tripwire.pageErrors).toEqual([])
  99. }, 90_000)
  100. it('renames a workspace over the wire with a duplicate-name pre-check', async () => {
  101. onTestFailed(() => saveFailureShot(page, 'web-e2e-ws-rename'))
  102. // The actions button is display:none until its row hovers — hover the
  103. // group row first, then the revealed button becomes actionable.
  104. await page.locator('[role="treeitem"]').filter({ hasText: 'alpha-ws' }).first().hover()
  105. await page.getByRole('button', { name: 'Workspace actions for alpha-ws' }).click()
  106. await page.getByRole('menuitem', { name: 'Rename' }).click()
  107. const dialog = page.getByRole('dialog', { name: 'Rename workspace' })
  108. await dialog.waitFor({ timeout: 10_000 })
  109. const input = dialog.getByLabel('Workspace name')
  110. // Client pre-check: a name colliding with another live workspace raises
  111. // the inline alert and blocks the primary button before any wire call.
  112. await input.fill('beta-ws')
  113. await expect.poll(() => dialog.getByRole('alert').count(), { timeout: 5_000 }).toBe(1)
  114. expect(await dialog.getByRole('button', { name: 'Rename' }).isDisabled()).toBe(true)
  115. // A fresh name goes through workspace.rename to the durable registry.
  116. await input.fill('gamma-ws')
  117. await expect.poll(() => dialog.getByRole('alert').count(), { timeout: 5_000 }).toBe(0)
  118. await dialog.getByRole('button', { name: 'Rename' }).click()
  119. await expect.poll(() => page.getByRole('dialog', { name: 'Rename workspace' }).count(), { timeout: 10_000 }).toBe(0)
  120. await expect.poll(() => page.getByText('gamma-ws', { exact: true }).count(), { timeout: 10_000 }).toBeGreaterThanOrEqual(1)
  121. expect(await page.getByText('alpha-ws', { exact: true }).count()).toBe(0)
  122. // Host durability, then reload: the projection is rebuilt from the wire.
  123. expect(scaffold.ctx.workspace.list().map(workspace => workspace.title)).toContain('gamma-ws')
  124. const warningStart = tripwire.warnings.length
  125. await page.reload({ waitUntil: 'load' })
  126. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  127. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  128. await expect.poll(() => page.getByText('gamma-ws', { exact: true }).count(), { timeout: 15_000 }).toBeGreaterThanOrEqual(1)
  129. expect(tripwire.pageErrors).toEqual([])
  130. }, 90_000)
  131. it('deletes only the Workspace registration and keeps its current Session, folder, and log', async () => {
  132. onTestFailed(() => saveFailureShot(page, 'web-e2e-ws-delete'))
  133. const slotConsoleErrors: string[] = []
  134. const transientSlotErrors: string[] = []
  135. page.on('console', (message) => {
  136. if (message.type() === 'error' && /slot entry crashed/i.test(message.text())) {
  137. slotConsoleErrors.push(message.text())
  138. }
  139. })
  140. await page.exposeFunction('recordDshSlotError', (key: string) => {
  141. if (!transientSlotErrors.includes(key)) transientSlotErrors.push(key)
  142. })
  143. await page.evaluate(() => {
  144. const target = window as unknown as { recordDshSlotError(key: string): Promise<void> }
  145. const seen = new Set<string>()
  146. const collect = (): void => {
  147. for (const node of document.querySelectorAll<HTMLElement>('[data-slot-error]')) {
  148. const key = node.dataset.slotError ?? ''
  149. if (!seen.has(key)) {
  150. seen.add(key)
  151. void target.recordDshSlotError(key)
  152. }
  153. }
  154. }
  155. new MutationObserver(collect).observe(document.documentElement, { childList: true, subtree: true })
  156. collect()
  157. })
  158. // Register the scaffold's existing project directory through the real UI.
  159. await openLocalFolder(scaffold.workspaceCwd, { waitForAgent: true })
  160. const workspace = await scaffold.ctx.workspace.resolveByPath(scaffold.workspaceCwd)
  161. if (workspace === undefined) throw new Error('GUI did not register the existing project directory')
  162. await workspace.attachSession(SessionId(SEED_ID))
  163. const header = (await scaffold.ctx.sessionPersistence.list())
  164. .find(candidate => candidate.id === SEED_ID)
  165. if (header === undefined) throw new Error('seeded Session log disappeared before deletion')
  166. const logLocation = scaffold.ctx.sessionPersistence.locate(header)
  167. if (logLocation === undefined) throw new Error('JSONL persistence did not expose the seeded log path')
  168. expect(await readFile(join(scaffold.workspaceCwd, 'workspace', 'a.txt'), 'utf8')).toBe('alpha\n')
  169. await stat(logLocation.path)
  170. // Open the seeded (first/accounted) Session so deletion must preserve the
  171. // current selection while it moves into Ungrouped.
  172. const groupRow = page.locator('[role="treeitem"]').filter({ hasText: workspace.title }).first()
  173. await groupRow.waitFor({ timeout: 10_000 })
  174. const groupSection = groupRow.locator('..')
  175. if (await groupSection.locator('[role="treeitem"]').count() < 2) await groupRow.click()
  176. await expect.poll(
  177. () => groupSection.locator('[role="treeitem"]').count(),
  178. { timeout: 10_000 },
  179. ).toBeGreaterThanOrEqual(2)
  180. const seededRow = groupSection.locator('[role="treeitem"]').nth(1)
  181. await seededRow.click()
  182. await expect.poll(() => seededRow.getAttribute('aria-selected'), { timeout: 10_000 }).toBe('true')
  183. await groupRow.hover()
  184. await page.getByRole('button', { name: `Workspace actions for ${workspace.title}` }).click()
  185. await page.getByRole('menuitem', { name: 'Delete workspace' }).click()
  186. const dialog = page.getByRole('dialog', { name: 'Delete workspace' })
  187. await dialog.waitFor({ timeout: 10_000 })
  188. const copy = await dialog.textContent()
  189. expect(copy).toContain('workspace list')
  190. expect(copy).toContain('folder and session logs will be kept')
  191. expect(copy).toContain('sessions will appear under Ungrouped')
  192. await dialog.getByRole('button', { name: 'Delete workspace' }).click()
  193. await expect.poll(() => dialog.count(), { timeout: 10_000 }).toBe(0)
  194. expect(scaffold.ctx.workspace.get(workspace.id)).toBeUndefined()
  195. await expect.poll(
  196. () => page.getByRole('button', { name: `Workspace actions for ${workspace.title}` }).count(),
  197. { timeout: 10_000 },
  198. ).toBe(0)
  199. await expect.poll(() => page.getByText('Ungrouped', { exact: true }).count(), { timeout: 10_000 })
  200. .toBeGreaterThanOrEqual(1)
  201. await expect.poll(
  202. () => page.locator('[role="treeitem"][aria-selected="true"]').count(),
  203. { timeout: 10_000 },
  204. ).toBe(1)
  205. expect(await readFile(join(scaffold.workspaceCwd, 'workspace', 'a.txt'), 'utf8')).toBe('alpha\n')
  206. await stat(logLocation.path)
  207. expect((await scaffold.ctx.sessionPersistence.inspect(SessionId(SEED_ID))).events.length).toBeGreaterThan(0)
  208. // Re-registering the exact deleted path immediately, without a reload, is
  209. // a supported reversible flow. It creates a fresh Workspace id without
  210. // re-adopting the retained Session.
  211. await openLocalFolder(scaffold.workspaceCwd)
  212. await expect.poll(
  213. () => scaffold.ctx.workspace.resolveByPath(scaffold.workspaceCwd),
  214. { timeout: 10_000 },
  215. ).not.toBeUndefined()
  216. const reregistered = await scaffold.ctx.workspace.resolveByPath(scaffold.workspaceCwd)
  217. expect(reregistered?.id).toBeDefined()
  218. expect(reregistered?.id).not.toBe(workspace.id)
  219. expect(reregistered?.sessionIds).toEqual([])
  220. await expect.poll(() => page.getByText('Ungrouped', { exact: true }).count(), { timeout: 10_000 })
  221. .toBeGreaterThanOrEqual(1)
  222. expect(await readFile(join(scaffold.workspaceCwd, 'workspace', 'a.txt'), 'utf8')).toBe('alpha\n')
  223. await stat(logLocation.path)
  224. // Restore the deleted-registry state so reload still verifies deletion
  225. // persistence independently of the successful re-registration above.
  226. if (reregistered === undefined) throw new Error('same-path re-registration did not materialize')
  227. await scaffold.ctx.workspace.delete(reregistered.id)
  228. await expect.poll(
  229. () => page.getByRole('button', { name: `Workspace actions for ${reregistered.title}` }).count(),
  230. { timeout: 10_000 },
  231. ).toBe(0)
  232. const warningStart = tripwire.warnings.length
  233. await page.reload({ waitUntil: 'load' })
  234. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  235. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  236. await expect.poll(() => page.getByText('Ungrouped', { exact: true }).count(), { timeout: 15_000 })
  237. .toBeGreaterThanOrEqual(1)
  238. await expect.poll(
  239. () => page.locator('[role="treeitem"][aria-selected="true"]').count(),
  240. { timeout: 15_000 },
  241. ).toBe(1)
  242. expect(scaffold.ctx.workspace.get(workspace.id)).toBeUndefined()
  243. expect(await readFile(join(scaffold.workspaceCwd, 'workspace', 'a.txt'), 'utf8')).toBe('alpha\n')
  244. await stat(logLocation.path)
  245. expect((await scaffold.ctx.sessionPersistence.inspect(SessionId(SEED_ID))).events.length).toBeGreaterThan(0)
  246. expect(transientSlotErrors).toEqual([])
  247. expect(slotConsoleErrors).toEqual([])
  248. expect(tripwire.pageErrors).toEqual([])
  249. }, 90_000)
  250. it('reuses a deleted title for a different new directory without any transient error surface', async () => {
  251. onTestFailed(() => saveFailureShot(page, 'web-e2e-ws-reuse-title'))
  252. const title = 'same-name'
  253. const oldPath = join(scaffold.workspaceCwd, 'adopted', title)
  254. await mkdir(oldPath, { recursive: true })
  255. const transientErrors: string[] = []
  256. const consoleErrors: string[] = []
  257. page.on('console', (message) => {
  258. if (message.type() === 'error') consoleErrors.push(message.text())
  259. })
  260. await page.exposeFunction('recordDshTransientWorkspaceError', (message: string) => {
  261. if (!transientErrors.includes(message)) transientErrors.push(message)
  262. })
  263. await page.evaluate(() => {
  264. const target = window as unknown as {
  265. recordDshTransientWorkspaceError(message: string): Promise<void>
  266. }
  267. const collect = (): void => {
  268. for (const node of document.querySelectorAll<HTMLElement>('[data-slot-error], [role="alert"]')) {
  269. const message = node.dataset.slotError ?? node.textContent?.trim() ?? ''
  270. if (message !== '') void target.recordDshTransientWorkspaceError(message)
  271. }
  272. }
  273. new MutationObserver(collect).observe(document.documentElement, { childList: true, subtree: true })
  274. collect()
  275. })
  276. await openLocalFolder(oldPath)
  277. await expect.poll(
  278. () => scaffold.ctx.workspace.resolveByPath(oldPath),
  279. { timeout: 10_000 },
  280. ).not.toBeUndefined()
  281. const oldWorkspace = await scaffold.ctx.workspace.resolveByPath(oldPath)
  282. if (oldWorkspace === undefined) throw new Error('old same-name Workspace was not registered')
  283. const oldRow = page.locator('[role="treeitem"]').filter({ hasText: title }).first()
  284. await oldRow.hover()
  285. await page.getByRole('button', { name: `Workspace actions for ${title}` }).click()
  286. await page.getByRole('menuitem', { name: 'Delete workspace' }).click()
  287. await page.getByRole('dialog', { name: 'Delete workspace' })
  288. .getByRole('button', { name: 'Delete workspace' }).click()
  289. await expect.poll(() => scaffold.ctx.workspace.get(oldWorkspace.id), { timeout: 10_000 }).toBeUndefined()
  290. await page.getByRole('button', { name: 'Create workspace' }).click()
  291. await page.getByRole('menuitem', { name: 'Create a new workspace' }).click()
  292. const create = page.getByRole('dialog', { name: 'Create a new workspace' })
  293. await create.getByLabel('New workspace name').fill(title)
  294. await create.getByRole('button', { name: 'Create workspace' }).click()
  295. await expect.poll(() => create.count(), { timeout: 10_000 }).toBe(0)
  296. const fresh = scaffold.ctx.workspace.list().find(workspace => workspace.title === title)
  297. expect(fresh?.id).toBeDefined()
  298. expect(fresh?.id).not.toBe(oldWorkspace.id)
  299. expect(fresh?.path).toBe(join(scaffold.workspaceCwd, title))
  300. expect(transientErrors).toEqual([])
  301. expect(consoleErrors).toEqual([])
  302. expect(tripwire.pageErrors).toEqual([])
  303. }, 90_000)
  304. it('switches to the flat "In one list" view and persists the preference', async () => {
  305. onTestFailed(() => saveFailureShot(page, 'web-e2e-ws-flat'))
  306. // Grouped default: workspace group rows render (the seeded session sits
  307. // under Ungrouped; the created workspaces are empty groups).
  308. await expect.poll(() => page.getByText('Workspaces', { exact: true }).count(), { timeout: 10_000 }).toBe(1)
  309. await page.getByRole('button', { name: 'Group by' }).click()
  310. await page.getByRole('menuitem', { name: 'In one list' }).click()
  311. // Flat mode: the section label flips and the seeded session is a
  312. // top-level row with no group headers above it.
  313. await expect.poll(() => page.getByText('Sessions', { exact: true }).count(), { timeout: 10_000 }).toBeGreaterThanOrEqual(1)
  314. await expect.poll(() => page.getByText('Ungrouped', { exact: true }).count(), { timeout: 5_000 }).toBe(0)
  315. await expect.poll(() => page.locator('[role="treeitem"]').count(), { timeout: 10_000 }).toBeGreaterThanOrEqual(1)
  316. expect(await page.evaluate(() => localStorage.getItem('dsh.workspace.view'))).toContain('flat')
  317. // Persisted across reload; then restore grouped for inter-spec hygiene.
  318. const warningStart = tripwire.warnings.length
  319. await page.reload({ waitUntil: 'load' })
  320. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  321. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  322. await expect.poll(() => page.getByText('Ungrouped', { exact: true }).count(), { timeout: 15_000 }).toBe(0)
  323. await page.getByRole('button', { name: 'Group by' }).click()
  324. await page.getByRole('menuitem', { name: 'WorkSpace' }).click()
  325. await expect.poll(() => page.getByText('Ungrouped', { exact: true }).count(), { timeout: 10_000 }).toBeGreaterThanOrEqual(1)
  326. expect(tripwire.pageErrors).toEqual([])
  327. }, 90_000)
  328. it('matches the directory-browser dialog aria golden at a staged directory', async () => {
  329. // A staged subtree under the scaffold cwd keeps the listing deterministic
  330. // (normalizeAria scrubs the cwd), and pointing the in-process host's HOME
  331. // at the cwd collapses the breadcrumb ancestry into the Home crumb — no
  332. // machine-specific path segments or real $HOME contents enter the golden.
  333. const staged = join(scaffold.workspaceCwd, 'browse-golden')
  334. await mkdir(join(staged, 'alpha'), { recursive: true })
  335. await mkdir(join(staged, 'beta'), { recursive: true })
  336. // homedir() reads HOME on POSIX and USERPROFILE on Windows: root both
  337. // at the scaffold cwd so the golden's ancestry collapses everywhere.
  338. const realHome = process.env.HOME
  339. const realUserProfile = process.env.USERPROFILE
  340. process.env.HOME = scaffold.workspaceCwd
  341. process.env.USERPROFILE = scaffold.workspaceCwd
  342. try {
  343. await page.getByRole('button', { name: 'Create workspace' }).click()
  344. await page.getByRole('menuitem', { name: 'Open local folder…' }).click()
  345. const dialog = page.getByRole('dialog', { name: '选择工作区目录' })
  346. await dialog.waitFor({ timeout: 10_000 })
  347. await dialog.getByRole('button', { name: '编辑路径' }).click()
  348. await dialog.getByLabel('编辑路径').fill(staged)
  349. await dialog.getByLabel('编辑路径').press('Enter')
  350. await expect.poll(() => dialog.getByText('alpha', { exact: true }).count(), { timeout: 10_000 }).toBe(1)
  351. const snapshot = await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd)
  352. await compareOrRefreshGolden(BROWSER_EXPECTED, snapshot, MODE)
  353. await dialog.getByRole('button', { name: '取消' }).click()
  354. await dialog.waitFor({ state: 'hidden', timeout: 10_000 })
  355. } finally {
  356. if (realHome === undefined) delete process.env.HOME
  357. else process.env.HOME = realHome
  358. if (realUserProfile === undefined) delete process.env.USERPROFILE
  359. else process.env.USERPROFILE = realUserProfile
  360. }
  361. expect(tripwire.pageErrors).toEqual([])
  362. }, 60_000)
  363. it('shows the session hover card after a dwell on the row', async () => {
  364. onTestFailed(() => saveFailureShot(page, 'web-e2e-ws-hover'))
  365. // Expand Ungrouped to reveal the seeded session row, then dwell on it
  366. // (the card opens after a 500ms hover delay, portaled to body).
  367. const ungroupedRow = page.getByText('Ungrouped', { exact: true }).locator('..').locator('..')
  368. const ungroupedSection = ungroupedRow.locator('..')
  369. // Initial-current auto-expansion can race this following test's gesture;
  370. // converge on expanded rather than assuming which update wins first.
  371. await expect.poll(async () => {
  372. if (await ungroupedRow.getAttribute('aria-expanded') !== 'true') {
  373. await page.getByText('Ungrouped', { exact: true }).click()
  374. await page.waitForTimeout(50)
  375. }
  376. return await ungroupedRow.getAttribute('aria-expanded')
  377. }, { timeout: 5_000 }).toBe('true')
  378. // The only visible child is the non-blank persisted Session; the blank
  379. // Session created while adopting the Workspace remains hidden.
  380. const sessionRow = ungroupedSection.locator('[role="treeitem"]').nth(1)
  381. await sessionRow.waitFor({ timeout: 10_000 })
  382. await sessionRow.hover()
  383. // Card content: the full title plus the Idle status line (display-only
  384. // card; no aria role — text anchors are the stable selector).
  385. await expect.poll(() => page.getByText('Idle', { exact: true }).count(), { timeout: 5_000 }).toBeGreaterThanOrEqual(1)
  386. // Leaving the anchor closes it with no delay.
  387. await page.getByRole('button', { name: '设置' }).hover()
  388. await expect.poll(() => page.getByText('Idle', { exact: true }).count(), { timeout: 5_000 }).toBe(0)
  389. expect(tripwire.pageErrors).toEqual([])
  390. }, 60_000)
  391. it.skipIf(MODE === 'record')('issued zero model calls and stayed clean', async () => {
  392. expect(tripwire.warnings).toEqual([])
  393. // The directory-browser aria golden is this spec's one owned artifact;
  394. // the seed it reuses is owned (and inventory-guarded) by seeded-history.
  395. await assertFixtureInventory(SNAPSHOT_DIR, ['.gitkeep', 'directory-browser.expected.md'])
  396. })
  397. })