session-unarchive.e2e.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Web e2e scenario: the archived-session Settings page restores a Session
  2. // through the real wire, from its row menu through the archive set, the page,
  3. // and the reload that rebuilds state from the host baseline. Zero model calls:
  4. // both verbs are host RPCs and the page reads already-loaded Session summaries,
  5. // so no replay fixture mounts and a stray model stream fails loud.
  6. import { readFile } from 'node:fs/promises'
  7. import { fileURLToPath } from 'node:url'
  8. import type { Browser, Locator, Page } from 'playwright'
  9. import { chromium } from 'playwright'
  10. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  11. import { SessionId } from '@deepseek-ai/dsh-session'
  12. import {
  13. acknowledgeReloadConnectionLoss, launchWebScaffold, seedSession, watchConsole, type WebScaffold,
  14. } from './scaffold.ts'
  15. import { newEnglishPage, saveFailureShot } from './support.ts'
  16. // The seed is another scenario's committed fixture, reused read-only: this
  17. // spec needs any one cold Session row, not new recorded content.
  18. const SEED = fileURLToPath(new URL('../../../snapshots/web/seeded-history/session.v3.jsonl', import.meta.url))
  19. const SEED_ID = 'session-unarchive-web-e2e'
  20. describe('web e2e: archived sessions are restored from the Settings page', () => {
  21. let scaffold: WebScaffold
  22. let browser: Browser
  23. let page: Page
  24. let tripwire: ReturnType<typeof watchConsole>
  25. /**
  26. * Expand the Ungrouped group when it renders collapsed so its rows are
  27. * addressable, then return the section holding them.
  28. * @returns the expanded Ungrouped section locator.
  29. */
  30. async function ungroupedSection(): Promise<Locator> {
  31. const header = page.getByText('Ungrouped', { exact: true })
  32. const groupRow = header.locator('..').locator('..')
  33. await expect.poll(async () => {
  34. if (await groupRow.count() === 0) return 'absent'
  35. if (await groupRow.getAttribute('aria-expanded') !== 'true') {
  36. await header.click()
  37. return 'collapsed'
  38. }
  39. return 'expanded'
  40. }, { timeout: 15_000 }).toBe('expanded')
  41. return groupRow.locator('..')
  42. }
  43. /**
  44. * Reveal and click a row action, re-hovering if a projection update replaces
  45. * the row before its hover-only button becomes visible.
  46. * @param row - the row owning the action.
  47. * @param name - accessible name of the action button.
  48. */
  49. async function clickHoverAction(row: Locator, name: string): Promise<void> {
  50. const button = row.getByRole('button', { name })
  51. await expect.poll(async () => {
  52. await row.hover()
  53. return await button.isVisible()
  54. }, { timeout: 10_000 }).toBe(true)
  55. await button.click()
  56. }
  57. beforeAll(async () => {
  58. scaffold = await launchWebScaffold({})
  59. // Seed one cold session; with no Workspace registered it is the sidebar's
  60. // only row, in the Ungrouped bucket.
  61. await seedSession(scaffold, await readFile(SEED, 'utf8'), SEED_ID)
  62. browser = await chromium.launch()
  63. page = await newEnglishPage(browser)
  64. tripwire = watchConsole(page)
  65. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  66. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  67. }, 120_000)
  68. afterAll(async () => {
  69. await browser?.close()
  70. await scaffold?.close()
  71. })
  72. it('archives the seed, unarchives it from Settings, and keeps it restored across reload', async () => {
  73. onTestFailed(() => saveFailureShot(page, 'web-e2e-session-unarchive'))
  74. // Select the only visible Session, then give it a user-owned title: the
  75. // locator binds to the seed's own copy on both sides of the round trip.
  76. const seededRow = (await ungroupedSection()).locator('[role="treeitem"]')
  77. .filter({ has: page.locator('button[aria-label^="Session actions for "]') })
  78. await expect.poll(() => seededRow.count(), { timeout: 10_000 }).toBe(1)
  79. await seededRow.click()
  80. await expect.poll(() => seededRow.getAttribute('aria-selected'), { timeout: 10_000 }).toBe('true')
  81. const { title } = await scaffold.ctx.sessionController.rename({
  82. sessionId: SessionId(SEED_ID), title: `Unarchive target ${SEED_ID}`,
  83. })
  84. const sessionRow = page.getByRole('treeitem').filter({ has: page.getByText(title, { exact: true }) })
  85. await expect.poll(() => sessionRow.count(), { timeout: 10_000 }).toBe(1)
  86. await expect.poll(() => sessionRow.getAttribute('aria-selected'), { timeout: 10_000 }).toBe('true')
  87. // Archive from the row menu: no confirmation dialog, and losing the last
  88. // visible Session withdraws the whole Ungrouped bucket.
  89. await clickHoverAction(sessionRow, `Session actions for ${title}`)
  90. await page.getByRole('menuitem', { name: 'Archive session' }).click()
  91. await expect.poll(() => sessionRow.count(), { timeout: 10_000 }).toBe(0)
  92. await expect.poll(() => page.getByText('Ungrouped', { exact: true }).count(), { timeout: 10_000 }).toBe(0)
  93. // Durable on the host: the registry-global set carries the id while the
  94. // Session log itself stays in persistence untouched.
  95. expect([...scaffold.ctx.workspaceRegistry.archivedSessionIds]).toEqual([SessionId(SEED_ID)])
  96. expect((await scaffold.ctx.sessionPersistence.list()).map(snapshot => snapshot.header.id))
  97. .toContain(SessionId(SEED_ID))
  98. // The Settings page lists the archived Session behind its own search box.
  99. await page.getByRole('button', { name: 'Settings', exact: true }).click()
  100. const dialog = page.getByRole('dialog', { name: 'Settings' })
  101. await dialog.waitFor({ timeout: 10_000 })
  102. await dialog.getByRole('button', { name: 'Archived sessions' }).click()
  103. const search = dialog.getByRole('searchbox', { name: 'Search archived sessions' })
  104. await search.waitFor({ timeout: 10_000 })
  105. const unarchiveRow = dialog.getByRole('button', { name: `Unarchive ${title}` })
  106. await expect.poll(() => unarchiveRow.count(), { timeout: 10_000 }).toBe(1)
  107. expect(await dialog.getByText(title, { exact: true }).count()).toBe(1)
  108. expect(await dialog.getByText(/^Ungrouped · /).count()).toBe(1)
  109. expect(await dialog.getByText('No archived sessions.', { exact: true }).count()).toBe(0)
  110. // The search box filters these rows in both directions.
  111. await search.fill('zzz-no-such-archived-session')
  112. await expect.poll(
  113. () => dialog.getByText('No matching sessions.', { exact: true }).count(),
  114. { timeout: 5_000 },
  115. ).toBe(1)
  116. expect(await unarchiveRow.count()).toBe(0)
  117. await search.fill(title)
  118. await expect.poll(() => unarchiveRow.count(), { timeout: 5_000 }).toBe(1)
  119. expect(await dialog.getByText('No matching sessions.', { exact: true }).count()).toBe(0)
  120. await search.fill('')
  121. await expect.poll(() => unarchiveRow.count(), { timeout: 5_000 }).toBe(1)
  122. // Unarchive: the durable set empties (the row's own RPC), the page row
  123. // leaves with the empty status, and the Session row is back in the sidebar.
  124. await unarchiveRow.click()
  125. await expect.poll(
  126. () => [...scaffold.ctx.workspaceRegistry.archivedSessionIds],
  127. { timeout: 10_000 },
  128. ).toEqual([])
  129. await expect.poll(() => unarchiveRow.count(), { timeout: 10_000 }).toBe(0)
  130. expect(await dialog.getByText(title, { exact: true }).count()).toBe(0)
  131. await expect.poll(
  132. () => dialog.getByText('No archived sessions.', { exact: true }).count(),
  133. { timeout: 10_000 },
  134. ).toBe(1)
  135. await dialog.getByRole('button', { name: 'Close' }).last().click()
  136. await dialog.waitFor({ state: 'hidden', timeout: 10_000 })
  137. await ungroupedSection()
  138. await expect.poll(() => sessionRow.count(), { timeout: 15_000 }).toBe(1)
  139. // Reload: the restored row is rebuilt from the host baseline, so the
  140. // unarchive was durable and not merely client state.
  141. const warningStart = tripwire.warnings.length
  142. await page.reload({ waitUntil: 'load' })
  143. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  144. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  145. await ungroupedSection()
  146. await expect.poll(() => sessionRow.count(), { timeout: 15_000 }).toBe(1)
  147. expect(tripwire.pageErrors).toEqual([])
  148. expect(tripwire.warnings).toEqual([])
  149. }, 120_000)
  150. })