diff-context.e2e.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 } from 'vitest'
  6. import {
  7. assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
  8. launchWebScaffold, seedSession, webSnapshotMode, type WebScaffold,
  9. } from './scaffold.ts'
  10. import { expandTurnProcesses, newEnglishPage } 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. beforeAll(async () => {
  19. scaffold = await launchWebScaffold({})
  20. await seedSession(scaffold, await readFile(SOURCE, 'utf8'), 'diff-context')
  21. browser = await chromium.launch()
  22. page = await newEnglishPage(browser)
  23. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  24. })
  25. afterAll(async () => {
  26. try {
  27. await browser?.close()
  28. } finally {
  29. await scaffold?.close()
  30. }
  31. })
  32. it('shows true totals before expansion and neutral shared context after expansion', async () => {
  33. const group = page.locator('[role="treeitem"]').first()
  34. await group.waitFor({ timeout: 15_000 })
  35. await group.click()
  36. await page.locator('[role="treeitem"]').nth(1).click()
  37. await page.getByText('DONE', { exact: true }).waitFor({ timeout: 15_000 })
  38. await expandTurnProcesses(page)
  39. const edit = page.locator('[data-variant="edit"]')
  40. expect(await edit.textContent()).toContain('+1 -1')
  41. expect(await edit.locator('[data-diff]').count()).toBe(0)
  42. await edit.locator('[data-expandable]').click()
  43. const card = edit.locator('[data-diff]')
  44. await card.waitFor()
  45. expect(await card.getByText('level=info', { exact: true }).count()).toBe(1)
  46. expect(await card.textContent()).toContain('+1 -1 · 1 file')
  47. await compareOrRefreshGolden(`${SNAPSHOT_DIR}/ui.expected.md`,
  48. await captureStableAria(page, '[data-variant="edit"]', scaffold.workspaceCwd), MODE)
  49. await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
  50. })
  51. })