goal-bar.e2e.ts 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Keyless browser coverage for the goal bar over the shipped Web composition.
  2. // The command creates a real projected goal in a real Host session. The
  3. // goldens pin the active and disarmed strips, while the clear gesture proves
  4. // the acknowledged tombstone leaves neither stale chrome nor a
  5. // duplicate-mutation error.
  6. import { fileURLToPath } from 'node:url'
  7. import { join } from 'node:path'
  8. import type { Browser, Page } from 'playwright'
  9. import { chromium } from 'playwright'
  10. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  11. import type {} from '@deepseek-ai/dsh-goal'
  12. import {
  13. assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
  14. launchWebScaffold, watchConsole, webSnapshotMode, type WebScaffold,
  15. } from './scaffold.ts'
  16. import { connectFreshWorkspace, newEnglishPage, saveFailureShot } from './support.ts'
  17. const SNAPSHOT_DIR = fileURLToPath(new URL('./expected/goal-bar', import.meta.url))
  18. const ACTIVE_EXPECTED = join(SNAPSHOT_DIR, 'active.expected.md')
  19. const INACTIVE_EXPECTED = join(SNAPSHOT_DIR, 'inactive.expected.md')
  20. const OVERLAY = fileURLToPath(new URL('./goal-bar.overlay.yml', import.meta.url))
  21. const MODE = webSnapshotMode()
  22. describe('web e2e: goal bar clear convergence', () => {
  23. let scaffold: WebScaffold
  24. let browser: Browser
  25. let page: Page
  26. let tripwire: ReturnType<typeof watchConsole>
  27. beforeAll(async () => {
  28. scaffold = await launchWebScaffold({ extraOverlayPath: OVERLAY })
  29. browser = await chromium.launch()
  30. page = await newEnglishPage(browser)
  31. tripwire = watchConsole(page)
  32. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  33. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  34. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  35. }, 120_000)
  36. afterAll(async () => {
  37. await browser?.close()
  38. await scaffold?.close()
  39. })
  40. it('renders one active goal and clears it without exposing a stale error', async () => {
  41. onTestFailed(() => saveFailureShot(page, 'web-e2e-goal-bar-clear'))
  42. const input = page.locator('[data-composer-input][data-placeholder="Describe what you want to build, / commands, @ files or sessions"]')
  43. await input.waitFor({ timeout: 10_000 })
  44. await input.fill('/goal guard rapid clear clicks')
  45. await input.press('Enter')
  46. const bar = page.locator('[data-goal-bar]')
  47. await bar.waitFor({ timeout: 10_000 })
  48. const pause = bar.getByRole('button', { name: 'Pause goal' })
  49. await expect.poll(() => pause.count(), {
  50. timeout: 10_000,
  51. }).toBe(1)
  52. const snapshot = await captureStableAria(page, '[data-goal-bar]', scaffold.workspaceCwd)
  53. await compareOrRefreshGolden(ACTIVE_EXPECTED, snapshot, MODE)
  54. const agents = scaffold.ctx.agents.list()
  55. expect(agents).toHaveLength(1)
  56. scaffold.ctx.goals.disarm(agents[0]!)
  57. await expect.poll(() => bar.getByRole('button', { name: 'Resume goal' }).count(), {
  58. timeout: 10_000,
  59. }).toBe(1)
  60. const inactive = await captureStableAria(page, '[data-goal-bar]', scaffold.workspaceCwd)
  61. await compareOrRefreshGolden(INACTIVE_EXPECTED, inactive, MODE)
  62. const clear = bar.getByRole('button', { name: 'Clear goal' })
  63. await clear.evaluate((button) => {
  64. const control = button as HTMLButtonElement
  65. control.click()
  66. control.click()
  67. })
  68. await expect.poll(() => page.locator('[data-goal-bar]').count(), { timeout: 10_000 }).toBe(0)
  69. expect(await page.getByText(/no current goal/iu).count()).toBe(0)
  70. expect(tripwire.pageErrors).toEqual([])
  71. expect(tripwire.warnings).toEqual([])
  72. }, 60_000)
  73. it.skipIf(MODE === 'record')('keeps the fixture inventory closed', async () => {
  74. await assertFixtureInventory(SNAPSHOT_DIR, ['active.expected.md', 'inactive.expected.md'])
  75. })
  76. })