diff-context.e2e.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /** Cold Session rendering covers exact context and bounded whole-fragment replacements. */
  2. import { readFile } from 'node:fs/promises'
  3. import { fileURLToPath } from 'node:url'
  4. import { chromium, type Browser, type Page } from 'playwright'
  5. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  6. import {
  7. assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
  8. launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold,
  9. } from './scaffold.ts'
  10. import { expandTurnProcesses, newEnglishPage, saveFailureShot } from './support.ts'
  11. const ROOT = fileURLToPath(new URL('../../../snapshots', import.meta.url))
  12. const MODE = webSnapshotMode()
  13. const CASES = [
  14. { name: 'diff-context', source: 'session/fs-edit/session.v3.jsonl', totals: '+1 -1', shared: 'level=info', inventory: ['ui.expected.md'] },
  15. { name: 'diff-bounded', source: 'web/diff-bounded/session.v3.jsonl', totals: '+130 -130', shared: 'shared heading', inventory: ['session.v3.jsonl', 'ui.expected.md'] },
  16. ]
  17. describe.skipIf(MODE === 'record').each(CASES)('web e2e: $name', (scenario) => {
  18. let scaffold: WebScaffold
  19. let browser: Browser
  20. let page: Page
  21. let tripwire: ReturnType<typeof watchConsole>
  22. beforeAll(async () => {
  23. scaffold = await launchWebScaffold({})
  24. await seedSession(scaffold, await readFile(`${ROOT}/${scenario.source}`, 'utf8'), scenario.name)
  25. browser = await chromium.launch()
  26. page = await newEnglishPage(browser)
  27. tripwire = watchConsole(page)
  28. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  29. })
  30. afterAll(async () => {
  31. try {
  32. await browser?.close()
  33. } finally {
  34. await scaffold?.close()
  35. }
  36. })
  37. it('keeps collapsed and expanded counts consistent with the displayed diff', async () => {
  38. onTestFailed(() => saveFailureShot(page, `web-e2e-${scenario.name}`))
  39. const group = page.locator('[role="treeitem"]').first()
  40. await group.waitFor({ timeout: 15_000 })
  41. await group.click()
  42. await page.locator('[role="treeitem"]').nth(1).click()
  43. await page.getByText('DONE', { exact: true }).waitFor({ timeout: 15_000 })
  44. await expandTurnProcesses(page)
  45. const edit = page.locator('[data-variant="edit"]')
  46. expect(await edit.textContent()).toContain(scenario.totals)
  47. expect(await edit.locator('[data-diff]').count()).toBe(0)
  48. await edit.locator('[data-expandable]').click()
  49. const card = edit.locator('[data-diff]')
  50. await card.waitFor()
  51. expect(await card.getByText(scenario.shared, { exact: true }).count()).toBe(1)
  52. expect(await card.textContent()).toContain(`${scenario.totals} · 1 file`)
  53. const snapshotDir = `${ROOT}/web/${scenario.name}`
  54. await compareOrRefreshGolden(`${snapshotDir}/ui.expected.md`,
  55. await captureStableAria(page, '[data-variant="edit"]', scaffold.workspaceCwd), MODE)
  56. await assertFixtureInventory(snapshotDir, scenario.inventory)
  57. expect(tripwire.pageErrors).toEqual([])
  58. expect(tripwire.warnings).toEqual([])
  59. })
  60. })