workspace-chat.spec.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { test, expect, type Page } from '@playwright/test'
  2. async function login(page: Page) {
  3. await page.goto('/conversations')
  4. await page.getByRole('textbox', { name: '账号', exact: true }).fill('fixture')
  5. await page.getByRole('textbox', { name: '密码', exact: true }).fill('fixture-pass')
  6. await page.getByRole('button', { name: '登录', exact: true }).click()
  7. await expect(page.getByRole('heading', { name: '还没有聊天' })).toBeVisible()
  8. }
  9. async function createAgent(page: Page, name: string) {
  10. await page.getByRole('button', { name: '+ 创建 Agent', exact: true }).click()
  11. const dialog = page.getByRole('dialog')
  12. await dialog.getByRole('textbox', { name: '名称', exact: true }).fill(name)
  13. await dialog
  14. .getByRole('textbox', { name: '角色提示词与规则', exact: true })
  15. .fill(`你是${name},每次回复给出验收证据。`)
  16. await dialog.getByRole('button', { name: `使用颜色 ${name === '产品经理' ? '#e78531' : '#0ea5c6'}`, exact: true }).click()
  17. await dialog.locator('.mascot-grid--shape button').filter({ hasText: name === '产品经理' ? '圆形' : '小三角' }).first().click()
  18. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  19. await expect(page.getByRole('heading', { name, exact: true })).toBeVisible()
  20. }
  21. test('created roles and editable teams share a durable chat list without plugin calls', async ({
  22. page,
  23. context,
  24. }, testInfo) => {
  25. const pluginCalls: string[] = []
  26. page.on('request', (r) => {
  27. if (r.url().includes('/plugins/yaoyao')) pluginCalls.push(r.url())
  28. })
  29. await login(page)
  30. await page.addInitScript(() => { Object.defineProperty(crypto, 'randomUUID', { value: undefined, configurable: true }) })
  31. await page.reload()
  32. await createAgent(page, '产品经理')
  33. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请说明角色职责')
  34. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  35. await expect(page.locator('.message--assistant')).toContainText('我是产品经理')
  36. await expect(page.locator('.message--assistant a').first()).toHaveAttribute(
  37. 'href',
  38. /\/api\/app\/files\/.+\/download/,
  39. )
  40. await page.getByRole('button', {name:'置顶聊天',exact:true}).click()
  41. await expect(page.getByRole('button', {name:'取消置顶',exact:true})).toBeVisible()
  42. const directURL = page.url()
  43. await createAgent(page, '开发工程师')
  44. await expect(page.locator('.message')).toHaveCount(0)
  45. await page.getByRole('button', { name: '+ 创建群聊', exact: true }).click()
  46. const dialog = page.getByRole('dialog')
  47. await dialog.getByRole('textbox', { name: '名称', exact: true }).fill('产品开发团队')
  48. await dialog.getByRole('checkbox', { name: '产品经理', exact: true }).check()
  49. await dialog.getByRole('checkbox', { name: '开发工程师', exact: true }).check()
  50. await dialog
  51. .getByRole('combobox', { name: '管理员', exact: true })
  52. .selectOption({ label: '产品经理' })
  53. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  54. await expect(page.getByRole('heading', { name: '产品开发团队', exact: true })).toBeVisible()
  55. await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(3)
  56. // Every cluster portrait must be the same portrait shown in that member's direct chat.
  57. const groupRow = page.locator('.desktop-sidebar .sidebar-item').filter({ hasText: '产品开发团队' })
  58. await expect(groupRow.locator('.team-avatar__member')).toHaveCount(2)
  59. for (const name of ['产品经理', '开发工程师']) {
  60. const portrait = `.agent-avatar[aria-label="${name} 的头像"]`
  61. const direct = page.locator('.desktop-sidebar .sidebar-item').filter({ hasText: name }).filter({ hasNot: page.locator('.team-avatar') }).locator(portrait)
  62. const member = groupRow.locator(portrait)
  63. await expect(member.locator('stop[offset="0.5"]')).toHaveAttribute('stop-color', await direct.locator('stop[offset="0.5"]').getAttribute('stop-color') || '')
  64. expect(await member.locator('.agent-avatar__body > :first-child').evaluate(el => el.tagName))
  65. .toBe(await direct.locator('.agent-avatar__body > :first-child').evaluate(el => el.tagName))
  66. }
  67. await expect(page.locator('.desktop-sidebar')).not.toContainText('话题')
  68. await expect(page.locator('.desktop-sidebar .sidebar-account-switcher')).not.toContainText(
  69. '通用助手',
  70. )
  71. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  72. await expect(dialog.getByRole('checkbox', { name: '产品经理', exact: true })).toBeDisabled()
  73. await expect(dialog.getByRole('checkbox', { name: '开发工程师', exact: true })).toBeEnabled()
  74. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  75. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请@开发工程师给出实现结果')
  76. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  77. await expect(page.locator('.message--assistant')).toHaveCount(3)
  78. await expect(page.locator('.message--assistant').nth(1)).toContainText('我是开发工程师')
  79. await expect(page.locator('.run-status')).toHaveCount(0)
  80. const second = await context.newPage()
  81. await second.goto(page.url())
  82. await expect(second.locator('.message--assistant')).toHaveCount(3)
  83. await page.screenshot({ path: testInfo.outputPath('mixed-chats.png'), fullPage: true })
  84. const groupURL=page.url()
  85. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  86. await dialog.getByRole('checkbox', { name: '开发工程师', exact: true }).uncheck()
  87. await expect(dialog.getByRole('checkbox', { name: '产品经理', exact: true })).toBeDisabled()
  88. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  89. await expect(groupRow.locator('.team-avatar__member')).toHaveCount(1)
  90. await expect(page.locator('.message--assistant')).toHaveCount(3)
  91. await expect(second.locator('.desktop-sidebar .sidebar-item').filter({ hasText: '产品开发团队' }).locator('.team-avatar__member')).toHaveCount(1)
  92. await page.reload()
  93. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  94. await expect(dialog.getByRole('checkbox', { name: '开发工程师', exact: true })).not.toBeChecked()
  95. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  96. await createAgent(page, '新成员')
  97. await page.goto(groupURL)
  98. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  99. await dialog.getByRole('checkbox', { name: '新成员', exact: true }).check()
  100. await dialog.getByRole('checkbox', { name: '产品经理', exact: true }).scrollIntoViewIfNeeded()
  101. await page.screenshot({ path: testInfo.outputPath('member-settings.png'), fullPage: true })
  102. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  103. await expect(groupRow.locator('.team-avatar__member')).toHaveCount(2)
  104. await expect(groupRow.locator('[aria-label="开发工程师 的头像"]')).toHaveCount(0)
  105. await expect(groupRow.locator('[aria-label="新成员 的头像"]')).toHaveCount(1)
  106. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请@新成员继续')
  107. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  108. await expect(page.locator('.message--assistant')).toHaveCount(6)
  109. await expect(page.locator('.message--assistant').nth(4)).toContainText('我是新成员')
  110. await page.getByRole('button',{name:'文件库',exact:true}).click()
  111. await page.getByRole('button',{name:'查看来源',exact:true}).first().click()
  112. await expect(page).toHaveURL(groupURL)
  113. await page.getByRole('button', { name: '归档聊天', exact: true }).click()
  114. await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(3)
  115. await page.getByRole('checkbox', { name: '显示已归档', exact: true }).first().check()
  116. await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(1)
  117. await page.getByRole('button', { name: '恢复聊天', exact: true }).click()
  118. await page.goto(directURL)
  119. await expect(page.locator('.message--assistant')).toHaveCount(1)
  120. await expect(page.locator('.message--assistant')).toContainText('我是产品经理')
  121. await page.getByRole('button', { name: '原生对话', exact: true }).click()
  122. await expect(page).toHaveURL(/\/chat/)
  123. expect(pluginCalls).toEqual([])
  124. await second.close()
  125. await page.goto('/conversations')
  126. await page.getByRole('button', { name: '+ 创建群聊', exact: true }).click()
  127. await expect(dialog.getByRole('button', { name: '信息收集团队', exact: true })).toBeDisabled()
  128. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  129. await createAgent(page, '模板成员四')
  130. await createAgent(page, '模板成员五')
  131. await page.getByRole('button', { name: '+ 创建群聊', exact: true }).click()
  132. for (const name of ['信息收集团队', '产品设计团队', '软件开发团队', '文案书写团队', '项目管理团队', '数据分析团队', '会议协作团队', '运维保障团队']) {
  133. await expect(dialog.getByRole('button', { name, exact: true })).toBeEnabled()
  134. }
  135. await page.screenshot({ path: testInfo.outputPath('restored-team-presets.png'), fullPage: true })
  136. await dialog.getByRole('button', { name: '产品设计团队', exact: true }).click()
  137. await expect(dialog.getByRole('textbox', { name: '名称', exact: true })).toHaveValue('产品设计团队')
  138. await dialog.getByRole('combobox', { name: '产品负责人对应的 Agent', exact: true }).selectOption({ label: '产品经理' })
  139. await dialog.getByRole('combobox', { name: '交互设计对应的 Agent', exact: true }).selectOption({ label: '开发工程师' })
  140. const [submitted] = await Promise.all([
  141. page.waitForRequest(r => r.method() === 'POST' && r.url().endsWith('/api/app/conversations')),
  142. dialog.getByRole('button', { name: '保存', exact: true }).click(),
  143. ])
  144. const payload = submitted.postDataJSON()
  145. expect(new Set(payload.memberIds).size).toBe(5)
  146. expect(Object.keys(payload.memberRoles)).toHaveLength(5)
  147. expect(payload.memberRoles[payload.administratorId].name).toBe('产品负责人')
  148. await expect(page.getByRole('heading', { name: '产品设计团队', exact: true })).toBeVisible()
  149. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  150. await expect(dialog.getByText('产品经理 · 产品负责人', { exact: false })).toBeVisible()
  151. await expect(dialog.getByText('开发工程师 · 交互设计', { exact: false })).toBeVisible()
  152. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  153. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请汇总设计方案')
  154. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  155. await expect(page.locator('.message--assistant')).toContainText('我是产品经理')
  156. const composer = page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行')
  157. await composer.fill('[hold-workspace] 正在执行的任务')
  158. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  159. await expect(page.getByRole('button', { name: '停止生成', exact: true })).toBeVisible()
  160. await composer.fill('后续排队任务')
  161. await expect(page.getByRole('button', { name: '发送消息', exact: true })).toBeEnabled()
  162. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  163. await expect(page.locator('.message--user').last()).toContainText('后续排队任务')
  164. const detail = await (await page.request.get(new URL(page.url()).pathname.replace('/conversations/', '/api/app/conversations/'))).json()
  165. expect(detail.conversation.queuedMessageCount).toBe(1)
  166. await page.request.post('http://127.0.0.1:19120/__release')
  167. await expect.poll(async () => (await (await page.request.get(`/api/app/conversations/${detail.conversation.id}`)).json()).conversation.activeRunId).toBeUndefined()
  168. expect(pluginCalls).toEqual([])
  169. })