message-actions.e2e.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Web e2e scenario: message IconActions + clocks. Cold-seeds the seeded-history
  2. // fixture (zero model calls) and pins the settled conversation aria after the
  3. // user/assistant footers are focus-revealed — the surface package jsdom tests
  4. // cannot substitute for (docs/testing.md snapshot rule).
  5. import { mkdir, readFile, writeFile } from 'node:fs/promises'
  6. import { join } from 'node:path'
  7. import { fileURLToPath } from 'node:url'
  8. import type { Browser, Page } from 'playwright'
  9. import { chromium } from 'playwright'
  10. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  11. import { SessionId } from '@deepseek-ai/dsh-session'
  12. import {
  13. assertFixtureInventory, captureStableAria, compareOrRefreshGolden, fixtureUserPrompts,
  14. launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold,
  15. } from './scaffold.ts'
  16. import { newEnglishPage, saveFailureShot } from './support.ts'
  17. const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/message-actions', import.meta.url))
  18. // Borrowed read-only: this scenario needs any settled user+assistant pair, not
  19. // a new recording (workspace-management / sidebar-scrollbar pattern).
  20. const SEED = fileURLToPath(new URL('./snapshots/seeded-history/seed.jsonl', import.meta.url))
  21. const UI_EXPECTED = join(SNAPSHOT_DIR, 'ui.expected.md')
  22. const FORK_EXPECTED = join(SNAPSHOT_DIR, 'fork.expected.md')
  23. const MODE = webSnapshotMode()
  24. const SEED_ID = 'message-actions-web-e2e'
  25. const PROMPT = 'Use the read tool twice in one assistant message: read a.txt and b.txt. Then reply with the single word DONE and stop.'
  26. describe('web e2e: message IconActions and clocks on settled history', () => {
  27. let scaffold: WebScaffold
  28. let browser: Browser
  29. let page: Page
  30. let tripwire: ReturnType<typeof watchConsole>
  31. beforeAll(async () => {
  32. scaffold = await launchWebScaffold({})
  33. const sessionCwd = join(scaffold.workspaceCwd, 'workspace')
  34. await mkdir(sessionCwd, { recursive: true })
  35. await writeFile(join(sessionCwd, 'a.txt'), 'alpha\n')
  36. await writeFile(join(sessionCwd, 'b.txt'), 'beta\n')
  37. const raw = await readFile(SEED, 'utf8')
  38. expect(fixtureUserPrompts(raw), 'borrowed seed must carry the drive prompt').toEqual([PROMPT])
  39. await seedSession(scaffold, raw, SEED_ID)
  40. browser = await chromium.launch()
  41. page = await newEnglishPage(browser)
  42. tripwire = watchConsole(page)
  43. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  44. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  45. }, 120_000)
  46. afterAll(async () => {
  47. await browser?.close()
  48. await scaffold?.close()
  49. })
  50. it.skipIf(MODE === 'record')('lists the seeded session and reveals user/assistant IconActions', async () => {
  51. onTestFailed(() => saveFailureShot(page, 'web-e2e-message-actions'))
  52. const groupRow = page.locator('[role="treeitem"]').first()
  53. await groupRow.waitFor({ timeout: 15_000 })
  54. await groupRow.click()
  55. const sessionRow = page.locator('[role="treeitem"]').nth(1)
  56. await sessionRow.waitFor({ timeout: 10_000 })
  57. await sessionRow.click()
  58. await expect.poll(() => page.getByText('DONE', { exact: true }).count(), { timeout: 15_000 }).toBe(1)
  59. // Focus-reveal the footers (hover:hover keeps them opacity-hidden until
  60. // hover/focus-within). User and each turn's last content assistant both
  61. // have copy + branch.
  62. const copyButtons = page.getByRole('button', { name: 'Copy' })
  63. await expect.poll(() => copyButtons.count(), { timeout: 10_000 }).toBeGreaterThanOrEqual(2)
  64. await copyButtons.first().focus()
  65. await expect.poll(() => page.getByRole('button', { name: 'Branch into a new conversation' }).count(), { timeout: 5_000 })
  66. .toBeGreaterThanOrEqual(2)
  67. await expect.poll(() => page.getByRole('button', { name: 'Edit' }).count(), { timeout: 5_000 }).toBe(0)
  68. }, 60_000)
  69. it.skipIf(MODE === 'record')('matches the conversation aria golden with IconActions and clocks', async () => {
  70. onTestFailed(() => saveFailureShot(page, 'web-e2e-message-actions-aria'))
  71. await page.getByRole('button', {
  72. name: 'Select model, current deepseek-v4-flash',
  73. }).waitFor({ timeout: 10_000 })
  74. // Keep a footer focused so opacity-hidden actions stay in the a11y tree
  75. // as an active/focused control during the capture.
  76. await page.getByRole('button', { name: 'Copy' }).first().focus()
  77. const snapshot = (await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd))
  78. .split(SEED_ID).join('{{seededId}}')
  79. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  80. })
  81. it.skipIf(MODE === 'record')('forks through the settled-message and session-row actions', async () => {
  82. onTestFailed(() => saveFailureShot(page, 'web-e2e-message-fork'))
  83. // Exercise the assistant action specifically; package coverage pins the
  84. // user action separately at its own event seq.
  85. await page.getByRole('button', { name: 'Branch into a new conversation' }).last().click()
  86. await expect.poll(
  87. () => scaffold.ctx.agents.list().find(agent => agent.session.header.parentSession === SessionId(SEED_ID)),
  88. { timeout: 15_000 },
  89. ).toBeDefined()
  90. await expect.poll(
  91. () => page.locator('[role="treeitem"]').count(),
  92. { timeout: 10_000 },
  93. ).toBe(3)
  94. await expect.poll(
  95. () => page.locator('[role="treeitem"][aria-selected="true"]').count(),
  96. { timeout: 10_000 },
  97. ).toBe(1)
  98. // The row action owns a distinct ui-workspace injection from the message
  99. // action above, so exercise both through the loaded app before capture.
  100. const sourceRow = page.locator('[role="treeitem"][aria-selected="true"]')
  101. const rowBox = await sourceRow.boundingBox()
  102. if (rowBox === null) throw new Error('fork source row has no layout box')
  103. const actionButton = sourceRow.locator('button[aria-label^="Session actions for "]')
  104. await sourceRow.hover({ position: { x: rowBox.width - 16, y: rowBox.height / 2 } })
  105. await expect.poll(() => actionButton.isVisible(), { timeout: 2_000 }).toBe(true)
  106. const buttonBox = await actionButton.boundingBox()
  107. if (buttonBox === null) throw new Error('fork source row action has no layout box')
  108. await page.mouse.click(buttonBox.x + buttonBox.width / 2, buttonBox.y + buttonBox.height / 2)
  109. await page.getByRole('menuitem', { name: 'Fork session' }).click()
  110. await expect.poll(
  111. () => scaffold.ctx.agents.list().filter(agent => agent.session.header.parentSession !== undefined).length,
  112. { timeout: 15_000 },
  113. ).toBe(2)
  114. await expect.poll(
  115. () => page.locator('[role="treeitem"]').count(),
  116. { timeout: 10_000 },
  117. ).toBe(4)
  118. await expect.poll(
  119. () => page.locator('[role="treeitem"][aria-selected="true"]').count(),
  120. { timeout: 10_000 },
  121. ).toBe(1)
  122. const tree = await captureStableAria(
  123. page,
  124. '[role="tree"][aria-label="Sessions"]',
  125. scaffold.workspaceCwd,
  126. )
  127. await compareOrRefreshGolden(FORK_EXPECTED, tree, MODE)
  128. })
  129. it.skipIf(MODE === 'record')('issued zero model calls and kept a closed inventory', async () => {
  130. expect(tripwire.pageErrors).toEqual([])
  131. expect(tripwire.warnings).toEqual([])
  132. await assertFixtureInventory(SNAPSHOT_DIR, ['fork.expected.md', 'ui.expected.md'])
  133. })
  134. })