feedback-release.e2e.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Keyless assembled-browser coverage for the shipped FEEDBACK_ONLY default
  2. // over the Web bundles and the real host wire. The scaffold mounts the
  3. // shipped telemetry row in FEEDBACK_ONLY mode against this suite's own
  4. // loopback mock collector, so the default release path is real: /feedback
  5. // releases the session records through that event (exactly one OTLP request,
  6. // carrying the drive prompt and the feedback text), the acknowledgement pins
  7. // the feedback-gated disclosure sentence, and a second feedback releases only
  8. // the records since the first handoff — the earlier prompt does not repeat.
  9. import { readFile } from 'node:fs/promises'
  10. import { fileURLToPath } from 'node:url'
  11. import { join } from 'node:path'
  12. import { createServer, type Server } from 'node:http'
  13. import { once } from 'node:events'
  14. import { gunzipSync } from 'node:zlib'
  15. import type { Browser, Page } from 'playwright'
  16. import { chromium } from 'playwright'
  17. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  18. import {
  19. assertFixtureInventory, captureStableAria, 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-release', import.meta.url))
  24. // The release path needs only a settled ordinary turn, so this lane replays
  25. // the feedback-command scenario's recorded session (declared as this
  26. // manifest's `session.source`) instead of recording a duplicate.
  27. const FIXTURE = fileURLToPath(new URL('../../../snapshots/web/feedback-command/session.jsonl', import.meta.url))
  28. const ACK_EXPECTED = join(SNAPSHOT_DIR, 'ack.expected.md')
  29. const MODE = webSnapshotMode()
  30. const PROMPT = 'Reply with the single word LIGHTHOUSE and stop.'
  31. describe('web e2e: feedback-gated release under the shipped default mode', () => {
  32. let scaffold: WebScaffold
  33. let browser: Browser
  34. let page: Page
  35. let tripwire: ReturnType<typeof watchConsole>
  36. let collector: Server
  37. const uploads: string[] = []
  38. beforeAll(async () => {
  39. collector = createServer((request, response) => {
  40. const chunks: Buffer[] = []
  41. request.on('data', chunk => chunks.push(chunk as Buffer))
  42. request.on('end', () => {
  43. const raw = Buffer.concat(chunks)
  44. uploads.push((request.headers['content-encoding'] === 'gzip' ? gunzipSync(raw) : raw).toString())
  45. response.writeHead(200, { 'content-type': 'application/json' }).end('{}')
  46. })
  47. })
  48. collector.listen(0, '127.0.0.1')
  49. await once(collector, 'listening')
  50. const address = collector.address()
  51. if (address === null || typeof address === 'string') throw new Error('collector has no port')
  52. scaffold = await launchWebScaffold({
  53. telemetryUrl: `http://127.0.0.1:${address.port}/v1/logs`,
  54. telemetryMode: 'FEEDBACK_ONLY',
  55. // The replayed session.jsonl belongs to the feedback-command scenario;
  56. // comparing (or refreshing) the persisted session here would rewrite
  57. // that shared source with this lane's feedback events. The release
  58. // evidence lives in this lane's golden and collector assertions.
  59. compareReplaySession: false,
  60. ...(MODE === 'record' ? {} : { replayFixture: FIXTURE }),
  61. })
  62. browser = await chromium.launch()
  63. page = await newEnglishPage(browser)
  64. tripwire = watchConsole(page)
  65. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  66. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  67. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  68. }, 120_000)
  69. afterAll(async () => {
  70. await browser?.close()
  71. await scaffold?.close()
  72. collector?.close()
  73. collector?.closeAllConnections()
  74. })
  75. it('drives the recorded prompt to a settled turn (all modes)', async () => {
  76. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-release-drive'))
  77. if (MODE !== 'record') {
  78. // Drift guard: the shared fixture must carry exactly the drive prompt.
  79. expect(fixtureUserPrompts(await readFile(FIXTURE, 'utf8'))).toEqual([PROMPT])
  80. }
  81. const input = page.locator('[data-composer-input]').first()
  82. await input.waitFor({ timeout: 10_000 })
  83. const settled = scaffold.whenTurnSettled()
  84. await input.fill(PROMPT)
  85. await input.press('Enter')
  86. const sessionId = await settled
  87. if (MODE === 'record') {
  88. // Re-records the SHARED feedback-command session this lane replays.
  89. await recordFixture(scaffold, sessionId, FIXTURE)
  90. }
  91. }, 60_000)
  92. it.skipIf(MODE === 'record')('releases the session records through the feedback and pins the disclosure', async () => {
  93. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-release'))
  94. await page.getByText('LIGHTHOUSE', { exact: true }).waitFor({ timeout: 15_000 })
  95. expect(uploads).toEqual([])
  96. const input = page.locator('[data-composer-input]').first()
  97. await input.fill('/feedback the diff view is unreadable')
  98. await input.press('Enter')
  99. await page.getByText(/Feedback recorded for session/).waitFor({ timeout: 10_000 })
  100. expect(await page.getByText(/recording feedback uploads the session records not yet shared/).count()).toBe(1)
  101. // FEEDBACK_ONLY releases through the committed feedback event: exactly
  102. // one request reaches the collector, carrying the whole unshared range.
  103. await expect.poll(() => uploads.length, { timeout: 15_000 }).toBe(1)
  104. expect(uploads[0]).toContain('the diff view is unreadable')
  105. expect(uploads[0]).toContain(PROMPT)
  106. const snapshot = await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd)
  107. await compareOrRefreshGolden(ACK_EXPECTED, snapshot, MODE)
  108. expect(tripwire.pageErrors).toEqual([])
  109. expect(tripwire.warnings).toEqual([])
  110. }, 60_000)
  111. it.skipIf(MODE === 'record')('releases only the records since the last handoff on a second feedback', async () => {
  112. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-release-suffix'))
  113. const input = page.locator('[data-composer-input]').first()
  114. await input.fill('/feedback the second remark')
  115. await input.press('Enter')
  116. await expect.poll(() => uploads.length, { timeout: 15_000 }).toBe(2)
  117. // Suffix semantics: the second release starts after the first feedback's
  118. // handoff, so the drive prompt already shared must not repeat.
  119. expect(uploads[1]).toContain('the second remark')
  120. expect(uploads[1]).not.toContain(PROMPT)
  121. }, 60_000)
  122. it.skipIf(MODE === 'record')('keeps the fixture inventory closed', async () => {
  123. await assertFixtureInventory(SNAPSHOT_DIR, ['ack.expected.md'])
  124. })
  125. })