agent-team-panel.e2e.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Keyless assembled-browser coverage for the opt-in Agent Teams Web profiles
  2. // over the real Host Typert Remote flow.
  3. import { fileURLToPath } from 'node:url'
  4. import { join } from 'node:path'
  5. import { readFileSync } from 'node:fs'
  6. import type { Browser, Page } from 'playwright'
  7. import { chromium } from 'playwright'
  8. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  9. import * as yaml from 'js-yaml'
  10. import { entryListSchema } from '@deepseek-ai/cordis-plugin-include'
  11. import { createMessage, createUserMessage } from '@deepseek-ai/dsh-llm'
  12. import {
  13. assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
  14. launchWebScaffold, watchConsole, webSnapshotMode, type WebScaffold,
  15. } from './scaffold.ts'
  16. import { connectFreshWorkspace, newEnglishPage, saveFailureShot } from './support.ts'
  17. const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/agent-team-panel', import.meta.url))
  18. const PANEL_EXPECTED = join(SNAPSHOT_DIR, 'task.expected.md')
  19. const OVERLAY = fileURLToPath(new URL('./agent-team-panel.overlay.yml', import.meta.url))
  20. const HOST_PATCH = fileURLToPath(new URL('../../../packages/experimental/agent-team-profile/cordis.patch.yml', import.meta.url))
  21. const WEB_PATCH = fileURLToPath(new URL('../../../packages/experimental/agent-team-web-profile/cordis.patch.yml', import.meta.url))
  22. const INSTALL_ANCHORS = [
  23. fileURLToPath(new URL('../../../packages/experimental/agent-team-profile/package.json', import.meta.url)),
  24. fileURLToPath(new URL('../../../packages/experimental/agent-team-web-profile/package.json', import.meta.url)),
  25. ]
  26. const MODE = webSnapshotMode()
  27. function profileEntries(path: string): unknown[] {
  28. const parsed = yaml.load(readFileSync(path, 'utf8'), { schema: entryListSchema })
  29. if (!Array.isArray(parsed)) throw new Error(`profile layer at ${path} must be a list`)
  30. return parsed
  31. }
  32. describe('Agent Teams panel overlay', () => {
  33. it('matches the shipped Host and Web profile layers', () => {
  34. expect(profileEntries(OVERLAY)).toEqual([
  35. ...profileEntries(HOST_PATCH),
  36. ...profileEntries(WEB_PATCH),
  37. ])
  38. })
  39. })
  40. describe('web e2e: Agent Teams panel', () => {
  41. let scaffold: WebScaffold
  42. let browser: Browser
  43. let page: Page
  44. let tripwire: ReturnType<typeof watchConsole>
  45. beforeAll(async () => {
  46. scaffold = await launchWebScaffold({ extraOverlayPath: OVERLAY, extraInstallAnchors: INSTALL_ANCHORS })
  47. browser = await chromium.launch()
  48. page = await newEnglishPage(browser)
  49. tripwire = watchConsole(page)
  50. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  51. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  52. await connectFreshWorkspace(page, scaffold.workspaceCwd)
  53. const agent = scaffold.ctx.agents.list()[0]
  54. if (agent === undefined) throw new Error('connected Team workspace did not create an Agent')
  55. agent.session.append('turn/start', { turn: 1 })
  56. agent.session.append('user/message', createUserMessage({
  57. content: [{ type: 'text', text: 'Open the Agent Team controls.' }],
  58. source: { kind: 'user' },
  59. }), { surfaceOp: 'append' })
  60. agent.session.append('step/start', { turn: 1, step: 1 })
  61. agent.session.append('assistant/message', {
  62. stream: [],
  63. turn: 1,
  64. step: 1,
  65. message: createMessage({
  66. role: 'assistant',
  67. content: [{ type: 'text', text: 'Ready.' }],
  68. source: { kind: 'model', provider: 'fixture', model: 'fixture' },
  69. }),
  70. }, { surfaceOp: 'append' })
  71. agent.session.append('step/end', { turn: 1, step: 1 })
  72. agent.session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
  73. await scaffold.ctx.sessions.flush(agent.session)
  74. await page.getByText('Ready.').waitFor({ timeout: 10_000 })
  75. }, 120_000)
  76. afterAll(async () => {
  77. await browser?.close()
  78. await scaffold?.close()
  79. })
  80. it('loads the roster and creates one shared task through generated Remote', async () => {
  81. onTestFailed(() => saveFailureShot(page, 'web-e2e-agent-team-panel'))
  82. const action = page.locator('[data-team-action]')
  83. await action.getByRole('button', { name: /Agent Team/iu }).click()
  84. await action.getByText('No shared tasks yet').waitFor()
  85. await action.getByText('lead').waitFor()
  86. await action.getByRole('button', { name: 'New task' }).click()
  87. await action.getByPlaceholder('Task subject').fill('Browser task')
  88. await action.getByPlaceholder('Task description').fill('Created through the assembled browser')
  89. await action.getByPlaceholder(/Write scopes/iu).fill('src/web')
  90. await action.getByRole('button', { name: 'Save' }).click()
  91. await action.getByText('Browser task').waitFor()
  92. const snapshot = await captureStableAria(page, '[data-team-action]', scaffold.workspaceCwd)
  93. await compareOrRefreshGolden(PANEL_EXPECTED, snapshot, MODE)
  94. expect(tripwire.pageErrors).toEqual([])
  95. expect(tripwire.warnings).toEqual([])
  96. }, 60_000)
  97. it.skipIf(MODE === 'record')('keeps the fixture inventory closed', async () => {
  98. await assertFixtureInventory(SNAPSHOT_DIR, ['task.expected.md'])
  99. })
  100. })