1
0

message-feedback.e2e.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Keyless browser regression for durable per-message feedback. Cold-seeds a
  2. // settled two-turn transcript (zero model calls), likes one assistant message
  3. // and sees the acknowledgement, replaces the Like through the Dislike dialog
  4. // with a category and a note, proves the judgment survives a full page reload
  5. // from the Host's canonical log, then retracts it.
  6. import { readFile } from 'node:fs/promises'
  7. import { fileURLToPath } from 'node:url'
  8. import type { Browser, Page } from 'playwright'
  9. import { chromium } from 'playwright'
  10. import { SessionId } from '@deepseek-ai/dsh-session'
  11. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  12. import {
  13. acknowledgeReloadConnectionLoss, launchWebScaffold,
  14. seedSession, watchConsole, webSnapshotMode, type WebScaffold,
  15. } from './scaffold.ts'
  16. import { newEnglishPage, saveFailureShot } from './support.ts'
  17. // Borrowed read-only: this scenario needs any settled assistant message to
  18. // address, not a new recording (message-actions / sidebar-scrollbar pattern).
  19. const SEED = fileURLToPath(new URL('../../../snapshots/web/seeded-history/session.v3.jsonl', import.meta.url))
  20. const MODE = webSnapshotMode()
  21. const SEED_ID = 'message-feedback-web-e2e'
  22. const NOTE = 'Read both files before answering.'
  23. describe('web e2e: durable per-message feedback', () => {
  24. let scaffold: WebScaffold
  25. let browser: Browser
  26. let page: Page
  27. let tripwire: ReturnType<typeof watchConsole>
  28. beforeAll(async () => {
  29. scaffold = await launchWebScaffold({})
  30. await seedSession(scaffold, await readFile(SEED, 'utf8'), SEED_ID)
  31. browser = await chromium.launch()
  32. page = await newEnglishPage(browser)
  33. tripwire = watchConsole(page)
  34. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  35. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  36. }, 120_000)
  37. afterAll(async () => {
  38. await browser?.close()
  39. await scaffold?.close()
  40. })
  41. /**
  42. * Open the seeded transcript. The first treeitem is the collapsible group
  43. * row; the session itself is the row beneath it. The group is already
  44. * expanded on a fresh load, so clicking it unconditionally would collapse it
  45. * and hide the session row.
  46. */
  47. async function openSeededSession(): Promise<void> {
  48. const groupRow = page.locator('[role="treeitem"]').first()
  49. await groupRow.waitFor({ timeout: 15_000 })
  50. if (await groupRow.getAttribute('aria-expanded') !== 'true') await groupRow.click()
  51. const sessionRow = page.locator('[role="treeitem"]').nth(1)
  52. await sessionRow.waitFor({ timeout: 15_000 })
  53. await sessionRow.click()
  54. }
  55. it.skipIf(MODE === 'record')('persists a Dislike with its category and note across a reload, then retracts', async () => {
  56. onTestFailed(() => saveFailureShot(page, 'web-e2e-message-feedback'))
  57. await openSeededSession()
  58. // The controls live in the assistant message's IconActions row, which the
  59. // transcript reveals on hover/focus like copy and branch. Wait for the
  60. // settled closing text first: the strip mounts with that turn's tail.
  61. await page.getByText('DONE', { exact: true }).waitFor({ timeout: 30_000 })
  62. const like = page.getByRole('button', { name: 'Good response' }).first()
  63. await like.waitFor({ timeout: 30_000 })
  64. await like.scrollIntoViewIfNeeded()
  65. await like.hover()
  66. await like.click()
  67. // A Like records at once and is acknowledged; a recorded rating relabels
  68. // the button to what the next click would do.
  69. await page.getByRole('alert').filter({ hasText: 'Thanks for your feedback' }).waitFor({ timeout: 10_000 })
  70. const rated = page.getByRole('button', { name: 'Remove rating' }).first()
  71. await expect.poll(() => rated.getAttribute('aria-pressed'), { timeout: 10_000 }).toBe('true')
  72. // Dislike opens the Session's feedback dialog; its submission replaces
  73. // the Like with a negative judgment carrying the category and note.
  74. await page.getByRole('button', { name: 'Bad response' }).first().click()
  75. const dialog = page.getByRole('dialog', { name: 'Submit feedback' })
  76. await dialog.waitFor({ timeout: 10_000 })
  77. await expect.poll(() => dialog.getByRole('textbox', { name: 'Feedback details' }).getAttribute('placeholder'))
  78. .toBe('Add details to help us improve. Your submission will include the current conversation log.')
  79. await dialog.getByRole('button', { name: 'Task result', exact: true }).click()
  80. await dialog.getByRole('textbox', { name: 'Feedback details' }).fill(NOTE)
  81. await dialog.getByRole('button', { name: 'Submit', exact: true }).click()
  82. await expect.poll(() => dialog.count(), { timeout: 10_000 }).toBe(0)
  83. await expect.poll(() => rated.getAttribute('aria-label'), { timeout: 10_000 }).toBe('Remove rating')
  84. await expect.poll(() => like.getAttribute('aria-pressed'), { timeout: 10_000 }).toBe('false')
  85. // The durable assertion: a cold browser re-reads the sidecar over the wire.
  86. const warningStart = tripwire.warnings.length
  87. await page.reload({ waitUntil: 'load' })
  88. acknowledgeReloadConnectionLoss(tripwire, warningStart)
  89. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  90. await openSeededSession()
  91. await page.getByText('DONE', { exact: true }).waitFor({ timeout: 30_000 })
  92. // The controller defers its list read to the first hover or focus, so a
  93. // cold reload shows the unrated label until the strip is touched. Hovering
  94. // the unrated control is what triggers the authoritative re-read.
  95. const cold = page.getByRole('button', { name: 'Good response' }).first()
  96. await cold.waitFor({ timeout: 30_000 })
  97. await cold.scrollIntoViewIfNeeded()
  98. await cold.hover()
  99. const restored = page.getByRole('button', { name: 'Remove rating' }).first()
  100. await restored.waitFor({ timeout: 30_000 })
  101. await restored.scrollIntoViewIfNeeded()
  102. await restored.hover()
  103. await expect.poll(() => restored.getAttribute('aria-pressed'), { timeout: 15_000 }).toBe('true')
  104. // The retract label sits on the Dislike side: the Like stays unpressed.
  105. await expect.poll(() => cold.getAttribute('aria-pressed'), { timeout: 10_000 }).toBe('false')
  106. const agent = scaffold.ctx.agents.get(SessionId(SEED_ID))
  107. if (agent === undefined) throw new Error('seeded session did not attach an agent')
  108. const put = agent.session.snapshotEvents().filter(event => event.type === 'feedback/message-put').at(-1)
  109. expect(put?.type === 'feedback/message-put' ? put.data.item : undefined)
  110. .toMatchObject({ rating: 'negative', note: NOTE, category: 'task-result' })
  111. // Re-clicking the active rating retracts it, and the note goes with it.
  112. await restored.click()
  113. await expect.poll(
  114. () => page.getByRole('button', { name: 'Bad response' }).first().getAttribute('aria-pressed'),
  115. { timeout: 10_000 },
  116. ).toBe('false')
  117. const last = agent.session.snapshotEvents().at(-1)
  118. expect(last?.type).toBe('feedback/message-delete')
  119. }, 90_000)
  120. it.skipIf(MODE === 'record')('kept the console clean', () => {
  121. expect(tripwire.pageErrors).toEqual([])
  122. expect(tripwire.warnings).toEqual([])
  123. })
  124. })