workspace-new-session-folding.e2e.ts 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /** Blank New Session folding through the shipped Web composition. */
  2. import { readFile } from 'node:fs/promises'
  3. import { basename, join } from 'node:path'
  4. import { fileURLToPath } from 'node:url'
  5. import type { Browser, Page } from 'playwright'
  6. import { chromium } from 'playwright'
  7. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  8. import {
  9. assertFixtureInventory,
  10. captureStableAria,
  11. compareOrRefreshGolden,
  12. launchWebScaffold,
  13. seedSession,
  14. watchConsole,
  15. webSnapshotMode,
  16. type WebScaffold,
  17. } from './scaffold.ts'
  18. import { newEnglishPage, saveFailureShot } from './support.ts'
  19. const EXPECTED_DIR = fileURLToPath(new URL('./expected/workspace-new-session-folding', import.meta.url))
  20. const SIDEBAR_EXPECTED = join(EXPECTED_DIR, 'sidebar.expected.md')
  21. const SEED = fileURLToPath(new URL('../../../snapshots/web/message-feedback-protocol/session.v3.jsonl', import.meta.url))
  22. const MODE = webSnapshotMode()
  23. const EXISTING_SESSION_COUNT = 6
  24. describe('web e2e: blank New Session folding quota', () => {
  25. let scaffold: WebScaffold
  26. let browser: Browser
  27. let page: Page
  28. let tripwire: ReturnType<typeof watchConsole>
  29. beforeAll(async () => {
  30. scaffold = await launchWebScaffold({})
  31. const fixture = await readFile(SEED, 'utf8')
  32. const sessionIds = []
  33. for (let index = 1; index <= EXISTING_SESSION_COUNT; index += 1) {
  34. sessionIds.push(await seedSession(
  35. scaffold,
  36. fixture,
  37. `workspace-new-session-folding-${String(index).padStart(2, '0')}`,
  38. ))
  39. }
  40. const workspace = await scaffold.ctx.workspaceRegistry.create(scaffold.workspaceCwd)
  41. for (const sessionId of sessionIds) await workspace.attachSession(sessionId)
  42. browser = await chromium.launch()
  43. page = await newEnglishPage(browser)
  44. tripwire = watchConsole(page)
  45. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  46. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  47. const workspaceTitle = basename(scaffold.workspaceCwd)
  48. const workspaceRow = page.getByText(workspaceTitle, { exact: true }).first()
  49. .locator('xpath=ancestor::*[@role="treeitem"][1]')
  50. await workspaceRow.waitFor({ timeout: 15_000 })
  51. if (await workspaceRow.getAttribute('aria-expanded') !== 'true') await workspaceRow.click()
  52. await workspaceRow.hover()
  53. await page.getByRole('button', { name: `New session in ${workspaceTitle}` }).click()
  54. await page.getByRole('tree', { name: 'Sessions' })
  55. .getByText('New Session', { exact: true }).waitFor({ timeout: 15_000 })
  56. }, 120_000)
  57. afterAll(async () => {
  58. await browser?.close()
  59. await scaffold?.close()
  60. })
  61. it('keeps five established sessions beside the provisional row', async () => {
  62. onTestFailed(() => saveFailureShot(page, 'web-e2e-workspace-new-session-folding'))
  63. const sidebar = page.getByRole('tree', { name: 'Sessions' })
  64. await expect.poll(() => sidebar.getByRole('treeitem').count(), { timeout: 15_000 }).toBe(7)
  65. expect(await sidebar.getByText('New Session', { exact: true }).count()).toBe(1)
  66. expect(await sidebar.getByText(basename(scaffold.workspaceCwd), { exact: true }).count()).toBe(6)
  67. const showMore = sidebar.getByRole('button', { name: 'Show 1 more sessions' })
  68. await showMore.waitFor({ timeout: 15_000 })
  69. await compareOrRefreshGolden(
  70. SIDEBAR_EXPECTED,
  71. await captureStableAria(page, '[role="tree"][aria-label="Sessions"]', scaffold.workspaceCwd),
  72. MODE,
  73. )
  74. await showMore.click()
  75. await expect.poll(() => sidebar.getByRole('treeitem').count(), { timeout: 10_000 }).toBe(8)
  76. expect(await sidebar.getByText(basename(scaffold.workspaceCwd), { exact: true }).count()).toBe(7)
  77. await sidebar.getByRole('button', { name: 'Show less' }).click()
  78. await expect.poll(() => sidebar.getByRole('treeitem').count()).toBe(7)
  79. await assertFixtureInventory(EXPECTED_DIR, ['sidebar.expected.md'])
  80. expect(tripwire.pageErrors).toEqual([])
  81. expect(tripwire.warnings).toEqual([])
  82. })
  83. })