feedback-command.e2e.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Keyless assembled-browser coverage for the /feedback command over the
  2. // shipped Web bundles and the real host wire. The command plane settles
  3. // without a model turn: the host appends the log-only command/run +
  4. // feedback/record + command/done lifecycle, and the transcript renders the
  5. // acknowledgement with the session and anonymous user ids as a persistent
  6. // command row.
  7. import { readFile } from 'node:fs/promises'
  8. import { fileURLToPath } from 'node:url'
  9. import { join } from 'node:path'
  10. import type { Browser, Page } from 'playwright'
  11. import { chromium } from 'playwright'
  12. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  13. import {
  14. assertFixtureInventory, captureExpandedTurnProcessAria, captureStableAria,
  15. compareOrRefreshGolden, fixtureUserPrompts,
  16. launchWebScaffold, recordFixture, watchConsole, webSnapshotMode, type WebScaffold,
  17. } from './scaffold.ts'
  18. import { connectFreshWorkspace, newEnglishPage, saveFailureShot } from './support.ts'
  19. const SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/feedback-command', import.meta.url))
  20. const FIXTURE = join(SNAPSHOT_DIR, 'session.v3.jsonl')
  21. const ACK_EXPECTED = join(SNAPSHOT_DIR, 'ack.expected.md')
  22. const ACK_EXPANDED_EXPECTED = join(SNAPSHOT_DIR, 'ack-expanded.expected.md')
  23. const MODE = webSnapshotMode()
  24. const PROMPT = 'Reply with the single word LIGHTHOUSE and stop.'
  25. describe('web e2e: /feedback command acknowledgement', () => {
  26. let scaffold: WebScaffold
  27. let browser: Browser
  28. let page: Page
  29. let tripwire: ReturnType<typeof watchConsole>
  30. beforeAll(async () => {
  31. scaffold = await launchWebScaffold({
  32. compareReplaySession: true,
  33. ...(MODE === 'record' ? {} : { replayFixture: FIXTURE, paceMs: 5 }),
  34. })
  35. browser = await chromium.launch()
  36. page = await newEnglishPage(browser)
  37. tripwire = watchConsole(page)
  38. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  39. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  40. // Fresh world: connecting a workspace births the blank session whose
  41. // live composer accepts the slash line.
  42. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  43. }, 120_000)
  44. afterAll(async () => {
  45. await browser?.close()
  46. await scaffold?.close()
  47. })
  48. it('drives the recorded prompt to a settled turn (all modes)', async () => {
  49. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-drive'))
  50. if (MODE !== 'record') {
  51. // Drift guard: the committed fixture must carry exactly the drive prompt.
  52. expect(fixtureUserPrompts(await readFile(FIXTURE, 'utf8'))).toEqual([PROMPT])
  53. }
  54. const input = page.locator('[data-composer-input]').first()
  55. await input.waitFor({ timeout: 10_000 })
  56. // Arm the turn-boundary waiter BEFORE sending, so a burst replay cannot
  57. // miss the turn/end that settles the recorded turn.
  58. const settled = scaffold.whenTurnSettled()
  59. await input.fill(PROMPT)
  60. await input.press('Enter')
  61. const sessionId = await settled
  62. if (MODE === 'record') {
  63. await recordFixture(scaffold, sessionId, FIXTURE)
  64. }
  65. }, 60_000)
  66. it.skipIf(MODE === 'record')('records feedback and renders the acknowledgement with session and anonymous user ids', async () => {
  67. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-command'))
  68. // The drive test settled the recorded turn: the transcript is active (a
  69. // command row does not render while a fresh session is still blank) and
  70. // the replayed reply is on screen.
  71. await page.getByText('LIGHTHOUSE', { exact: true }).waitFor({ timeout: 15_000 })
  72. const input = page.locator('[data-composer-input]').first()
  73. await input.fill('/feedback the diff view is unreadable')
  74. await input.press('Enter')
  75. await page.getByText(/Feedback recorded for session/).waitFor({ timeout: 10_000 })
  76. expect(await page.getByText(/Anonymous user: [0-9a-f-]+\.$/i).count()).toBe(1)
  77. await expect.poll(() => input.textContent(), { timeout: 10_000 }).toBe('')
  78. await expect.poll(() => page.getByRole('button', { name: 'Add files or run commands' }).isEnabled(), { timeout: 10_000 }).toBe(true)
  79. const snapshot = await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd)
  80. await compareOrRefreshGolden(ACK_EXPECTED, snapshot, MODE)
  81. const expanded = await captureExpandedTurnProcessAria(
  82. page,
  83. '[class*="centerCol"]',
  84. scaffold.workspaceCwd,
  85. )
  86. await compareOrRefreshGolden(ACK_EXPANDED_EXPECTED, expanded, MODE)
  87. expect(tripwire.pageErrors).toEqual([])
  88. expect(tripwire.warnings).toEqual([])
  89. }, 60_000)
  90. it.skipIf(MODE === 'record')('keeps the fixture inventory closed', async () => {
  91. await assertFixtureInventory(SNAPSHOT_DIR, [
  92. 'session.v3.jsonl', 'ack.expected.md', 'ack-expanded.expected.md',
  93. ])
  94. })
  95. })