reference-composer.e2e.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Web e2e scenario: the shipped composition discovers local files and cold
  2. // sessions through the real Host, groups both domains in the shared @ menu,
  3. // and projects each pick back into the composer without issuing a model call.
  4. import { writeFile } from 'node:fs/promises'
  5. import { fileURLToPath } from 'node:url'
  6. import { join } from 'node:path'
  7. import type { Browser, Page } from 'playwright'
  8. import { chromium } from 'playwright'
  9. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  10. import { createUserMessage } from '@deepseek-ai/dsh-llm'
  11. import {
  12. SESSION_FORMAT_VERSION,
  13. Session,
  14. SessionId,
  15. } from '@deepseek-ai/dsh-session'
  16. import type {} from '@deepseek-ai/dsh-session-title'
  17. import {
  18. assertFixtureInventory,
  19. captureStableAria,
  20. compareOrRefreshGolden,
  21. launchWebScaffold,
  22. seedSession,
  23. watchConsole,
  24. webSnapshotMode,
  25. type WebScaffold,
  26. } from './scaffold.ts'
  27. import { connectFreshWorkspace, newEnglishPage, saveFailureShot } from './support.ts'
  28. const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/reference-composer', import.meta.url))
  29. const MENU_EXPECTED = join(SNAPSHOT_DIR, 'menu.expected.md')
  30. const MODE = webSnapshotMode()
  31. const SOURCE_SESSION_ID = 'reference-source-session'
  32. /** Build one closed source session with a stable title for reference discovery. */
  33. function sourceSessionFixture(): string {
  34. const session = Session.create(SessionId(SOURCE_SESSION_ID))
  35. session.append('turn/start', {
  36. turn: 1,
  37. })
  38. const user = session.append('user/message', createUserMessage({
  39. content: [{ type: 'text', text: 'Research context for the reference menu.' }],
  40. source: { kind: 'user' },
  41. }), { surfaceOp: 'append' })
  42. session.append('session/title', {
  43. title: 'Research notes',
  44. messageSeqs: [user.seq],
  45. source: { kind: 'fallback' },
  46. })
  47. session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
  48. return [
  49. JSON.stringify({
  50. type: 'session',
  51. version: SESSION_FORMAT_VERSION,
  52. id: '{{sessionId}}',
  53. createdAt: 0,
  54. cwd: '{{cwd}}',
  55. }),
  56. ...session.events.map(event => JSON.stringify(event)),
  57. '',
  58. ].join('\n')
  59. }
  60. describe.skipIf(MODE === 'record')('web e2e: file and session references through the real host', () => {
  61. let scaffold: WebScaffold
  62. let browser: Browser
  63. let page: Page
  64. let tripwire: ReturnType<typeof watchConsole>
  65. beforeAll(async () => {
  66. scaffold = await launchWebScaffold({})
  67. await seedSession(scaffold, sourceSessionFixture(), SOURCE_SESSION_ID)
  68. browser = await chromium.launch()
  69. page = await newEnglishPage(browser)
  70. tripwire = watchConsole(page)
  71. await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
  72. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  73. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  74. await writeFile(join(scaffold.workspaceCwd, 'workspace', 'reference.txt'), 'reference fixture\n')
  75. }, 120_000)
  76. afterAll(async () => {
  77. await browser?.close()
  78. await scaffold?.close()
  79. })
  80. it('groups both sources and projects file text plus an atomic session chip', async () => {
  81. onTestFailed(() => saveFailureShot(page, 'web-e2e-reference-composer'))
  82. const input = page.locator('textarea').first()
  83. const menu = page.getByRole('listbox', { name: 'Trigger suggestions' })
  84. await input.fill('@')
  85. await expect.poll(() => menu.getByRole('option').count(), { timeout: 15_000 }).toBeGreaterThanOrEqual(2)
  86. const snapshot = await captureStableAria(page, '[role="listbox"]', scaffold.workspaceCwd)
  87. await compareOrRefreshGolden(MENU_EXPECTED, snapshot, MODE)
  88. expect(snapshot).toContain('Files & folders')
  89. expect(snapshot).toContain('Session conversations')
  90. expect(snapshot).toContain('File \u00b7 reference.txt')
  91. expect(snapshot).toContain('Session \u00b7 Research notes')
  92. expect(snapshot).not.toContain('text: Subagents')
  93. await input.fill('@reference')
  94. await menu.getByRole('option', { name: /File \u00b7 reference\.txt/ }).click()
  95. await expect.poll(() => input.inputValue()).toBe('@reference.txt ')
  96. await input.fill('@Research')
  97. await menu.getByRole('option', { name: /Session \u00b7 Research notes/ }).click()
  98. await expect.poll(() => page.locator('[data-decoration="chip"]').textContent()).toBe('@Research notes')
  99. expect(tripwire.pageErrors).toEqual([])
  100. expect(tripwire.warnings).toEqual([])
  101. await assertFixtureInventory(SNAPSHOT_DIR, ['menu.expected.md'])
  102. })
  103. })