feedback-release.e2e.ts 6.9 KB

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