goal-command-presentation.e2e.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Web e2e: /goal opts its command input into the human transcript while the
  2. // command remains log-only. The shipped composition runs with no model adapter,
  3. // so an accidental turn fails loud in addition to the event-level assertions.
  4. import { fileURLToPath } from 'node:url'
  5. import type { Browser, Page } from 'playwright'
  6. import { chromium } from 'playwright'
  7. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  8. import type { SessionEvent } from '@deepseek-ai/dsh-session/types'
  9. import type {} from '@deepseek-ai/dsh-commands/types'
  10. import {
  11. acknowledgeReloadConnectionLoss, assertFixtureInventory, captureStableAria,
  12. compareOrRefreshGolden, launchWebScaffold, watchConsole, webSnapshotMode,
  13. type WebScaffold,
  14. } from './scaffold.ts'
  15. import { connectFreshWorkspace, newEnglishPage, saveFailureShot } from './support.ts'
  16. const SNAPSHOT_DIR = fileURLToPath(new URL('./expected/goal-command-presentation', import.meta.url))
  17. const UI_EXPECTED = fileURLToPath(new URL(
  18. './expected/goal-command-presentation/ui.expected.md', import.meta.url,
  19. ))
  20. const MODE = webSnapshotMode()
  21. describe('web e2e: /goal human transcript presentation', () => {
  22. let scaffold: WebScaffold
  23. let browser: Browser
  24. let page: Page
  25. let tripwire: ReturnType<typeof watchConsole>
  26. const events: SessionEvent[] = []
  27. beforeAll(async () => {
  28. scaffold = await launchWebScaffold()
  29. scaffold.ctx.on('session/event', (_session, event: SessionEvent) => { events.push(event) })
  30. browser = await chromium.launch()
  31. page = await newEnglishPage(browser)
  32. tripwire = watchConsole(page)
  33. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  34. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  35. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  36. }, 120_000)
  37. afterAll(async () => {
  38. await browser?.close()
  39. await scaffold?.close()
  40. })
  41. it('shows the bare input and result from a fresh session without a model turn', async () => {
  42. onTestFailed(() => saveFailureShot(page, 'web-e2e-goal-command-presentation'))
  43. await expect.poll(() => page.getByText('Into the Unknown', { exact: false }).count(), {
  44. timeout: 15_000,
  45. }).toBe(1)
  46. const input = page.locator('textarea').first()
  47. await input.fill('/goal')
  48. await input.press('Enter')
  49. await expect.poll(() => input.inputValue()).toBe('/goal ')
  50. await input.press('Enter')
  51. const commandInput = page.locator('[data-command-input]')
  52. await commandInput.waitFor({ timeout: 10_000 })
  53. await expect.poll(() => commandInput.textContent()).toBe('/goal')
  54. expect(await commandInput.getAttribute('role')).toBe('group')
  55. expect(await commandInput.getAttribute('aria-label')).toBe('Command input')
  56. expect(await commandInput.getByRole('button').count()).toBe(0)
  57. const typography = await commandInput.evaluate((element) => {
  58. const bubble = element.firstElementChild?.firstElementChild
  59. if (!(bubble instanceof HTMLElement)) throw new Error('command input bubble is missing')
  60. const rootStyle = getComputedStyle(element)
  61. const bubbleStyle = getComputedStyle(bubble)
  62. return {
  63. fontFamily: bubbleStyle.fontFamily,
  64. parentFontFamily: rootStyle.fontFamily,
  65. fontSize: bubbleStyle.fontSize,
  66. lineHeight: bubbleStyle.lineHeight,
  67. }
  68. })
  69. expect(typography).toMatchObject({ fontSize: '14px', lineHeight: '22px' })
  70. expect(typography.fontFamily).not.toBe(typography.parentFontFamily)
  71. const resultRow = page.locator('[data-variant="others"]').filter({ hasText: 'No goal is currently set.' })
  72. await expect.poll(() => resultRow.count(), { timeout: 10_000 }).toBe(1)
  73. expect(await resultRow.getByText('goal', { exact: true }).count()).toBe(1)
  74. await expect.poll(() => page.locator('[data-phase="active"]').count()).toBe(1)
  75. expect(await page.getByText('Into the Unknown', { exact: false }).count()).toBe(0)
  76. const run = events.find(event => event.type === 'command/run')
  77. expect(run).toMatchObject({
  78. type: 'command/run',
  79. data: { name: 'goal', args: ' ', source: { kind: 'user' } },
  80. })
  81. expect(events.some(event => event.type === 'command/done')).toBe(true)
  82. expect(events.some(event => event.type === 'user/message')).toBe(false)
  83. expect(events.some(event => event.type === 'turn/start')).toBe(false)
  84. expect(events.some(event => event.type === 'step/start')).toBe(false)
  85. expect(events.some(event => event.type === 'request/header')).toBe(false)
  86. const snapshot = await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd)
  87. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  88. }, 60_000)
  89. it('reloads the same bubble and result from the persisted command lifecycle', async () => {
  90. onTestFailed(() => saveFailureShot(page, 'web-e2e-goal-command-presentation-reload'))
  91. const warningStart = tripwire.warnings.length
  92. await page.reload({ waitUntil: 'load' })
  93. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  94. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  95. await expect.poll(() => page.locator('[data-command-input]').textContent(), { timeout: 15_000 }).toBe('/goal')
  96. const resultRow = page.locator('[data-variant="others"]').filter({ hasText: 'No goal is currently set.' })
  97. await expect.poll(() => resultRow.count(), { timeout: 10_000 }).toBe(1)
  98. await expect.poll(() => page.locator('[data-phase="active"]').count()).toBe(1)
  99. const sessions = scaffold.ctx.sessions.list()
  100. expect(sessions).toHaveLength(1)
  101. const persisted = sessions[0]?.events ?? []
  102. expect(persisted.filter(event => event.type === 'command/run' || event.type === 'command/done')
  103. .map(event => event.type)).toEqual(['command/run', 'command/done'])
  104. expect(persisted.some(event => event.type === 'user/message')).toBe(false)
  105. expect(persisted.some(event => event.type === 'turn/start')).toBe(false)
  106. expect(persisted.some(event => event.type === 'step/start')).toBe(false)
  107. expect(persisted.some(event => event.type === 'request/header')).toBe(false)
  108. expect(tripwire.pageErrors).toEqual([])
  109. expect(tripwire.warnings).toEqual([])
  110. await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
  111. }, 90_000)
  112. })