1
0

feedback-release.e2e.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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, 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.v2.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.v2.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. await settled
  89. }, 60_000)
  90. it.skipIf(MODE === 'record')('releases the session records through the feedback and pins the disclosure', async () => {
  91. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-release'))
  92. await page.getByText('LIGHTHOUSE', { exact: true }).waitFor({ timeout: 15_000 })
  93. expect(uploads).toEqual([])
  94. const input = page.locator('[data-composer-input]').first()
  95. await input.fill('/feedback the diff view is unreadable')
  96. await input.press('Enter')
  97. await page.getByText(/Feedback recorded for session/).waitFor({ timeout: 10_000 })
  98. expect(await page.getByText(/recording feedback uploads the session records not yet shared/).count()).toBe(1)
  99. // FEEDBACK_ONLY releases through the committed feedback event: exactly
  100. // one request reaches the collector, carrying the whole unshared range.
  101. await expect.poll(() => uploads.length, { timeout: 15_000 }).toBe(1)
  102. expect(uploads[0]).toContain('the diff view is unreadable')
  103. expect(uploads[0]).toContain(PROMPT)
  104. const snapshot = await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd)
  105. await compareOrRefreshGolden(ACK_EXPECTED, snapshot, MODE)
  106. const expanded = await captureExpandedTurnProcessAria(
  107. page,
  108. '[class*="centerCol"]',
  109. scaffold.workspaceCwd,
  110. )
  111. await compareOrRefreshGolden(ACK_EXPANDED_EXPECTED, expanded, MODE)
  112. expect(tripwire.pageErrors).toEqual([])
  113. expect(tripwire.warnings).toEqual([])
  114. }, 60_000)
  115. it.skipIf(MODE === 'record')('releases only the records since the last handoff on a second feedback', async () => {
  116. onTestFailed(() => saveFailureShot(page, 'web-e2e-feedback-release-suffix'))
  117. const input = page.locator('[data-composer-input]').first()
  118. await input.fill('/feedback the second remark')
  119. await input.press('Enter')
  120. await expect.poll(() => uploads.length, { timeout: 15_000 }).toBe(2)
  121. // Suffix semantics: the second release starts after the first feedback's
  122. // handoff, so the drive prompt already shared must not repeat.
  123. expect(uploads[1]).toContain('the second remark')
  124. expect(uploads[1]).not.toContain(PROMPT)
  125. }, 60_000)
  126. it.skipIf(MODE === 'record')('keeps the fixture inventory closed', async () => {
  127. await assertFixtureInventory(SNAPSHOT_DIR, ['ack.expected.md', 'ack-expanded.expected.md'])
  128. })
  129. })