seeded-history.e2e.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // Web e2e scenario: seeded history. A recorded session seeded cold through
  2. // the REAL persistence API renders purely from the log — the surface nothing
  3. // else covers: sidebar cold listing, the implicit resume/attach inside the
  4. // history RPC, history-page tool views, and the client fold of historical
  5. // events — with ZERO model calls in replay (no replay fixture; a stray stream
  6. // fails loud on the open llm seam). The seed is a recorded fixture under the
  7. // same record discipline as every other: DSH_SNAPSHOT=record drives the turn
  8. // live through the composer (real read tool against seeded workspace files)
  9. // and harvests seed.jsonl; replay/refresh seed it cold and only render.
  10. import { readFile, writeFile, mkdir } from 'node:fs/promises'
  11. import { fileURLToPath } from 'node:url'
  12. import type { Browser, Page } from 'playwright'
  13. import { chromium } from 'playwright'
  14. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  15. import { join } from 'node:path'
  16. import {
  17. assertFixtureInventory, captureStableAria, compareOrRefreshGolden, fixtureUserPrompts,
  18. launchWebScaffold, recordFixture, seedSession, watchConsole, webSnapshotMode, type WebScaffold,
  19. } from './scaffold.ts'
  20. import { saveFailureShot } from './support.ts'
  21. const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/seeded-history', import.meta.url))
  22. const SEED = fileURLToPath(new URL('./snapshots/seeded-history/seed.jsonl', import.meta.url))
  23. const UI_EXPECTED = fileURLToPath(new URL('./snapshots/seeded-history/ui.expected.md', import.meta.url))
  24. const MODE = webSnapshotMode()
  25. const SEED_ID = 'seeded-history-web-e2e'
  26. 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.'
  27. describe('web e2e: seeded history renders through cold resume', () => {
  28. let scaffold: WebScaffold
  29. let browser: Browser
  30. let page: Page
  31. let tripwire: ReturnType<typeof watchConsole>
  32. beforeAll(async () => {
  33. scaffold = await launchWebScaffold({})
  34. // The workspace-aware flow runs sessions in <workspaceRoot>/workspace
  35. // (the composer's default draft name); the read-tool targets must live in
  36. // that session cwd. Pre-creating the directory is safe: create-by-name
  37. // adopts an existing directory.
  38. const sessionCwd = join(scaffold.workspaceCwd, 'workspace')
  39. await mkdir(sessionCwd, { recursive: true })
  40. await writeFile(join(sessionCwd, 'a.txt'), 'alpha\n')
  41. await writeFile(join(sessionCwd, 'b.txt'), 'beta\n')
  42. if (MODE !== 'record') {
  43. const raw = await readFile(SEED, 'utf8')
  44. expect(fixtureUserPrompts(raw), 'seed fixture must carry exactly the drive prompt').toEqual([PROMPT])
  45. await seedSession(scaffold, raw, SEED_ID)
  46. }
  47. browser = await chromium.launch()
  48. page = await browser.newPage({ viewport: { width: 1680, height: 1000 } })
  49. tripwire = watchConsole(page)
  50. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  51. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  52. }, 120_000)
  53. afterAll(async () => {
  54. await browser?.close()
  55. await scaffold?.close()
  56. })
  57. it.skipIf(MODE !== 'record')('records the seed turn live through the composer', async () => {
  58. onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-record'))
  59. const input = page.locator('textarea').first()
  60. await input.waitFor({ timeout: 10_000 })
  61. const settled = scaffold.whenTurnSettled()
  62. await input.fill(PROMPT)
  63. await input.press('Enter')
  64. const sessionId = await settled
  65. await recordFixture(scaffold, sessionId, SEED)
  66. }, 200_000)
  67. it.skipIf(MODE === 'record')('serves the projections baseline on the real composition tail page', async () => {
  68. // Composition regression tripwire: the projection registry must be a row
  69. // in the SHIPPED cordis.yml — with it absent every domain unit's optional
  70. // injection stays silent and this block disappears (no titles/todos on
  71. // the web), while fixture-level suites stay green. Assert through the
  72. // real HTTP wire against the booted real host.
  73. const response = await fetch(`${scaffold.baseUrl}/api/session.history`, {
  74. method: 'POST',
  75. headers: { 'content-type': 'application/json' },
  76. body: JSON.stringify({
  77. type: 'client-request', rpcId: 'seeded-projections', method: 'session.history',
  78. payload: { sessionId: SEED_ID },
  79. }),
  80. })
  81. expect(response.ok).toBe(true)
  82. const body = await response.json() as {
  83. result: { ok: boolean; value?: { projections?: { asOfSeq: number; values: Record<string, unknown> } } }
  84. }
  85. expect(body.result.ok).toBe(true)
  86. const projections = body.result.value?.projections
  87. expect(projections).toBeDefined()
  88. expect(projections?.asOfSeq).toBeGreaterThanOrEqual(0)
  89. // The seed carries a session/title event: the title unit must serve it.
  90. expect(typeof projections?.values.title).toBe('string')
  91. // tool-todo is composed but the seed has no todo/write: whole-value null,
  92. // key PRESENT (absence would mean the unit never registered).
  93. expect(projections?.values).toHaveProperty('todos', null)
  94. })
  95. it.skipIf(MODE === 'record')('lists the seeded session cold and renders its history from the log', async () => {
  96. onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-history'))
  97. // The sidebar tree collapses workspace groups by default: click the group
  98. // row (treeitem 0) to expand, then the revealed session row.
  99. const groupRow = page.locator('[role="treeitem"]').first()
  100. await groupRow.waitFor({ timeout: 15_000 })
  101. await groupRow.click()
  102. const sessionRow = page.locator('[role="treeitem"]').nth(1)
  103. await sessionRow.waitFor({ timeout: 10_000 })
  104. await sessionRow.click()
  105. // Settled barrier for history: the recorded final assistant text renders.
  106. await expect.poll(() => page.getByText('DONE', { exact: true }).count(), { timeout: 15_000 }).toBe(1)
  107. // Tool cards render from logged tool/call + tool/result alone (views are
  108. // host-recomputed per page; the generic card is the documented default).
  109. const toolRows = page.locator('[data-variant], [data-sample]')
  110. await expect.poll(() => toolRows.count(), { timeout: 10_000 }).toBeGreaterThanOrEqual(2)
  111. expect(await page.getByText('a.txt', { exact: false }).count()).toBeGreaterThan(0)
  112. }, 60_000)
  113. it.skipIf(MODE === 'record')('matches the historical conversation aria golden', async () => {
  114. onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-aria'))
  115. await page.getByRole('button', {
  116. // This scenario deliberately leaves the LLM seam open to prove zero
  117. // model calls. History still restores the selected id, but no catalog
  118. // adapter exists to provide its presentation name.
  119. name: '选择模型,当前 deepseek-v4-flash',
  120. }).waitFor({ timeout: 10_000 })
  121. const snapshot = (await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd))
  122. .split(SEED_ID).join('{{seededId}}')
  123. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  124. })
  125. it.skipIf(MODE === 'record')('file-path tool rows rebuilt from the cold log stay details-inert', async () => {
  126. onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-toolrow'))
  127. // Interaction over cold-resumed history: read summaries are host-open
  128. // file links (not expand-in-place / not details). Runs after the golden
  129. // capture; still zero model calls.
  130. const fileLink = page.locator('[data-variant="read"] button').first()
  131. await fileLink.waitFor({ timeout: 10_000 })
  132. const frame = page.locator('[data-details-collapsed], [class*="frame"]').first()
  133. expect(await frame.getAttribute('data-details-collapsed')).not.toBeNull()
  134. await fileLink.click()
  135. await expect.poll(() => frame.getAttribute('data-details-collapsed'), { timeout: 5_000 }).not.toBeNull()
  136. // Path label survives from the recorded args (a.txt).
  137. await expect.poll(() => page.getByText('a.txt', { exact: false }).count(), { timeout: 5_000 }).toBeGreaterThan(0)
  138. })
  139. it.skipIf(MODE === 'record')('issued zero model calls and stayed clean', async () => {
  140. // No replay fixture was installed and the llm seam is open — any stray
  141. // stream would have failed the turn loudly. Cleanliness pins the wire.
  142. expect(tripwire.pageErrors).toEqual([])
  143. expect(tripwire.warnings).toEqual([])
  144. await assertFixtureInventory(SNAPSHOT_DIR, ['seed.jsonl', 'ui.expected.md'])
  145. })
  146. })