seeded-history.e2e.ts 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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, cold history paging without Agent
  4. // activation, history-page tool views, and the client's log-ordered transcript
  5. // events — with ZERO model calls in replay (no replay fixture; a stray stream
  6. // fails loud on the open llm seam). The cold session also carries keyless
  7. // command-row surfaces: the seeded manual `/compact` lifecycle folds into its
  8. // checkpoint, an Access-chip pick later runs `/permission` on the host, and
  9. // `/feedback` pins its expandable correlation ids. The seed is a recorded
  10. // fixture under the same record discipline as every other: DSH_SNAPSHOT=record drives the turn
  11. // live through the composer (real read tool against seeded workspace files)
  12. // and harvests session.v3.jsonl; replay/refresh seed it cold and only render.
  13. import { readFile, writeFile, mkdir } from 'node:fs/promises'
  14. import { fileURLToPath } from 'node:url'
  15. import type { Browser, Page } from 'playwright'
  16. import { chromium } from 'playwright'
  17. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  18. import { createUserMessage } from '@deepseek-ai/dsh-llm'
  19. import type { ContentBlock, Message } from '@deepseek-ai/dsh-llm'
  20. import { deriveEventMessage, SessionId } from '@deepseek-ai/dsh-session'
  21. import type { SessionEvent } from '@deepseek-ai/dsh-session'
  22. import type { TokenMeter } from '@deepseek-ai/dsh-token-meter'
  23. import { join } from 'node:path'
  24. import {
  25. assertFixtureInventory, captureExpandedTurnProcessAria, captureStableAria,
  26. compareOrRefreshGolden, fixtureUserPrompts,
  27. launchWebScaffold, parseSeedFixture, realizeSeedFixture, recordFixture, renderSeedFixture, seedSession, watchConsole,
  28. webSnapshotMode, type WebScaffold,
  29. } from './scaffold.ts'
  30. import { expandOwningTurnProcess, newEnglishPage, saveFailureShot } from './support.ts'
  31. const SNAPSHOT_DIR = fileURLToPath(new URL('../../../snapshots/web/seeded-history', import.meta.url))
  32. const SEED = fileURLToPath(new URL('../../../snapshots/web/seeded-history/session.v3.jsonl', import.meta.url))
  33. const UI_EXPECTED = fileURLToPath(new URL('../../../snapshots/web/seeded-history/ui.expected.md', import.meta.url))
  34. const UI_EXPANDED_EXPECTED = fileURLToPath(
  35. new URL('../../../snapshots/web/seeded-history/ui-expanded.expected.md', import.meta.url),
  36. )
  37. // Command-row goldens over the same conversation after direct host commands.
  38. const COMMAND_ROW_EXPECTED = fileURLToPath(new URL('../../../snapshots/web/seeded-history/command-row.expected.md', import.meta.url))
  39. const FEEDBACK_ROW_EXPECTED = fileURLToPath(new URL('../../../snapshots/web/seeded-history/feedback-row.expected.md', import.meta.url))
  40. const FILE_PREVIEW_EXPECTED = join(SNAPSHOT_DIR, 'file-preview.expected.md')
  41. const MODE = webSnapshotMode()
  42. const SEED_ID = 'seeded-history-web-e2e'
  43. 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.'
  44. /**
  45. * Append a complete manual `/compact` lifecycle and valid compaction transaction
  46. * over the recorded turn's own surface. The recording stays model-authentic and
  47. * reusable; replay adds this deterministic condition before seeding it cold, so
  48. * the scenario pins both the log-preserving marker and its single-card command
  49. * presentation through the real host and browser.
  50. * @param raw - the seed fixture text, already realized (placeholder-free) so
  51. * the shadow price below is computed from the exact strings the host folds.
  52. * @param meter - the composed token meter; the appended `compaction/summary`'s
  53. * shadow price must be the exact heuristic price of the shadowed nodes, the
  54. * way compaction-basic derives it, because the token-meter projections subtract
  55. * it verbatim.
  56. * @returns the fixture with a manual compaction lifecycle appended.
  57. */
  58. function withCompaction(raw: string, meter: TokenMeter): string {
  59. const decoded = parseSeedFixture(raw)
  60. const events = decoded.events as unknown as Array<{
  61. type: string
  62. seq: number
  63. time: number
  64. surfaceOp?: unknown
  65. data?: { turn?: unknown; message?: unknown; content?: unknown; callId?: unknown; isError?: unknown }
  66. }>
  67. const surfaceSeqs = events
  68. .filter(event => event.surfaceOp === 'append'
  69. && (event.type === 'user/message'
  70. || event.type === 'assistant/message'
  71. || event.type === 'tool/result'))
  72. .map(event => event.seq)
  73. const first = surfaceSeqs[0]
  74. const last = surfaceSeqs.at(-1)
  75. const tail = events.at(-1)
  76. if (first === undefined || last === undefined || tail === undefined) {
  77. throw new Error('seeded-history compaction requires a non-empty closed surface')
  78. }
  79. const lastTurn = events.filter(event => event.type === 'turn/end').at(-1)?.data?.turn
  80. if (typeof lastTurn !== 'number') {
  81. throw new Error('seeded-history compaction requires a recording ending on a closed turn')
  82. }
  83. let seq = tail.seq + 1
  84. let time = tail.time + 1
  85. /**
  86. * Append one event at the next seq/time.
  87. * @param event - the event body, without seq/time.
  88. * @returns the assigned seq, so later `sourceEventSeqs` cite the pushed event directly.
  89. */
  90. const at = (event: { type: string } & Record<string, unknown>): number => {
  91. const taken = seq++
  92. events.push({ ...event, seq: taken, time: time++ })
  93. return taken
  94. }
  95. const commandId = 'cmd-seeded-manual-compact'
  96. const compactionId = 'compact-seeded-manual-compact'
  97. at({
  98. type: 'command/run',
  99. data: { commandId, name: 'compact', args: '', source: { kind: 'user' } },
  100. })
  101. const startSeq = at({
  102. type: 'compaction/start',
  103. data: { compactionId, sourceCommandId: commandId, turn: null },
  104. })
  105. // Load-bearing exactness: the projections subtract this count verbatim, so
  106. // it must equal what the host's fold prices for these nodes. The estimator
  107. // prices message CONTENT only, so a minimal wrapper for each stored event format is
  108. // exact — pre-identity rows carry bare `content` (the persistence read path
  109. // upgrades them), a current row carries the full `message` envelope.
  110. const priceRow = (row: (typeof events)[number]): number => {
  111. if (row.data?.message !== undefined) {
  112. const message = deriveEventMessage(row as unknown as SessionEvent)
  113. return message === null ? 0 : meter.estimateMessage(message)
  114. }
  115. const content = row.data?.content as ContentBlock[]
  116. if (row.type === 'tool/result') {
  117. return meter.estimateMessage({
  118. content: [{ type: 'tool-result', toolCallId: row.data?.callId, content, isError: row.data?.isError === true }],
  119. } as unknown as Message)
  120. }
  121. // An empty-content assistant message derives no transcript entry.
  122. if (row.type === 'assistant/message' && content.length === 0) return 0
  123. return meter.estimateMessage({ content } as unknown as Message)
  124. }
  125. const shadowedTokenCount = surfaceSeqs.reduce((total, surfaceSeq) => {
  126. const event = events.find(candidate => candidate.seq === surfaceSeq)
  127. if (event === undefined) throw new Error(`seeded-history compaction: shadowed seq ${surfaceSeq} is not in the seed`)
  128. return total + priceRow(event)
  129. }, 0)
  130. const summarySeq = at({
  131. type: 'compaction/summary',
  132. data: {
  133. compactionId,
  134. sourceCommandId: commandId,
  135. summary: [{
  136. type: 'text',
  137. text: '## Cold resume compact summary\n\n- The exact summary remains available.',
  138. }],
  139. shadowedRange: { start: first, end: last },
  140. shadowedSeqs: surfaceSeqs,
  141. shadowedTokenCount,
  142. provider: 'snapshot',
  143. model: 'snapshot-compactor',
  144. },
  145. })
  146. at({
  147. type: 'user/message',
  148. data: createUserMessage({
  149. content: [{
  150. type: 'text',
  151. text: '<context_checkpoint>Model-only compact checkpoint.</context_checkpoint>',
  152. }],
  153. source: {
  154. kind: 'plugin', plugin: 'compact', compactionId, sourceCommandId: commandId,
  155. },
  156. }),
  157. surfaceOp: { op: 'replace', startSeq: first, endSeq: last },
  158. sourceEventSeqs: [startSeq, summarySeq, ...surfaceSeqs],
  159. })
  160. at({
  161. type: 'compaction/end',
  162. data: { compactionId, sourceCommandId: commandId, turn: null },
  163. })
  164. at({
  165. type: 'command/done',
  166. data: {
  167. commandId,
  168. kind: 'success',
  169. text: `Compacted ${surfaceSeqs.length} history items (~${shadowedTokenCount} tokens).`,
  170. sourceEventSeq: summarySeq,
  171. },
  172. })
  173. // The persistence seed helper requires a terminal turn/end. Keep the manual
  174. // command standalone, then add a closed zero-step turn after it.
  175. const closureTurn = lastTurn + 1
  176. at({ type: 'turn/start', data: { turn: closureTurn } })
  177. at({ type: 'turn/end', data: { turn: closureTurn, reason: { kind: 'completed' } } })
  178. return renderSeedFixture(decoded.headerLine, events)
  179. }
  180. describe('web e2e: seeded history renders through cold resume', () => {
  181. let scaffold: WebScaffold
  182. let browser: Browser
  183. let page: Page
  184. let tripwire: ReturnType<typeof watchConsole>
  185. let seededThroughSeq = -1
  186. beforeAll(async () => {
  187. scaffold = await launchWebScaffold({})
  188. // Composer recording uses a child workspace; seedSession owns the scaffold root.
  189. const sessionCwd = MODE === 'record' ? join(scaffold.workspaceCwd, 'workspace') : scaffold.workspaceCwd
  190. await mkdir(sessionCwd, { recursive: true })
  191. await writeFile(join(sessionCwd, 'a.txt'), 'alpha\n')
  192. await writeFile(join(sessionCwd, 'b.txt'), 'beta\n')
  193. if (MODE !== 'record') {
  194. const raw = await readFile(SEED, 'utf8')
  195. expect(fixtureUserPrompts(raw), 'seed fixture must carry exactly the drive prompt').toEqual([PROMPT])
  196. // The meter is host-plane — it takes no configuration and keys every
  197. // fold by Session — so pricing fixture content needs no agent at all.
  198. const meter = scaffold.ctx.get('tokenMeter')
  199. if (meter === undefined) throw new Error('seeded-history requires the host token meter')
  200. const realizedWithCompaction = withCompaction(realizeSeedFixture(scaffold, raw, SEED_ID), meter)
  201. seededThroughSeq = parseSeedFixture(realizedWithCompaction).events.at(-1)?.seq ?? -1
  202. await seedSession(scaffold, realizedWithCompaction, SEED_ID)
  203. }
  204. browser = await chromium.launch()
  205. page = await newEnglishPage(browser)
  206. tripwire = watchConsole(page)
  207. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  208. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  209. }, 120_000)
  210. afterAll(async () => {
  211. await browser?.close()
  212. await scaffold?.close()
  213. })
  214. it.skipIf(MODE !== 'record')('records the seed turn live through the composer', async () => {
  215. onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-record'))
  216. const input = page.locator('[data-composer-input]').first()
  217. await input.waitFor({ timeout: 10_000 })
  218. const settled = scaffold.whenTurnSettled()
  219. await input.fill(PROMPT)
  220. await input.press('Enter')
  221. const sessionId = await settled
  222. await recordFixture(scaffold, sessionId, SEED)
  223. }, 200_000)
  224. it.skipIf(MODE === 'record')('serves the projections baseline on the real composition opening snapshot', async () => {
  225. // Composition regression tripwire: the projection registry must be a row
  226. // in the SHIPPED cordis.yml — with it absent every domain unit's optional
  227. // injection stays silent and this block disappears (no titles/todos on
  228. // the web), while fixture-level suites stay green. Assert through the
  229. // production Session Controller against the booted real host.
  230. const controller = new AbortController()
  231. const stream = scaffold.ctx.sessionController.follow({
  232. address: { kind: 'session', sessionId: SessionId(SEED_ID) },
  233. }, controller.signal)[Symbol.asyncIterator]()
  234. const first = await stream.next()
  235. controller.abort()
  236. if (first.done || first.value.type !== 'snapshot') {
  237. throw new Error('session follow did not publish its opening snapshot')
  238. }
  239. expect(first.value.cursor).toBe(seededThroughSeq)
  240. const projections = first.value.projections
  241. expect(projections.asOfSeq).toBe(seededThroughSeq)
  242. // The seed carries a session/title event: the title unit is host-plane, so
  243. // it folds the detached log and serves the value with nothing composed.
  244. expect(typeof projections.values.title).toBe('string')
  245. // `todos` is absent because its unit belongs to the agent preset and this
  246. // directly seeded session never composed that preset. History computes
  247. // the baseline through the standard projection registry without mounting
  248. // an Agent composition as a read side effect.
  249. expect(projections.values).not.toHaveProperty('todos')
  250. // The session-stats unit is a shipped web-app bundle row: whole-log
  251. // turn/step counts ride the same tail block (the stats strip's source).
  252. const sessionStats = projections.values.sessionStats as { turns: number; steps: number } | undefined
  253. expect(sessionStats).toBeDefined()
  254. expect(sessionStats?.turns).toBeGreaterThanOrEqual(1)
  255. expect(sessionStats?.steps).toBeGreaterThanOrEqual(sessionStats?.turns ?? 0)
  256. })
  257. it.skipIf(MODE === 'record')('lists the seeded session cold and renders its history from the log', async () => {
  258. onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-history'))
  259. // The sidebar tree collapses workspace groups by default: click the group
  260. // row (treeitem 0) to expand, then the revealed session row.
  261. const groupRow = page.locator('[role="treeitem"]').first()
  262. await groupRow.waitFor({ timeout: 15_000 })
  263. await groupRow.click()
  264. const sessionRow = page.locator('[role="treeitem"]').nth(1)
  265. await sessionRow.waitFor({ timeout: 10_000 })
  266. await sessionRow.click()
  267. // Settled barrier for history: the recorded final assistant text renders.
  268. await expect.poll(() => page.getByText('DONE', { exact: true }).count(), { timeout: 15_000 }).toBe(1)
  269. await expect.poll(() => page.getByText('compact', { exact: true }).count(), { timeout: 10_000 }).toBe(1)
  270. await expect.poll(() => page.getByText(/^Compacted \d+ history items \(~\d+ tokens\)$/).count(), {
  271. timeout: 10_000,
  272. }).toBe(1)
  273. const process = page.locator('[data-turn-process="1"]')
  274. await process.waitFor({ state: 'visible', timeout: 10_000 })
  275. expect(await process.getAttribute('aria-expanded')).toBe('false')
  276. const processBottom = await process.evaluate(element => element.getBoundingClientRect().bottom)
  277. const answerTop = await page.getByText('DONE', { exact: true }).evaluate(element =>
  278. element.getBoundingClientRect().top)
  279. // Collapsed control row keeps its own 8px margin plus the 8px flow gap.
  280. expect(answerTop).toBe(processBottom + 16)
  281. expect(await page.getByText('Context compacted', { exact: true }).count()).toBe(0)
  282. // Tool cards render from logged tool/call + tool/result alone (views are
  283. // host-recomputed per page; the generic card is the documented default).
  284. const toolRows = page.locator('[data-variant], [data-sample]')
  285. await expect.poll(() => toolRows.count(), { timeout: 10_000 }).toBeGreaterThanOrEqual(2)
  286. expect(await page.getByText('a.txt', { exact: false }).count()).toBeGreaterThan(0)
  287. // The pinned hazard: compaction shadows the surface on the model side
  288. // only — the prompt and full tool output must stay on screen.
  289. expect(await page.getByText(PROMPT, { exact: true }).count()).toBe(1)
  290. await expect.poll(
  291. () => scaffold.ctx.agents.get(SessionId(SEED_ID)) !== undefined,
  292. { timeout: 10_000 },
  293. ).toBe(true)
  294. const agent = scaffold.ctx.agents.get(SessionId(SEED_ID))
  295. if (agent === undefined) throw new Error('seeded session did not attach an agent')
  296. agent.session.append('user/message', createUserMessage({
  297. content: [{
  298. type: 'text',
  299. text: '<system-reminder>\n'
  300. + 'The following workspace instructions may be relevant to your work. '
  301. + 'Use them as guidance when applicable.\n\n'
  302. + Array.from({ length: 24 }, (_, index) => `Instruction ${index + 1}: preserve the logged context contract.`).join('\n')
  303. + '\n</system-reminder>',
  304. }],
  305. source: {
  306. kind: 'agent-instructions',
  307. form: 'instructions',
  308. baseline: true,
  309. changes: [{
  310. action: 'set',
  311. scope: '.\u0000AGENTS.md',
  312. path: 'AGENTS.md',
  313. digest: 'context-injection-browser-snapshot',
  314. }],
  315. },
  316. }), { surfaceOp: 'append' })
  317. // The header names the producer the durable source records, so the
  318. // reconciled instruction file is readable without expanding the row.
  319. await page.getByRole('button', { name: 'Context injection AGENTS.md', exact: true })
  320. .waitFor({ timeout: 10_000 })
  321. }, 60_000)
  322. it.skipIf(MODE === 'record')('matches the historical conversation aria golden', async () => {
  323. onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-aria'))
  324. // This scenario issues zero model calls — the scaffold's route-only
  325. // adapter serves the catalog and refuses to stream — so history restores
  326. // the routed id and the seat resolves it against an advertised row.
  327. await page.getByRole('button', { name: /^Select model, current/ })
  328. .waitFor({ timeout: 10_000 })
  329. const snapshot = (await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd))
  330. .split(SEED_ID).join('{{seededId}}')
  331. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  332. const expanded = (await captureExpandedTurnProcessAria(
  333. page,
  334. '[class*="centerCol"]',
  335. scaffold.workspaceCwd,
  336. )).split(SEED_ID).join('{{seededId}}')
  337. await compareOrRefreshGolden(UI_EXPANDED_EXPECTED, expanded, MODE)
  338. })
  339. it.skipIf(MODE === 'record')('matches the Figma context disclosure geometry', async () => {
  340. onTestFailed(() => saveFailureShot(page, 'web-e2e-context-injection'))
  341. const disclosure = page.getByRole('button', { name: 'Context injection AGENTS.md', exact: true })
  342. expect(await disclosure.getAttribute('aria-expanded')).toBe('false')
  343. const collapsedIcon = disclosure.locator('svg').first()
  344. const collapsedIconBox = await collapsedIcon.boundingBox()
  345. expect(collapsedIconBox?.width).toBe(14)
  346. expect(collapsedIconBox?.height).toBe(14)
  347. await disclosure.click()
  348. await expect.poll(() => disclosure.getAttribute('aria-expanded')).toBe('true')
  349. const body = page.locator('[data-context-injection-body]')
  350. await body.waitFor({ timeout: 5_000 })
  351. // The instructions form names the file it reconciled above the text, and
  352. // the text keeps the framing the model read rather than a cleaned excerpt.
  353. expect(await body.locator('[data-context-files] li').allInnerTexts()).toEqual(['AGENTS.md\nloaded'])
  354. expect(await body.locator('[data-context-text]').innerText()).toContain('<system-reminder>')
  355. const headerBox = await disclosure.boundingBox()
  356. const bodyBox = await body.boundingBox()
  357. if (headerBox === null || bodyBox === null) throw new Error('context disclosure geometry is not measurable')
  358. expect(headerBox.height).toBe(24)
  359. expect(bodyBox.x - headerBox.x).toBe(22)
  360. expect(bodyBox.y - headerBox.y - headerBox.height).toBe(4)
  361. expect(bodyBox.height).toBe(141)
  362. const style = await body.evaluate((element) => {
  363. const computed = getComputedStyle(element)
  364. return {
  365. backgroundColor: computed.backgroundColor,
  366. borderRadius: computed.borderRadius,
  367. color: computed.color,
  368. fontSize: computed.fontSize,
  369. lineHeight: computed.lineHeight,
  370. padding: [
  371. computed.paddingTop,
  372. computed.paddingRight,
  373. computed.paddingBottom,
  374. computed.paddingLeft,
  375. ],
  376. scrolls: element.scrollHeight > element.clientHeight,
  377. }
  378. })
  379. expect(style).toEqual({
  380. backgroundColor: 'rgb(249, 250, 251)',
  381. borderRadius: '8px',
  382. color: 'rgb(129, 133, 140)',
  383. fontSize: '11px',
  384. lineHeight: '16px',
  385. padding: ['10px', '16px', '12px', '12px'],
  386. scrolls: true,
  387. })
  388. await disclosure.click()
  389. await expect.poll(() => disclosure.getAttribute('aria-expanded')).toBe('false')
  390. })
  391. it.skipIf(MODE === 'record')('file-path tool rows rebuilt from the cold log open the right Sidebar', async () => {
  392. onTestFailed(async () => {
  393. await mkdir(fileURLToPath(new URL('../../../.artifacts/screenshots/0907-2205-sidebar', import.meta.url)), { recursive: true })
  394. await saveFailureShot(page, `screenshots/0907-2205-sidebar/seeded-toolrow-${process.pid}`)
  395. })
  396. // Interaction over cold-resumed history: read summaries are file links
  397. // that open a text-preview tab in the right Sidebar (not expand-in-place).
  398. // Runs after the golden capture; still zero model calls.
  399. const fileLink = page.locator('[data-variant="read"] button').first()
  400. await expandOwningTurnProcess(page, fileLink)
  401. await fileLink.waitFor({ timeout: 10_000 })
  402. const frame = page.locator('[style*="grid-template-columns"]').first()
  403. expect(await frame.getAttribute('data-rightbar-collapsed')).toBe('true')
  404. await fileLink.click()
  405. await expect.poll(() => frame.getAttribute('data-rightbar-collapsed'), { timeout: 5_000 }).toBe(null)
  406. const column = page.locator('[data-rightbar-col]')
  407. await expect.poll(() => column.locator('[data-dockkit-tab-title]').allTextContents(), { timeout: 5_000 }).toEqual(['a.txt'])
  408. // Path label survives from the recorded args (a.txt).
  409. await expect.poll(() => page.getByText('a.txt', { exact: false }).count(), { timeout: 5_000 }).toBeGreaterThan(0)
  410. const path = column.locator('[data-textpreview-path]')
  411. const absolutePath = join(scaffold.workspaceCwd, 'a.txt')
  412. await expect.poll(() => path.textContent()).toBe(absolutePath)
  413. expect(await path.getAttribute('title')).toBe(absolutePath)
  414. await expect.poll(() => column.locator('[data-textpreview-line="1"]').textContent()).toBe('alpha\n')
  415. const preview = await captureStableAria(page, '[data-textpreview-state="text"]', scaffold.workspaceCwd)
  416. await compareOrRefreshGolden(FILE_PREVIEW_EXPECTED, preview, MODE)
  417. // Put the column back so the later goldens see the default frame.
  418. await column.locator('[data-sidebar-right-toggle]').click()
  419. await expect.poll(() => frame.getAttribute('data-rightbar-collapsed'), { timeout: 5_000 }).toBe('true')
  420. await page.getByRole('button', { name: 'Open right sidebar', exact: true }).waitFor({ state: 'visible' })
  421. await page.getByRole('navigation', { name: 'Turn navigation', exact: true }).waitFor({ state: 'visible' })
  422. })
  423. it.skipIf(MODE === 'record')('expands the cold-resumed compact summary', async () => {
  424. onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-compaction'))
  425. const marker = page.getByRole('button', { name: /compact Compacted \d+ history items/ })
  426. await marker.waitFor({ timeout: 10_000 })
  427. expect(await marker.getAttribute('aria-expanded')).toBe('false')
  428. await marker.click()
  429. await expect.poll(() => marker.getAttribute('aria-expanded'), { timeout: 5_000 }).toBe('true')
  430. await expect.poll(() => page.getByRole('heading', { name: 'Cold resume compact summary' }).count(), {
  431. timeout: 5_000,
  432. }).toBe(1)
  433. expect(await page.getByText('The exact summary remains available.', { exact: false }).count()).toBeGreaterThan(0)
  434. // Restore the shared page state for any later case.
  435. await marker.click()
  436. await expect.poll(() => marker.getAttribute('aria-expanded'), { timeout: 5_000 }).toBe('false')
  437. })
  438. it.skipIf(MODE === 'record')('an Access-chip switch lands one command row: bare name, non-repeating settlement text', async () => {
  439. onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-command-row'))
  440. // The Access chip submits `/permission <preset>` — a host command with no
  441. // model call, so the settled row renders keylessly over this cold history.
  442. // The row copy is the assertion: `permission · preset read-only`,
  443. // where neither half repeats the other (the dispatched `/` and its
  444. // argument stay out of the title, and the settlement text never restates
  445. // the command's own name).
  446. await page.getByRole('button', { name: 'Access mode, current: Workspace Write' }).click()
  447. await page.getByRole('menuitem', { name: 'Read Only' }).click()
  448. const access = page.getByRole('button', { name: 'Access mode, current: Read Only' })
  449. await expect.poll(() => access.isEnabled(), { timeout: 10_000 }).toBe(true)
  450. // Scoped to the row itself, so unrelated page text that happens to read
  451. // `permission` (a future resident slash menu) cannot satisfy or break it.
  452. const row = page.locator('[data-variant="others"]').filter({ hasText: 'preset read-only' })
  453. await expect.poll(() => row.count(), { timeout: 10_000 }).toBe(1)
  454. expect(await row.getByText('permission', { exact: true }).count()).toBe(1)
  455. expect(await row.getByText('/permission read-only', { exact: true }).count()).toBe(0)
  456. const snapshot = (await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd))
  457. .split(SEED_ID).join('{{seededId}}')
  458. await compareOrRefreshGolden(COMMAND_ROW_EXPECTED, snapshot, MODE)
  459. }, 60_000)
  460. it.skipIf(MODE === 'record')('reports full feedback correlation ids in an expandable two-line row', async () => {
  461. onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-feedback-row'))
  462. const previousDshHome = process.env.DSH_HOME
  463. process.env.DSH_HOME = scaffold.harnessHome
  464. try {
  465. const input = page.locator('[data-composer-input]').first()
  466. await input.fill('/feedback the diff view is unreadable')
  467. await input.press('Enter')
  468. const row = page.locator('[data-variant="others"]').filter({
  469. hasText: `Feedback recorded for session ${SEED_ID}`,
  470. })
  471. await row.waitFor({ timeout: 10_000 })
  472. const disclosure = row.locator('[data-expandable]')
  473. expect(await disclosure.getAttribute('aria-expanded')).toBe('false')
  474. await disclosure.click()
  475. await expect.poll(() => disclosure.getAttribute('aria-expanded')).toBe('true')
  476. const agent = scaffold.ctx.agents.get(SessionId(SEED_ID))
  477. if (agent === undefined) throw new Error('seeded session did not attach an agent')
  478. const done = agent.session.snapshotEvents().filter(event => event.type === 'command/done').at(-1)
  479. if (done?.type !== 'command/done') throw new Error('feedback command did not settle')
  480. const [sessionLine, userLine, extraLine] = done.data.text?.split('\n') ?? []
  481. expect(sessionLine).toBe(`Feedback recorded for session ${SEED_ID}`)
  482. expect(userLine).toMatch(/^Anonymous user: [0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.$/i)
  483. expect(extraLine).toBeUndefined()
  484. const userId = userLine?.match(/^Anonymous user: ([0-9a-f-]+)/i)?.[1]
  485. if (userId === undefined) throw new Error('feedback command omitted the user id')
  486. // command/done can arrive before the submit reply releases the composer.
  487. await expect.poll(() => input.textContent(), { timeout: 10_000 }).toBe('')
  488. await expect.poll(() => page.getByRole('button', { name: 'Add files or run commands' }).isEnabled(), { timeout: 10_000 }).toBe(true)
  489. const snapshot = (await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd))
  490. .split(SEED_ID).join('{{seededId}}')
  491. .split(userId).join('{{userId}}')
  492. await compareOrRefreshGolden(FEEDBACK_ROW_EXPECTED, snapshot, MODE)
  493. } finally {
  494. if (previousDshHome === undefined) delete process.env.DSH_HOME
  495. else process.env.DSH_HOME = previousDshHome
  496. }
  497. }, 60_000)
  498. it.skipIf(MODE === 'record')('fits short logged context without a scrollport', async () => {
  499. const agent = scaffold.ctx.agents.get(SessionId(SEED_ID))
  500. if (agent === undefined) throw new Error('seeded session did not attach an agent')
  501. agent.session.append('user/message', createUserMessage({
  502. content: [{ type: 'text', text: 'Short injected context.' }],
  503. source: { kind: 'plugin', plugin: 'fixture' },
  504. }), { surfaceOp: 'append' })
  505. const disclosure = page.getByRole('button', { name: 'Context injection fixture', exact: true })
  506. await disclosure.waitFor({ timeout: 10_000 })
  507. await disclosure.click()
  508. await expect.poll(() => disclosure.getAttribute('aria-expanded')).toBe('true')
  509. // The instructions row above stays expanded from the geometry case; the
  510. // opaque body is the one without a declared form.
  511. const body = page.locator('[data-context-injection-body]:not([data-context-form])')
  512. const bodyBox = await body.boundingBox()
  513. if (bodyBox === null) throw new Error('short context disclosure geometry is not measurable')
  514. expect(bodyBox.height).toBeLessThan(141)
  515. expect(await body.evaluate(element => element.scrollHeight > element.clientHeight)).toBe(false)
  516. })
  517. it.skipIf(MODE === 'record')('issued zero model calls and stayed clean', async () => {
  518. // No replay fixture was installed and the llm seam is open — any stray
  519. // stream would have failed the turn loudly. Cleanliness pins the wire.
  520. expect(tripwire.pageErrors).toEqual([])
  521. expect(tripwire.warnings).toEqual([])
  522. await assertFixtureInventory(SNAPSHOT_DIR, [
  523. 'command-row.expected.md', 'feedback-row.expected.md', 'file-preview.expected.md',
  524. 'session.v3.jsonl', 'ui.expected.md', 'ui-expanded.expected.md',
  525. ])
  526. })
  527. })