goal-command-presentation.e2e.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.authenticatedUrl, { 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('completes with Tab and shows the bare input and result 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('[data-composer-input]').first()
  47. await input.fill('/go')
  48. const menu = page.getByRole('listbox', { name: 'Trigger suggestions' })
  49. await menu.getByRole('option', { name: 'goal set or view the goal for a long-running task' })
  50. .waitFor({ timeout: 10_000 })
  51. await input.press('Tab')
  52. await expect.poll(() => input.textContent()).toBe('/goal ')
  53. await expect.poll(() => menu.count()).toBe(0)
  54. await input.press('Enter')
  55. const commandInput = page.locator('[data-command-input]')
  56. await commandInput.waitFor({ timeout: 10_000 })
  57. await expect.poll(() => commandInput.textContent()).toBe('/goal')
  58. expect(await commandInput.getAttribute('role')).toBe('group')
  59. expect(await commandInput.getAttribute('aria-label')).toBe('Command input')
  60. expect(await commandInput.getByRole('button').count()).toBe(0)
  61. const typography = await commandInput.evaluate((element) => {
  62. const bubble = element.firstElementChild?.firstElementChild
  63. if (!(bubble instanceof HTMLElement)) throw new Error('command input bubble is missing')
  64. const chip = bubble.querySelector('[data-ref-chip="command"]')
  65. if (!(chip instanceof HTMLElement)) throw new Error('command chip is missing')
  66. const rootStyle = getComputedStyle(element)
  67. const bubbleStyle = getComputedStyle(bubble)
  68. const chipStyle = getComputedStyle(chip)
  69. return {
  70. fontFamily: bubbleStyle.fontFamily,
  71. parentFontFamily: rootStyle.fontFamily,
  72. fontSize: bubbleStyle.fontSize,
  73. lineHeight: bubbleStyle.lineHeight,
  74. chipText: chip.textContent,
  75. chipFontFamily: chipStyle.fontFamily,
  76. chipFontSize: chipStyle.fontSize,
  77. }
  78. })
  79. expect(typography).toMatchObject({ fontSize: '14px', lineHeight: '22px', chipText: '/goal', chipFontSize: '14px' })
  80. // The bubble reads in the body face like a user bubble; only the command
  81. // chip carries the code face that marks the echoed token as a command.
  82. expect(typography.fontFamily).toBe(typography.parentFontFamily)
  83. expect(typography.chipFontFamily).not.toBe(typography.fontFamily)
  84. const resultRow = page.locator('[data-variant="others"]').filter({ hasText: 'No goal is currently set.' })
  85. await expect.poll(() => resultRow.count(), { timeout: 10_000 }).toBe(1)
  86. expect(await resultRow.getByText('goal', { exact: true }).count()).toBe(1)
  87. await expect.poll(() => page.locator('[data-phase="active"]').count()).toBe(1)
  88. expect(await page.getByText('Into the Unknown', { exact: false }).count()).toBe(0)
  89. const run = events.find(event => event.type === 'command/run')
  90. expect(run).toMatchObject({
  91. type: 'command/run',
  92. data: { name: 'goal', args: ' ', source: { kind: 'user' } },
  93. })
  94. expect(events.some(event => event.type === 'command/done')).toBe(true)
  95. expect(events.some(event => event.type === 'user/message')).toBe(false)
  96. expect(events.some(event => event.type === 'turn/start')).toBe(false)
  97. expect(events.some(event => event.type === 'step/start')).toBe(false)
  98. expect(events.some(event => event.type === 'request/header')).toBe(false)
  99. // The command result can arrive before Lexical clears the submitted claim.
  100. await expect.poll(() => input.textContent(), { timeout: 10_000 }).toBe('')
  101. const snapshot = await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd)
  102. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  103. }, 60_000)
  104. it('reloads the same bubble and result from the persisted command lifecycle', async () => {
  105. onTestFailed(() => saveFailureShot(page, 'web-e2e-goal-command-presentation-reload'))
  106. const warningStart = tripwire.warnings.length
  107. await page.reload({ waitUntil: 'load' })
  108. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  109. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  110. await expect.poll(() => page.locator('[data-command-input]').textContent(), { timeout: 15_000 }).toBe('/goal')
  111. const resultRow = page.locator('[data-variant="others"]').filter({ hasText: 'No goal is currently set.' })
  112. await expect.poll(() => resultRow.count(), { timeout: 10_000 }).toBe(1)
  113. await expect.poll(() => page.locator('[data-phase="active"]').count()).toBe(1)
  114. const sessions = scaffold.ctx.sessions.list()
  115. expect(sessions).toHaveLength(1)
  116. const persisted = sessions[0]?.snapshotEvents() ?? []
  117. expect(persisted.filter(event => event.type === 'command/run' || event.type === 'command/done')
  118. .map(event => event.type)).toEqual(['command/run', 'command/done'])
  119. expect(persisted.some(event => event.type === 'user/message')).toBe(false)
  120. expect(persisted.some(event => event.type === 'turn/start')).toBe(false)
  121. expect(persisted.some(event => event.type === 'step/start')).toBe(false)
  122. expect(persisted.some(event => event.type === 'request/header')).toBe(false)
  123. expect(tripwire.pageErrors).toEqual([])
  124. expect(tripwire.warnings).toEqual([])
  125. await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
  126. }, 90_000)
  127. })