cold-blank-session.e2e.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /** Cold Session list visibility through the shipped compressed JSONL backend. */
  2. import { mkdir, stat } from 'node:fs/promises'
  3. import { fileURLToPath } from 'node:url'
  4. import { join } from 'node:path'
  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. captureStableAria, compareOrRefreshGolden, launchWebScaffold, seedBlankSession,
  10. watchConsole, webSnapshotMode, type WebScaffold,
  11. } from './scaffold.ts'
  12. import { newEnglishPage, saveFailureShot } from './support.ts'
  13. const SNAPSHOT_DIR = fileURLToPath(new URL('./expected/cold-blank-session', import.meta.url))
  14. const SIDEBAR_EXPECTED = join(SNAPSHOT_DIR, 'sidebar.expected.md')
  15. const MODE = webSnapshotMode()
  16. const SESSION_ID = 'cold-blank-session-web-e2e'
  17. const WORKSPACE_NAME = 'cold-blank-workspace'
  18. describe('web e2e: cold blank Session visibility', () => {
  19. let scaffold: WebScaffold
  20. let browser: Browser
  21. let page: Page
  22. let tripwire: ReturnType<typeof watchConsole>
  23. beforeAll(async () => {
  24. scaffold = await launchWebScaffold({})
  25. const cwd = join(scaffold.workspaceCwd, WORKSPACE_NAME)
  26. await mkdir(cwd, { recursive: true })
  27. await seedBlankSession(scaffold, SESSION_ID, cwd)
  28. const header = (await scaffold.ctx.sessionPersistence.list())
  29. .find(candidate => candidate.id === SESSION_ID)
  30. if (header === undefined) throw new Error('blank Session fixture did not materialize')
  31. const location = scaffold.ctx.sessionPersistence.locate(header)
  32. if (location === undefined) throw new Error('JSONL fixture has no physical artifact')
  33. expect((await stat(location.path)).size).toBeLessThanOrEqual(1024)
  34. browser = await chromium.launch()
  35. page = await newEnglishPage(browser)
  36. tripwire = watchConsole(page)
  37. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  38. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  39. }, 120_000)
  40. afterAll(async () => {
  41. await browser?.close()
  42. await scaffold?.close()
  43. })
  44. it('keeps the verified cold blank Session out of the sidebar', async () => {
  45. onTestFailed(() => saveFailureShot(page, 'web-e2e-cold-blank-session'))
  46. const tree = page.getByRole('tree', { name: 'Sessions' })
  47. await tree.waitFor({ timeout: 30_000 })
  48. expect(await tree.getByText(WORKSPACE_NAME, { exact: true }).count()).toBe(0)
  49. const sidebar = await captureStableAria(page, '[role="tree"][aria-label="Sessions"]', scaffold.workspaceCwd)
  50. await compareOrRefreshGolden(SIDEBAR_EXPECTED, sidebar, MODE)
  51. expect(tripwire.pageErrors).toEqual([])
  52. })
  53. })