diff-context.e2e.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /** Cold rendering of the shared filesystem edit Session preserves neutral context. */
  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 SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/diff-context', import.meta.url))
  12. const SOURCE = fileURLToPath(new URL('../../../snapshots/session/fs-edit/session.v3.jsonl', import.meta.url))
  13. const MODE = webSnapshotMode()
  14. describe.skipIf(MODE === 'record')('web e2e: contextual edit diff', () => {
  15. let scaffold: WebScaffold
  16. let browser: Browser
  17. let page: Page
  18. let tripwire: ReturnType<typeof watchConsole>
  19. beforeAll(async () => {
  20. scaffold = await launchWebScaffold({})
  21. await seedSession(scaffold, await readFile(SOURCE, 'utf8'), 'diff-context')
  22. browser = await chromium.launch()
  23. page = await newEnglishPage(browser)
  24. tripwire = watchConsole(page)
  25. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  26. })
  27. afterAll(async () => {
  28. try {
  29. await browser?.close()
  30. } finally {
  31. await scaffold?.close()
  32. }
  33. })
  34. it('shows true totals before expansion and neutral shared context after expansion', async () => {
  35. onTestFailed(() => saveFailureShot(page, 'web-e2e-diff-context'))
  36. const group = page.locator('[role="treeitem"]').first()
  37. await group.waitFor({ timeout: 15_000 })
  38. await group.click()
  39. await page.locator('[role="treeitem"]').nth(1).click()
  40. await page.getByText('DONE', { exact: true }).waitFor({ timeout: 15_000 })
  41. await expandTurnProcesses(page)
  42. const edit = page.locator('[data-variant="edit"]')
  43. expect(await edit.textContent()).toContain('+1 -1')
  44. expect(await edit.locator('[data-diff]').count()).toBe(0)
  45. await edit.locator('[data-expandable]').click()
  46. const card = edit.locator('[data-diff]')
  47. await card.waitFor()
  48. expect(await card.getByText('level=info', { exact: true }).count()).toBe(1)
  49. expect(await card.textContent()).toContain('+1 -1 · 1 file')
  50. await compareOrRefreshGolden(`${SNAPSHOT_DIR}/ui.expected.md`,
  51. await captureStableAria(page, '[data-variant="edit"]', scaffold.workspaceCwd), MODE)
  52. await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
  53. expect(tripwire.pageErrors).toEqual([])
  54. expect(tripwire.warnings).toEqual([])
  55. })
  56. })