feedback-command.e2e.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 — the recorded session id plus the session-sharing
  6. // disclosure — as a persistent command row. The scaffold mounts the shipped
  7. // telemetry row in FULL mode against a local dead endpoint (no record leaves
  8. // the process), so the golden pins the shipped default sentence
  9. // `Session sharing is enabled.`; the per-status sentences are pinned by the
  10. // package and OTel unit tests.
  11. import { readFile } from 'node:fs/promises'
  12. import { fileURLToPath } from 'node:url'
  13. import { join } from 'node:path'
  14. import type { Browser, Page } from 'playwright'
  15. import { chromium } from 'playwright'
  16. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  17. import {
  18. assertFixtureInventory, captureExpandedTurnProcessAria, captureStableAria,
  19. compareOrRefreshGolden, fixtureUserPrompts,
  20. launchWebScaffold, recordFixture, watchConsole, webSnapshotMode, type WebScaffold,
  21. } from './scaffold.ts'
  22. import { connectFreshWorkspace, newEnglishPage, saveFailureShot } from './support.ts'
  23. const SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/feedback-command', import.meta.url))
  24. const FIXTURE = join(SNAPSHOT_DIR, 'session.v2.jsonl')
  25. const ACK_EXPECTED = join(SNAPSHOT_DIR, 'ack.expected.md')
  26. const ACK_EXPANDED_EXPECTED = join(SNAPSHOT_DIR, 'ack-expanded.expected.md')
  27. const MODE = webSnapshotMode()
  28. // Discard port: loopback listener never binds, so FULL telemetry discloses
  29. // the shipped default policy without any record reaching a collector.
  30. const TELEMETRY_URL = 'http://127.0.0.1:9/v1/logs'
  31. const PROMPT = 'Reply with the single word LIGHTHOUSE and stop.'
  32. describe('web e2e: /feedback command acknowledgement', () => {
  33. let scaffold: WebScaffold
  34. let browser: Browser
  35. let page: Page
  36. let tripwire: ReturnType<typeof watchConsole>
  37. beforeAll(async () => {
  38. scaffold = await launchWebScaffold({
  39. telemetryUrl: TELEMETRY_URL,
  40. compareReplaySession: true,
  41. ...(MODE === 'record' ? {} : { replayFixture: FIXTURE, paceMs: 5 }),
  42. })
  43. browser = await chromium.launch()
  44. page = await newEnglishPage(browser)
  45. tripwire = watchConsole(page)
  46. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  47. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  48. // Fresh world: connecting a workspace births the blank session whose
  49. // live composer accepts the slash line.
  50. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  51. }, 120_000)
  52. afterAll(async () => {
  53. await browser?.close()
  54. await scaffold?.close()
  55. })
  56. it('drives the recorded prompt to a settled turn (all modes)', async () => {
  57. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-drive'))
  58. if (MODE !== 'record') {
  59. // Drift guard: the committed fixture must carry exactly the drive prompt.
  60. expect(fixtureUserPrompts(await readFile(FIXTURE, 'utf8'))).toEqual([PROMPT])
  61. }
  62. const input = page.locator('[data-composer-input]').first()
  63. await input.waitFor({ timeout: 10_000 })
  64. // Arm the turn-boundary waiter BEFORE sending, so a burst replay cannot
  65. // miss the turn/end that settles the recorded turn.
  66. const settled = scaffold.whenTurnSettled()
  67. await input.fill(PROMPT)
  68. await input.press('Enter')
  69. const sessionId = await settled
  70. if (MODE === 'record') {
  71. await recordFixture(scaffold, sessionId, FIXTURE)
  72. }
  73. }, 60_000)
  74. it.skipIf(MODE === 'record')('records feedback and renders the acknowledgement with session id and sharing status', async () => {
  75. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-command'))
  76. // The drive test settled the recorded turn: the transcript is active (a
  77. // command row does not render while a fresh session is still blank) and
  78. // the replayed reply is on screen.
  79. await page.getByText('LIGHTHOUSE', { exact: true }).waitFor({ timeout: 15_000 })
  80. const input = page.locator('[data-composer-input]').first()
  81. await input.fill('/feedback the diff view is unreadable')
  82. await input.press('Enter')
  83. // The command plane settles without a model turn: the ack row names the
  84. // recorded session and the mounted FULL backend's disclosure.
  85. await page.getByText(/Feedback recorded for session/).waitFor({ timeout: 10_000 })
  86. expect(await page.getByText(/Session sharing is enabled/).count()).toBe(1)
  87. const snapshot = await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd)
  88. await compareOrRefreshGolden(ACK_EXPECTED, snapshot, MODE)
  89. const expanded = await captureExpandedTurnProcessAria(
  90. page,
  91. '[class*="centerCol"]',
  92. scaffold.workspaceCwd,
  93. )
  94. await compareOrRefreshGolden(ACK_EXPANDED_EXPECTED, expanded, MODE)
  95. expect(tripwire.pageErrors).toEqual([])
  96. expect(tripwire.warnings).toEqual([])
  97. }, 60_000)
  98. it.skipIf(MODE === 'record')('keeps the fixture inventory closed', async () => {
  99. await assertFixtureInventory(SNAPSHOT_DIR, [
  100. 'session.v2.jsonl', 'ack.expected.md', 'ack-expanded.expected.md',
  101. ])
  102. })
  103. })