workspace-management.e2e.ts 27 KB

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