workflow-run.e2e.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // Keyless shipped-Web acceptance for the durable workflow Conversation Node.
  2. // Reuses the existing recorded workflow parent/child model fixtures; the real
  3. // workflow tool, worker, subagent provider, Session log, browser plugin graph,
  4. // and navigation all execute during replay.
  5. import { readFile } 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 type { Session, SessionEvent, SessionId } from '@deepseek-ai/dsh-session'
  12. import {
  13. assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
  14. fixtureUserPrompts, launchWebScaffold, watchConsole, webSnapshotMode,
  15. type WebScaffold,
  16. } from './scaffold.ts'
  17. import {
  18. connectFreshWorkspace, newEnglishPage, REPO_ROOT, saveFailureShot,
  19. } from './support.ts'
  20. const MODE = webSnapshotMode()
  21. const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/workflow-run', import.meta.url))
  22. const UI_EXPECTED = join(SNAPSHOT_DIR, 'ui.expected.md')
  23. const PARENT_FIXTURE = join(REPO_ROOT, 'examples/acp-agent/tests/snapshots/workflow-run/session.jsonl')
  24. const CHILD_FIXTURE = join(REPO_ROOT, 'examples/acp-agent/tests/snapshots/workflow-run/session.1.jsonl')
  25. const CHILD_PROMPT = 'Reply with exactly the word WF_CHILD_OK and nothing else.'
  26. describe.skipIf(MODE === 'record')('web e2e: durable workflow run in Chat', () => {
  27. let scaffold: WebScaffold
  28. let browser: Browser
  29. let page: Page
  30. let tripwire: ReturnType<typeof watchConsole>
  31. let prompt: string
  32. const waitForParentSettlement = (): Promise<SessionId> => new Promise((resolve, reject) => {
  33. let dispose = (): void => {}
  34. dispose = scaffold.ctx.on('session/event', (session: Session, event: SessionEvent) => {
  35. if (event.type !== 'turn/end' || session.header.origin === 'subagent') return
  36. dispose()
  37. void (async () => {
  38. await scaffold.ctx.agents.get(session.id)?.whenIdle()
  39. await scaffold.ctx.sessions.flush(session)
  40. resolve(session.id)
  41. })().catch(reject)
  42. })
  43. })
  44. beforeAll(async () => {
  45. const prompts = fixtureUserPrompts(await readFile(PARENT_FIXTURE, 'utf8'))
  46. expect(prompts).toHaveLength(1)
  47. prompt = prompts[0]!
  48. scaffold = await launchWebScaffold({
  49. replayFixture: PARENT_FIXTURE,
  50. replayChildFixtures: [CHILD_FIXTURE],
  51. paceMs: 25,
  52. })
  53. browser = await chromium.launch()
  54. page = await newEnglishPage(browser)
  55. tripwire = watchConsole(page)
  56. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  57. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  58. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  59. }, 120_000)
  60. afterAll(async () => {
  61. await browser?.close()
  62. await scaffold?.close()
  63. })
  64. it('shows the live member, opens its local child, then retains the settled record beside the tool row', async () => {
  65. onTestFailed(() => saveFailureShot(page, 'web-e2e-workflow-run-live'))
  66. const settled = waitForParentSettlement()
  67. const input = page.locator('textarea').first()
  68. await input.fill(prompt)
  69. await input.press('Enter')
  70. const workflow = page.getByRole('button', { name: /^snapshot-flow/ })
  71. await workflow.waitFor({ timeout: 30_000 })
  72. expect(await workflow.getAttribute('aria-expanded')).toBe('true')
  73. const phase = page.getByRole('button', { name: /^Run/ })
  74. await phase.waitFor({ timeout: 15_000 })
  75. await phase.click()
  76. const member = page.getByRole('button', { name: /^Open Reply with exactly the word/ })
  77. await member.waitFor({ timeout: 15_000 })
  78. await member.focus()
  79. const lightColor = await member.locator('[data-member-label]').evaluate(element => getComputedStyle(element).color)
  80. await page.setViewportSize({ width: 560, height: 800 })
  81. await page.evaluate(() => { document.body.setAttribute('data-ds-dark-theme', '') })
  82. const darkNarrow = await page.locator('[data-workflow-run]').evaluate((element) => {
  83. const panel = element as HTMLElement
  84. panel.style.width = '356px'
  85. const label = element.querySelector('[data-member-label]')
  86. const labelWrap = element.querySelector('[data-member-label-wrap]')
  87. const status = element.querySelector('[data-member-status-text]')
  88. const disclosures = element.querySelectorAll('[data-disclosure-row]')
  89. const runHeader = disclosures[0]
  90. const phaseHeader = disclosures[1]
  91. const phaseTitle = phaseHeader?.children.item(1) as HTMLElement | null
  92. const phaseStatus = element.querySelector('[data-phase-status-text]')
  93. const originalPhaseTitle = phaseTitle?.textContent ?? ''
  94. if (phaseTitle !== null) phaseTitle.textContent = 'A phase name long enough to require ellipsis in the narrow layout'
  95. const phaseTitleRight = phaseTitle?.getBoundingClientRect().right ?? 0
  96. const phaseStatusLeft = phaseStatus?.getBoundingClientRect().left ?? 0
  97. if (phaseTitle !== null) phaseTitle.textContent = originalPhaseTitle
  98. return {
  99. clientWidth: element.clientWidth,
  100. scrollWidth: element.scrollWidth,
  101. color: label === null ? '' : getComputedStyle(label).color,
  102. decoration: label === null ? '' : getComputedStyle(label).textDecorationLine,
  103. focusWidth: labelWrap === null ? '' : getComputedStyle(labelWrap).outlineWidth,
  104. statusWidth: status?.getBoundingClientRect().width ?? 0,
  105. statusFontSize: status === null ? '' : getComputedStyle(status).fontSize,
  106. runHeight: runHeader?.getBoundingClientRect().height ?? 0,
  107. phaseHeight: phaseHeader?.getBoundingClientRect().height ?? 0,
  108. phaseTitleRight,
  109. phaseStatusLeft,
  110. }
  111. })
  112. expect(darkNarrow.clientWidth).toBe(356)
  113. expect(darkNarrow.scrollWidth).toBeLessThanOrEqual(darkNarrow.clientWidth)
  114. expect(darkNarrow.color).not.toBe(lightColor)
  115. expect(darkNarrow.decoration).toContain('underline')
  116. expect(Number.parseFloat(darkNarrow.focusWidth)).toBeGreaterThanOrEqual(2)
  117. expect(darkNarrow.statusWidth).toBe(64)
  118. expect(darkNarrow.statusFontSize).toBe('13px')
  119. expect(darkNarrow.runHeight).toBe(32)
  120. expect(darkNarrow.phaseHeight).toBe(32)
  121. expect(darkNarrow.phaseTitleRight).toBeLessThanOrEqual(darkNarrow.phaseStatusLeft)
  122. await page.locator('[data-workflow-run]').evaluate((element) => {
  123. (element as HTMLElement).style.removeProperty('width')
  124. document.body.removeAttribute('data-ds-dark-theme')
  125. })
  126. await page.setViewportSize({ width: 1280, height: 800 })
  127. await member.click()
  128. await page.getByText(CHILD_PROMPT, { exact: true }).waitFor({ timeout: 15_000 })
  129. const sessions = page.getByRole('tree', { name: 'Sessions' })
  130. await sessions.getByRole('treeitem', { name: /Use the workflow tool exactly/ }).click()
  131. await settled
  132. expect(await page.locator('[data-chat-flow-kind="tool-call"]').count()).toBeGreaterThanOrEqual(1)
  133. expect(await page.locator('[data-chat-flow-kind="workflow-run"]').count()).toBe(1)
  134. const terminalWorkflow = page.getByRole('button', { name: /^snapshot-flow/ })
  135. await terminalWorkflow.waitFor()
  136. if (await terminalWorkflow.getAttribute('aria-expanded') !== 'true') await terminalWorkflow.click()
  137. const terminalPhase = page.getByRole('button', { name: /^Run/ })
  138. await terminalPhase.waitFor()
  139. if (await terminalPhase.getAttribute('aria-expanded') !== 'true') await terminalPhase.click()
  140. await page.getByText(CHILD_PROMPT, { exact: false }).waitFor()
  141. await expect.poll(
  142. () => page.getByRole('button', { name: /^Open Reply with exactly the word/ }).count(),
  143. { timeout: 10_000 },
  144. ).toBe(0)
  145. }, 90_000)
  146. it('rebuilds the terminal record from history after reload', async () => {
  147. onTestFailed(() => saveFailureShot(page, 'web-e2e-workflow-run-history'))
  148. await page.reload({ waitUntil: 'load' })
  149. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  150. const workflow = page.getByRole('button', { name: /^snapshot-flow/ })
  151. await workflow.waitFor({ timeout: 15_000 })
  152. expect(await workflow.getAttribute('aria-expanded')).toBe('false')
  153. await workflow.click()
  154. const phase = page.getByRole('button', { name: /^Run/ })
  155. await phase.waitFor()
  156. await phase.click()
  157. await page.getByText(CHILD_PROMPT, { exact: false }).waitFor()
  158. expect(await page.getByRole('button', { name: /^Open Reply with exactly the word/ }).count()).toBe(0)
  159. const snapshot = await captureStableAria(page, '[data-chat-flow]', scaffold.workspaceCwd)
  160. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  161. }, 60_000)
  162. it('stays clean and owns only its one golden', async () => {
  163. expect(tripwire.pageErrors).toEqual([])
  164. expect(tripwire.warnings).toEqual([])
  165. await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
  166. })
  167. })