feedback-command.e2e.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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, captureStableAria, compareOrRefreshGolden, fixtureUserPrompts,
  19. launchWebScaffold, recordFixture, watchConsole, webSnapshotMode, type WebScaffold,
  20. } from './scaffold.ts'
  21. import { connectFreshWorkspace, newEnglishPage, saveFailureShot } from './support.ts'
  22. const SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/feedback-command', import.meta.url))
  23. const FIXTURE = join(SNAPSHOT_DIR, 'session.jsonl')
  24. const ACK_EXPECTED = join(SNAPSHOT_DIR, 'ack.expected.md')
  25. const MODE = webSnapshotMode()
  26. // Discard port: loopback listener never binds, so FULL telemetry discloses
  27. // the shipped default policy without any record reaching a collector.
  28. const TELEMETRY_URL = 'http://127.0.0.1:9/v1/logs'
  29. const PROMPT = 'Reply with the single word LIGHTHOUSE and stop.'
  30. describe('web e2e: /feedback command acknowledgement', () => {
  31. let scaffold: WebScaffold
  32. let browser: Browser
  33. let page: Page
  34. let tripwire: ReturnType<typeof watchConsole>
  35. beforeAll(async () => {
  36. scaffold = await launchWebScaffold({
  37. telemetryUrl: TELEMETRY_URL,
  38. compareReplaySession: true,
  39. ...(MODE === 'record' ? {} : { replayFixture: FIXTURE }),
  40. })
  41. browser = await chromium.launch()
  42. page = await newEnglishPage(browser)
  43. tripwire = watchConsole(page)
  44. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  45. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  46. // Fresh world: connecting a workspace births the blank session whose
  47. // live composer accepts the slash line.
  48. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  49. }, 120_000)
  50. afterAll(async () => {
  51. await browser?.close()
  52. await scaffold?.close()
  53. })
  54. it('drives the recorded prompt to a settled turn (all modes)', async () => {
  55. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-drive'))
  56. if (MODE !== 'record') {
  57. // Drift guard: the committed fixture must carry exactly the drive prompt.
  58. expect(fixtureUserPrompts(await readFile(FIXTURE, 'utf8'))).toEqual([PROMPT])
  59. }
  60. const input = page.locator('textarea').first()
  61. await input.waitFor({ timeout: 10_000 })
  62. // Arm the turn-boundary waiter BEFORE sending, so a burst replay cannot
  63. // miss the turn/end that settles the recorded turn.
  64. const settled = scaffold.whenTurnSettled()
  65. await input.fill(PROMPT)
  66. await input.press('Enter')
  67. const sessionId = await settled
  68. if (MODE === 'record') {
  69. await recordFixture(scaffold, sessionId, FIXTURE)
  70. }
  71. }, 60_000)
  72. it.skipIf(MODE === 'record')('records feedback and renders the acknowledgement with session id and sharing status', async () => {
  73. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-command'))
  74. // The drive test settled the recorded turn: the transcript is active (a
  75. // command row does not render while a fresh session is still blank) and
  76. // the replayed reply is on screen.
  77. await page.getByText('LIGHTHOUSE', { exact: true }).waitFor({ timeout: 15_000 })
  78. const input = page.locator('textarea').first()
  79. await input.fill('/feedback the diff view is unreadable')
  80. await input.press('Enter')
  81. // The command plane settles without a model turn: the ack row names the
  82. // recorded session and the mounted FULL backend's disclosure.
  83. await page.getByText(/Feedback recorded for session/).waitFor({ timeout: 10_000 })
  84. expect(await page.getByText(/Session sharing is enabled/).count()).toBe(1)
  85. const snapshot = await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd)
  86. await compareOrRefreshGolden(ACK_EXPECTED, snapshot, 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, ['session.jsonl', 'ack.expected.md'])
  92. })
  93. })