workspace.spec.ts 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. import { expect, test } from '@playwright/test'
  2. const WIDE_DOCX_BASE64 = 'UEsDBAoAAAAIAKwmFF15bjPX6AAAAK0BAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbH1QyU7DMBD9FWuuKHHggBCK0wPLETiUDxjZk8SqN3nc0v49Tlt6QIXjzFv1+tXeO7GjzDYGBbdtB4KCjsaGScHn+rV5AMEFg0EXAyk4EMNq6NeHRCyqNrCCuZT0KCXrmTxyGxOFiowxeyz1zJNMqDc4kbzrunupYygUSlMWDxj6Zxpx64p42df3qUcmxyCeTsQlSwGm5KzGUnG5C+ZXSnNOaKvyyOHZJr6pBJBXExbk74Cz7r0Ok60h8YG5vKGvLPkVs5Em6q2vyvZ/mys94zhaTRf94pZy1MRcF/euvSAebfjpL49zD99QSwMECgAAAAAArCYUXQAAAAAAAAAAAAAAAAYAAABfcmVscy9QSwMECgAAAAgArCYUXZv9N+qtAAAAKQEAAAsAAABfcmVscy8ucmVsc43POw7CMAwG4KtE3mlaBoRQ0y4IqSsqB7ASN61oHkrCo7cnAwNFDIy2f3+W6/ZpZnanECdnBVRFCYysdGqyWsClP232wGJCq3B2lgQsFKFt6jPNmPJKHCcfWTZsFDCm5A+cRzmSwVg4TzZPBhcMplwGzT3KK2ri27Lc8fBpwNpknRIQOlUB6xdP/9huGCZJRydvhmz6ceIrkWUMmpKAhwuKq3e7yCzwpuarF5sXUEsDBAoAAAAAAKwmFF0AAAAAAAAAAAAAAAAFAAAAd29yZC9QSwMECgAAAAgArCYUXalT+9hjAQAABwMAABEAAAB3b3JkL2RvY3VtZW50LnhtbKVSW0/CMBT+K03fpXMBJYRBFAaaYDSKwdeydluTrW3awsBfb7uVDYwmJr6cc75z+c6lHU8PZQH2VGkmeASvewEElCeCMJ5F8H29uBpCoA3mBBeC0wgeqYbTybgaEZHsSsoNsARcj6oI5sbIEUI6yWmJdU9Iym0sFarExkKVoUooIpVIqNaWvyxQGAQ3qMSMQ0e5FeTotHRCOWEmG0YomD/PPoBUdM9oNUbO7aSqZZ1stoVXL8obG1C5oa6DYWB3sq6jtOOTA4bIZ6zwUexMG0rZgRIXRJdES8WIMzOrZ6JoaAd9y4p+daOLStNQJY30xMnmrOT7fKhLPD/GKl6swfrufhWDeL6MfzgF6vr8u9vr4/Lhb+1QsyNqH0LTxHjC7O3Tv0QY9uveubUHw76/n8yesHITCRnB27DOUCzLTYu2whhRtrCgaRfLKSZURbAGqRCmBdnOeNBseBoJnf4Z6v7w5AtQSwECFAAKAAAACACsJhRdeW4z1+gAAACtAQAAEwAAAAAAAAAAAAAAAAAAAAAAW0NvbnRlbnRfVHlwZXNdLnhtbFBLAQIUAAoAAAAAAKwmFF0AAAAAAAAAAAAAAAAGAAAAAAAAAAAAEAAAABkBAABfcmVscy9QSwECFAAKAAAACACsJhRdm/036q0AAAApAQAACwAAAAAAAAAAAAAAAAA9AQAAX3JlbHMvLnJlbHNQSwECFAAKAAAAAACsJhRdAAAAAAAAAAAAAAAABQAAAAAAAAAAABAAAAATAgAAd29yZC9QSwECFAAKAAAACACsJhRdqVP72GMBAAAHAwAAEQAAAAAAAAAAAAAAAAA2AgAAd29yZC9kb2N1bWVudC54bWxQSwUGAAAAAAUABQAgAQAAyAMAAAAA'
  3. const E2E_PASSWORD = 'e2e-password'
  4. test.beforeAll(async ({ request }) => {
  5. const signIn = async (password: string) => {
  6. const initial = await request.get('/api/app/bootstrap')
  7. const initialBody = await initial.json() as { csrfToken: string }
  8. return request.post('/api/app/login', {
  9. headers: { Origin: 'http://127.0.0.1:18801', 'X-CSRF-Token': initialBody.csrfToken },
  10. data: { username: 'admin', password },
  11. })
  12. }
  13. let login = await signIn(E2E_PASSWORD)
  14. if (!login.ok()) login = await signIn('admin')
  15. expect(login.ok()).toBe(true)
  16. const loginBody = await login.json() as { csrfToken: string; user: { mustChangePassword?: boolean } }
  17. if (loginBody.user.mustChangePassword) {
  18. const changed = await request.put('/api/app/account/credentials', {
  19. headers: { Origin: 'http://127.0.0.1:18801', 'X-CSRF-Token': loginBody.csrfToken },
  20. data: { currentPassword: 'admin', newPassword: E2E_PASSWORD, username: 'admin' },
  21. })
  22. expect(changed.ok()).toBe(true)
  23. }
  24. })
  25. test.beforeEach(async ({ page }) => {
  26. await page.goto('/chat')
  27. if (await page.getByRole('heading', { name: '登录夭夭' }).isVisible()) {
  28. await page.getByLabel('账号').fill('admin')
  29. await page.getByLabel('密码').fill(E2E_PASSWORD)
  30. await page.getByRole('button', { name: '登录' }).click()
  31. }
  32. await expect(page.getByRole('navigation')).toBeVisible()
  33. })
  34. test('explains optional upstream credentials without blocking a ready connection', async ({ page }, testInfo) => {
  35. await page.getByRole('button', { name: /^(打开设置中心|设置与模式)$/ }).first().click()
  36. if (await page.getByRole('menuitem', { name: '进入设置', exact: true }).isVisible()) await page.getByRole('menuitem', { name: '进入设置', exact: true }).click()
  37. const dialog = page.getByRole('dialog', { name: '设置中心' })
  38. await dialog.getByRole('button', { name: 'Hermes 连接', exact: true }).click()
  39. await expect(dialog.locator('[aria-label="Hermes 连接状态"]')).toBeVisible()
  40. await expect(dialog.getByText('9119 连接正常', { exact: true })).toBeVisible()
  41. await expect(dialog.getByRole('heading', { name: '服务账号(按需配置)' })).toBeVisible()
  42. await expect(dialog.getByText(/无需配置用户名和密码/)).toBeVisible()
  43. await expect(dialog.locator('input[name="upstream-username"]')).toHaveValue('')
  44. await expect(dialog.locator('input[name="upstream-password"]')).toHaveValue('')
  45. await page.screenshot({ path: testInfo.outputPath('loopback-authorization.png') })
  46. })
  47. test('uses the yaoyao-webui grouped model picker without a mobile full-screen sheet', async ({ page }) => {
  48. await page.goto('/chat/session-demo')
  49. await page.locator('.composer-tool--model').click()
  50. const dialog = page.getByRole('dialog', { name: '选择模型' })
  51. await expect(dialog).toBeVisible()
  52. await expect(dialog.getByPlaceholder('搜索模型名称或 ID')).toBeFocused()
  53. await expect(dialog.locator('.model-dialog__group-header')).toContainText('OpenAI')
  54. await expect(dialog.locator('.model-dialog__item--active')).toContainText('gpt-5.6')
  55. const desktopBox = await dialog.boundingBox()
  56. expect(desktopBox?.width).toBeGreaterThanOrEqual(450)
  57. expect(desktopBox?.width).toBeLessThanOrEqual(480)
  58. await dialog.getByPlaceholder('搜索模型名称或 ID').fill('gpt-5.5')
  59. await expect(dialog.locator('.model-dialog__item')).toHaveCount(1)
  60. await page.keyboard.press('Escape')
  61. await expect(dialog).toBeHidden()
  62. await page.setViewportSize({ width: 390, height: 844 })
  63. await page.locator('.composer-tool--model').click()
  64. const mobileBox = await dialog.boundingBox()
  65. expect(mobileBox?.x).toBeGreaterThanOrEqual(12)
  66. expect(mobileBox?.width).toBeLessThanOrEqual(366)
  67. expect(mobileBox?.height).toBeLessThan(820)
  68. })
  69. test('navigates every 9119 workspace without blank transitions', async ({ page }) => {
  70. const consoleErrors: string[] = []
  71. page.on('console', message => { if (message.type() === 'error') consoleErrors.push(message.text()) })
  72. await expect(page.getByRole('option').first()).toContainText('夭夭 Web 验收会话')
  73. await expect(page.getByRole('option').first()).toContainText('夭夭')
  74. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toBeVisible()
  75. await page.getByRole('button', { name: '团队' }).click()
  76. await expect(page.getByRole('heading', { name: '设计验收' })).toBeVisible()
  77. await expect(page.getByRole('button', { name: '对话', exact: true })).toBeVisible()
  78. await expect(page.getByRole('button', { name: '团队', exact: true })).toHaveCount(0)
  79. await expect(page.getByRole('button', { name: '文件库', exact: true })).toHaveCount(0)
  80. await expect(page.getByRole('button', { name: '产物', exact: true })).toHaveCount(0)
  81. await expect(page.getByRole('button', { name: '新建团队' })).toBeVisible()
  82. await page.mouse.move(1200, 20)
  83. await expect(page.getByRole('button', { name: '新建团队' })).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  84. await expect(page.getByRole('button', { name: '新建团队' })).toHaveCSS('font-weight', '650')
  85. await expect(page.getByRole('button', { name: '管理团队', exact: true })).toBeVisible()
  86. await expect(page.getByRole('button', { name: '发送消息' })).toBeVisible()
  87. await page.goto('/files')
  88. await expect(page.getByRole('heading', { name: '文件库', exact: true }).last()).toBeVisible()
  89. const fileSidebar = page.locator('.desktop-sidebar')
  90. await expect(fileSidebar.getByRole('button', { name: '新建聊天' })).toBeVisible()
  91. await expect(fileSidebar.getByRole('button', { name: '搜索', exact: true })).toHaveCount(0)
  92. const compactControlHeights = await fileSidebar.locator('.sidebar-search-trigger, .sidebar-primary-action button, .sidebar-feature-nav button').evaluateAll(elements => (
  93. elements.map(element => element.getBoundingClientRect().height)
  94. ))
  95. expect(compactControlHeights.length).toBeGreaterThanOrEqual(3)
  96. expect(Math.max(...compactControlHeights)).toBeLessThanOrEqual(36)
  97. await expect(page.getByText('demo-report.pdf')).toBeVisible()
  98. const firstFileCard = page.locator('.library-grid article').first()
  99. const cardGeometry = await firstFileCard.evaluate(element => {
  100. const card = element.getBoundingClientRect()
  101. const preview = element.querySelector('.library-thumb')?.getBoundingClientRect()
  102. return { width: card.width, previewHeight: preview?.height || 0 }
  103. })
  104. expect(cardGeometry.width).toBeGreaterThanOrEqual(220)
  105. expect(cardGeometry.previewHeight).toBe(154)
  106. await page.getByText('demo-report.pdf').click()
  107. await expect(page.getByRole('dialog', { name: /预览 demo-report.pdf/ })).toBeVisible()
  108. await expect(page.locator('.preview-meta')).toHaveCount(0)
  109. const previewDialog = page.getByRole('dialog', { name: /预览 demo-report.pdf/ })
  110. await expect(previewDialog.getByRole('link', { name: '下载' })).toBeVisible()
  111. await expect(previewDialog.getByRole('button', { name: '加入输入框' })).toBeVisible()
  112. await expect(previewDialog.locator('.preview-close')).toBeVisible()
  113. const modalHeight = await page.locator('.preview-modal').evaluate(element => element.getBoundingClientRect().height)
  114. expect(modalHeight).toBeGreaterThan(600)
  115. await previewDialog.locator('.preview-close').click()
  116. await fileSidebar.getByRole('button', { name: '新建聊天' }).click()
  117. await expect(page).toHaveURL(/\/chat\/draft-[^?]+\?profile=yaoyao/)
  118. await page.goto('/artifacts')
  119. await expect(page).toHaveURL(/\/chat$/)
  120. await expect(page.getByRole('button', { name: '产物', exact: true })).toHaveCount(0)
  121. expect(consoleErrors).toEqual([])
  122. })
  123. test('uses the active session or group title in the browser title', async ({ page }) => {
  124. await page.goto('/chat/session-demo?profile=yaoyao')
  125. await expect(page).toHaveTitle('夭夭 Web 验收会话 · 夭夭')
  126. await page.goto('/groups/group-demo')
  127. await expect(page).toHaveTitle('设计与工程协作 · 夭夭')
  128. })
  129. test('uses split search for topics, teams, and archived content', async ({ page }) => {
  130. await page.getByRole('button', { name: '团队' }).click()
  131. await expect(page.getByRole('heading', { name: '设计验收' })).toBeVisible()
  132. await page.locator('.desktop-sidebar').getByRole('button', { name: '搜索', exact: true }).click()
  133. const searchDialog = page.getByRole('dialog', { name: '搜索话题、团队或归档' })
  134. await expect(searchDialog).toBeVisible()
  135. await expect(searchDialog.getByRole('navigation', { name: '搜索范围' })).toContainText('设计与工程协作')
  136. await searchDialog.getByRole('searchbox', { name: '搜索全部' }).fill('发布检查')
  137. const topicResult = searchDialog.getByRole('option', { name: /发布检查/ })
  138. await expect(topicResult).toBeVisible()
  139. await topicResult.click()
  140. await expect(page).toHaveURL(/\/groups\/22222222-2222-4222-8222-222222222222\/88888888-8888-4888-8888-888888888888$/)
  141. await expect(searchDialog).toBeHidden()
  142. })
  143. test('shows member mascot clusters in the list and during creation', async ({ page }) => {
  144. await page.getByRole('button', { name: '团队' }).click()
  145. const topicRow = page.locator('[data-sidebar-id="topic:22222222-2222-4222-8222-222222222222:77777777-7777-4777-8777-777777777777"]')
  146. const roomAvatar = topicRow.getByRole('img', { name: '设计验收团队头像' })
  147. await expect(roomAvatar).toBeVisible()
  148. await expect(roomAvatar.locator('.team-avatar__member')).toHaveCount(3)
  149. const releaseTopicAvatar = page.locator('[data-sidebar-id="topic:22222222-2222-4222-8222-222222222222:88888888-8888-4888-8888-888888888888"]').first().locator('.team-avatar__member')
  150. await expect(releaseTopicAvatar).toHaveCount(3)
  151. await page.getByRole('button', { name: '新建团队' }).click()
  152. const dialog = page.getByRole('dialog', { name: '新建团队' })
  153. await expect(dialog.getByRole('region', { name: '团队预设' })).toBeVisible()
  154. await expect(dialog.getByRole('button', { name: /信息收集团队/ })).toBeDisabled()
  155. await expect(dialog.getByRole('button', { name: /信息收集团队/ })).toContainText('还缺 2 人')
  156. await expect(dialog.getByText('由成员的动态角色自动组成')).toBeVisible()
  157. await expect(dialog.getByRole('button', { name: '成员组合' })).toBeVisible()
  158. await expect(dialog.locator('.team-avatar__member')).toHaveCount(3)
  159. await expect(dialog.getByRole('button', { name: '上传图片' })).toBeVisible()
  160. await dialog.locator('input[type="file"]').setInputFiles('public/brand/AppIcon-1024.png')
  161. await expect(dialog.getByText('使用上传的图片')).toBeVisible()
  162. await expect(dialog.getByRole('img', { name: '团队团队头像' }).locator('img')).toBeVisible()
  163. })
  164. test('updates an existing team avatar from the Web manager', async ({ page }) => {
  165. await page.getByRole('button', { name: '团队' }).click()
  166. await page.getByRole('button', { name: '管理团队', exact: true }).click()
  167. const manager = page.locator('.group-manager')
  168. const preview = manager.getByRole('img', { name: '设计与工程协作团队头像' })
  169. await expect(preview.locator('.team-avatar__member')).toHaveCount(3)
  170. const uploadRequest = page.waitForRequest(request => request.method() === 'PATCH' && request.url().endsWith('/rooms/22222222-2222-4222-8222-222222222222'))
  171. await manager.locator('input[type="file"]').setInputFiles('public/brand/AppIcon-1024.png')
  172. expect((await uploadRequest).postDataJSON().avatar).toMatch(/^data:image\/png;base64,/)
  173. await expect(manager.getByText('使用上传的图片')).toBeVisible()
  174. await expect(preview.locator('img')).toBeVisible()
  175. const dynamicRequest = page.waitForRequest(request => request.method() === 'PATCH' && request.url().endsWith('/rooms/22222222-2222-4222-8222-222222222222'))
  176. await manager.getByRole('button', { name: '成员组合' }).click()
  177. expect((await dynamicRequest).postDataJSON()).toMatchObject({ avatar: '' })
  178. await expect(manager.getByText('由成员的动态角色自动组成')).toBeVisible()
  179. await expect(preview.locator('.team-avatar__member')).toHaveCount(3)
  180. })
  181. test('selects one protocol v5 host independently from no-mention replies', async ({ page }) => {
  182. await page.getByRole('button', { name: '团队' }).click()
  183. await expect(page.locator('.group-host-chip')).toHaveText('管理员 夭夭')
  184. await page.getByRole('button', { name: '新建团队' }).click()
  185. const createDialog = page.getByRole('dialog', { name: '新建团队' })
  186. await createDialog.getByRole('button', { name: /yaoer/ }).click()
  187. await createDialog.getByLabel('管理员').selectOption({ label: '瑶儿' })
  188. await expect(createDialog.getByLabel('所有成员无需 @ 也回复')).toBeChecked()
  189. await createDialog.getByRole('button', { name: '关闭' }).click()
  190. await page.getByRole('button', { name: '管理团队', exact: true }).click()
  191. const manager = page.locator('.group-manager')
  192. await expect(manager.getByLabel('管理员')).toHaveValue('33333333-3333-4333-8333-333333333333')
  193. const promoteRequest = page.waitForRequest(request => request.method() === 'PATCH' && request.url().endsWith('/agents/34343434-3434-4434-8434-343434343434'))
  194. await manager.getByLabel('管理员').selectOption({ label: '瑶儿' })
  195. expect((await promoteRequest).postDataJSON()).toMatchObject({ isHost: true })
  196. await expect(manager.locator('article').filter({ hasText: '瑶儿' }).getByText('管理员', { exact: true })).toBeVisible()
  197. await expect(page.locator('.group-host-chip')).toHaveText('管理员 瑶儿')
  198. const restoreRequest = page.waitForRequest(request => request.method() === 'PATCH' && request.url().endsWith('/agents/33333333-3333-4333-8333-333333333333'))
  199. await manager.getByLabel('管理员').selectOption({ label: '夭夭' })
  200. expect((await restoreRequest).postDataJSON()).toMatchObject({ isHost: true })
  201. await expect(page.locator('.group-host-chip')).toHaveText('管理员 夭夭')
  202. })
  203. test('edits every protocol v5 Agent setting with one inspector close control', async ({ page }) => {
  204. await page.getByRole('button', { name: '团队' }).click()
  205. await expect(page.getByRole('heading', { name: '设计验收' })).toBeVisible()
  206. await page.getByRole('button', { name: '管理团队', exact: true }).click()
  207. await expect(page.getByRole('button', { name: '关闭团队管理' })).toHaveCount(1)
  208. await expect(page.getByRole('button', { name: '关闭预览' })).toHaveCount(0)
  209. await expect(page.getByLabel('最多回复轮数')).toHaveValue('-1')
  210. await page.getByRole('button', { name: '设置瑶儿' }).click()
  211. const editor = page.getByRole('dialog', { name: '瑶儿 Agent 设置' })
  212. await expect(page.locator('.group-manager .agent-editor')).toHaveCount(0)
  213. await expect(editor.getByLabel('群内名称')).toHaveValue('瑶儿')
  214. await expect(editor.getByLabel('职责说明')).toHaveValue('评审 Agent')
  215. await expect(editor.getByLabel('模型')).toHaveValue(JSON.stringify(['openai', 'gpt-5.6']))
  216. await expect(editor.getByLabel('推理强度')).toHaveValue('medium')
  217. await expect(editor.getByLabel('快速模式')).toHaveValue('false')
  218. await editor.getByLabel('群内名称').fill('所有人')
  219. const rejectedResponse = page.waitForResponse(response => response.request().method() === 'PATCH' && /\/api\/app\/groups\/rooms\/[^/]+\/agents\/[^/]+$/.test(new URL(response.url()).pathname))
  220. await editor.getByRole('button', { name: '保存 Agent 设置' }).click()
  221. expect((await rejectedResponse).status()).toBe(409)
  222. await expect(editor.getByRole('alert')).toContainText('成员名称不能使用“所有人”')
  223. await editor.getByRole('button', { name: '关闭 Agent 设置' }).click()
  224. await page.getByRole('button', { name: '设置瑶儿' }).click()
  225. await expect(editor.getByLabel('群内名称')).toHaveValue('所有人')
  226. await editor.getByLabel('群内名称').fill('瑶儿')
  227. await editor.getByLabel('模型').selectOption(JSON.stringify(['openai', 'gpt-5.5']))
  228. await editor.getByLabel('推理强度').selectOption('xhigh')
  229. await editor.getByLabel('快速模式').selectOption('true')
  230. await editor.getByLabel('无需 @ 也回复').check()
  231. const updateRequest = page.waitForRequest(request => request.method() === 'PATCH' && /\/api\/app\/groups\/rooms\/[^/]+\/agents\/[^/]+$/.test(new URL(request.url()).pathname))
  232. await editor.getByRole('button', { name: '保存 Agent 设置' }).click()
  233. expect((await updateRequest).postDataJSON()).toMatchObject({
  234. model: 'gpt-5.5', provider: 'openai', reasoningEffort: 'xhigh', fastMode: true, replyWithoutMention: true,
  235. })
  236. await expect(editor.getByLabel('模型')).toHaveValue(JSON.stringify(['openai', 'gpt-5.5']))
  237. await editor.getByLabel('模型').selectOption(JSON.stringify(['openai', 'gpt-5.6']))
  238. await editor.getByLabel('推理强度').selectOption('medium')
  239. await editor.getByLabel('快速模式').selectOption('false')
  240. await editor.getByLabel('无需 @ 也回复').uncheck()
  241. const restoreResponse = page.waitForResponse(response => response.request().method() === 'PATCH' && /\/api\/app\/groups\/rooms\/[^/]+\/agents\/[^/]+$/.test(new URL(response.url()).pathname))
  242. await editor.getByRole('button', { name: '保存 Agent 设置' }).click()
  243. expect((await restoreResponse).status()).toBe(200)
  244. })
  245. test('pins the named Agent typing status above the group composer', async ({ page }) => {
  246. await page.getByRole('button', { name: '团队' }).click()
  247. const composer = page.locator('.composer-area')
  248. await page.getByRole('textbox', { name: '发消息给团队,输入 @ 提及 Agent' }).fill('@夭夭 检查输入状态')
  249. await page.getByRole('button', { name: '发送消息' }).click()
  250. const typing = composer.getByRole('status', { name: 'Agent 输入状态' })
  251. await page.waitForTimeout(250)
  252. await expect(typing).toHaveCount(0)
  253. await expect(typing).toHaveText('夭夭正在输入…')
  254. await expect(page.locator('.message-stack .thinking-indicator')).toHaveCount(0)
  255. const typingBox = await typing.boundingBox()
  256. const shellBox = await composer.locator('.composer-shell').boundingBox()
  257. expect(typingBox?.y).toBeLessThan(shellBox?.y ?? 0)
  258. await expect(typing).toHaveCount(0, { timeout: 4_000 })
  259. })
  260. test('reconnects the group event stream after an unexpected close', async ({ page }) => {
  261. await page.getByRole('button', { name: '团队' }).click()
  262. await expect(page.getByText('已同步', { exact: true })).toBeVisible()
  263. const before = await (await page.request.get('http://127.0.0.1:19119/__test/group-connections')).json() as { count: number }
  264. await page.request.post('http://127.0.0.1:19119/__test/groups/disconnect')
  265. await expect.poll(async () => {
  266. const value = await (await page.request.get('http://127.0.0.1:19119/__test/group-connections')).json() as { count: number }
  267. return value.count
  268. }, { timeout: 5_000 }).toBeGreaterThan(before.count)
  269. await expect(page.getByText('已同步', { exact: true })).toBeVisible()
  270. })
  271. test('recovers the group page after its initial upstream connection fails', async ({ page }) => {
  272. await page.request.post('http://127.0.0.1:19119/__test/groups/availability', { data: { available: false } })
  273. await page.getByRole('button', { name: '团队' }).click()
  274. await expect(page.getByRole('heading', { name: '团队服务暂不可用' })).toBeVisible()
  275. await page.request.post('http://127.0.0.1:19119/__test/groups/availability', { data: { available: true } })
  276. await expect(page.getByRole('heading', { name: '设计验收' })).toBeVisible({ timeout: 5_000 })
  277. })
  278. test('previews an octet-stream Markdown file from the file library', async ({ page }) => {
  279. await page.route('**/api/app/files**', async route => {
  280. const url = new URL(route.request().url())
  281. if (url.pathname === '/api/app/files') {
  282. await route.fulfill({
  283. status: 200,
  284. contentType: 'application/json',
  285. body: JSON.stringify({
  286. profile: 'yaoyao',
  287. items: [{
  288. id: 'markdown-file',
  289. path: '/tmp/版本说明.md',
  290. name: '版本说明.md',
  291. extension: '.md',
  292. mimeType: 'application/octet-stream',
  293. size: 48,
  294. modifiedAt: Date.now() / 1000,
  295. exists: true,
  296. origins: [{ profile: 'yaoyao', sessionId: 'session-demo', sessionTitle: '夭夭 Web 验收会话' }],
  297. }, {
  298. id: 'empty-markdown-file',
  299. path: '/tmp/空白说明.md',
  300. name: '空白说明.md',
  301. extension: 'md',
  302. mimeType: 'application/octet-stream',
  303. size: 0,
  304. modifiedAt: Date.now() / 1000,
  305. exists: true,
  306. origins: [{ profile: 'yaoyao', sessionId: 'session-demo', sessionTitle: '夭夭 Web 验收会话' }],
  307. }],
  308. nextCursor: null,
  309. total: 2,
  310. }),
  311. })
  312. return
  313. }
  314. if (url.pathname === '/api/app/files/markdown-file/preview') {
  315. await route.fulfill({
  316. status: 200,
  317. contentType: 'application/octet-stream',
  318. body: '# 版本说明\n\n- Markdown 预览已恢复',
  319. })
  320. return
  321. }
  322. if (url.pathname === '/api/app/files/empty-markdown-file/preview') {
  323. await route.fulfill({ status: 200, contentType: 'application/octet-stream', body: '' })
  324. return
  325. }
  326. await route.continue()
  327. })
  328. await page.goto('/files')
  329. await page.getByText('版本说明.md', { exact: true }).click()
  330. const dialog = page.getByRole('dialog', { name: '预览 版本说明.md' })
  331. await expect(dialog.locator('.preview-text h1')).toHaveText('版本说明')
  332. await expect(dialog.getByText('Markdown 预览已恢复', { exact: true })).toBeVisible()
  333. await dialog.locator('.preview-close').click()
  334. await page.getByText('空白说明.md', { exact: true }).click()
  335. const emptyDialog = page.getByRole('dialog', { name: '预览 空白说明.md' })
  336. await expect(emptyDialog.locator('.preview-text')).toBeVisible()
  337. await expect(emptyDialog.locator('.preview-unavailable')).toHaveCount(0)
  338. })
  339. test('keeps DOCX body at 36px inset with zero canvas margin', async ({ page }) => {
  340. await page.setViewportSize({ width: 620, height: 760 })
  341. await page.route('**/api/app/files**', async route => {
  342. const url = new URL(route.request().url())
  343. if (url.pathname === '/api/app/files') {
  344. await route.fulfill({
  345. status: 200,
  346. contentType: 'application/json',
  347. body: JSON.stringify({
  348. profile: 'yaoyao',
  349. items: [{
  350. id: 'wide-docx-file',
  351. path: '/tmp/宽版文档.docx',
  352. name: '宽版文档.docx',
  353. extension: 'docx',
  354. mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  355. size: 1024,
  356. modifiedAt: Date.now() / 1000,
  357. exists: true,
  358. origins: [{ profile: 'yaoyao', sessionId: 'session-demo', sessionTitle: '夭夭 Web 验收会话' }],
  359. }],
  360. nextCursor: null,
  361. total: 1,
  362. }),
  363. })
  364. return
  365. }
  366. if (url.pathname === '/api/app/files/wide-docx-file/preview') {
  367. await route.fulfill({
  368. status: 200,
  369. contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  370. body: Buffer.from(WIDE_DOCX_BASE64, 'base64'),
  371. })
  372. return
  373. }
  374. await route.continue()
  375. })
  376. await page.goto('/files')
  377. await page.getByText('宽版文档.docx', { exact: true }).click()
  378. const dialog = page.getByRole('dialog', { name: '预览 宽版文档.docx' })
  379. const office = dialog.locator('.preview-office')
  380. await expect(office.locator('section.docx')).toBeVisible()
  381. const geometry = await office.evaluate(element => {
  382. const wrapper = element.querySelector<HTMLElement>('.docx-wrapper')!
  383. const pageElement = element.querySelector<HTMLElement>('section.docx')!
  384. const article = pageElement.querySelector<HTMLElement>('article')!
  385. const table = article.querySelector<HTMLElement>('table')!
  386. const officeRect = element.getBoundingClientRect()
  387. const pageRect = pageElement.getBoundingClientRect()
  388. const officeStyle = getComputedStyle(element)
  389. const wrapperStyle = getComputedStyle(wrapper)
  390. const articleStyle = getComputedStyle(article)
  391. return {
  392. officeLeft: officeRect.left,
  393. pageLeft: pageRect.left,
  394. pageWidth: pageRect.width,
  395. clientWidth: element.clientWidth,
  396. scrollWidth: element.scrollWidth,
  397. wrapperWidth: wrapper.getBoundingClientRect().width,
  398. articlePaddingTop: Number.parseFloat(articleStyle.paddingTop),
  399. articlePaddingLeft: Number.parseFloat(articleStyle.paddingLeft),
  400. articlePaddingRight: Number.parseFloat(articleStyle.paddingRight),
  401. tableLeft: table.getBoundingClientRect().left,
  402. tableRight: table.getBoundingClientRect().right,
  403. officeBackground: officeStyle.backgroundColor,
  404. wrapperBackground: wrapperStyle.backgroundColor,
  405. wrapperPaddingTop: Number.parseFloat(wrapperStyle.paddingTop),
  406. wrapperPaddingLeft: Number.parseFloat(wrapperStyle.paddingLeft),
  407. wrapperPaddingRight: Number.parseFloat(wrapperStyle.paddingRight),
  408. }
  409. })
  410. expect(geometry.pageWidth).toBeLessThanOrEqual(geometry.clientWidth)
  411. expect(geometry.pageLeft).toBeGreaterThanOrEqual(geometry.officeLeft)
  412. expect(geometry.scrollWidth).toBeLessThanOrEqual(geometry.clientWidth + 1)
  413. expect(Math.abs(geometry.wrapperWidth - geometry.clientWidth)).toBeLessThan(1)
  414. expect(geometry.articlePaddingTop).toBe(36)
  415. expect(geometry.articlePaddingLeft).toBe(36)
  416. expect(geometry.articlePaddingRight).toBe(36)
  417. expect(geometry.tableLeft).toBeGreaterThanOrEqual(geometry.pageLeft - 1)
  418. expect(geometry.tableRight).toBeLessThanOrEqual(geometry.pageLeft + geometry.pageWidth + 1)
  419. expect(geometry.officeBackground).toBe('rgb(255, 255, 255)')
  420. expect(geometry.wrapperBackground).toBe('rgb(255, 255, 255)')
  421. expect(geometry.wrapperPaddingTop).toBe(0)
  422. expect(geometry.wrapperPaddingLeft).toBe(0)
  423. expect(geometry.wrapperPaddingRight).toBe(0)
  424. await page.setViewportSize({ width: 930, height: 760 })
  425. const centered = await office.evaluate(element => {
  426. const pageElement = element.querySelector<HTMLElement>('section.docx')!
  427. const officeRect = element.getBoundingClientRect()
  428. const pageRect = pageElement.getBoundingClientRect()
  429. return {
  430. pageWidth: pageRect.width,
  431. clientWidth: element.clientWidth,
  432. leftGap: pageRect.left - officeRect.left,
  433. rightGap: officeRect.right - pageRect.right,
  434. }
  435. })
  436. expect(centered.pageWidth).toBeLessThan(centered.clientWidth)
  437. expect(centered.leftGap).toBeGreaterThanOrEqual(18)
  438. expect(centered.rightGap).toBeGreaterThanOrEqual(18)
  439. expect(Math.abs(centered.leftGap - centered.rightGap)).toBeLessThanOrEqual(12)
  440. })
  441. test('keeps pins first and loads the next session page at the list bottom', async ({ page }) => {
  442. const sidebar = page.locator('.desktop-sidebar')
  443. const items = sidebar.locator('.sidebar-list [role="option"]')
  444. await expect(items).toHaveCount(100)
  445. await expect(items.first()).toContainText('夭夭 Web 验收会话')
  446. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toBeVisible()
  447. const list = sidebar.locator('.sidebar-list')
  448. await list.evaluate(element => {
  449. element.scrollTop = element.scrollHeight
  450. element.dispatchEvent(new Event('scroll'))
  451. })
  452. await expect(items).toHaveCount(103)
  453. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toHaveCount(0)
  454. })
  455. test('switches the composer model to the selected historical session model', async ({ page }) => {
  456. await page.goto('/chat/session-demo?profile=yaoyao')
  457. await expect(page.locator('.composer-tool--model')).toContainText('gpt-5.6')
  458. await page.getByRole('option', { name: /第二个会话/ }).click()
  459. await expect(page.locator('.composer-tool--model')).toContainText('gpt-5.5')
  460. })
  461. test('restores a routed conversation even when unread-count refresh fails', async ({ page }) => {
  462. await page.route('**/api/app/sessions/unread*', async route => {
  463. await route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'unread unavailable' }) })
  464. })
  465. await page.goto('/chat/session-demo')
  466. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  467. await page.reload()
  468. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  469. })
  470. test('opens a conversation even when marking it read is unsupported', async ({ page }) => {
  471. const pageErrors: string[] = []
  472. page.on('pageerror', error => pageErrors.push(error.message))
  473. await page.route('**/api/app/sessions/unread/*', async route => {
  474. await route.fulfill({ status: 405, contentType: 'application/json', body: JSON.stringify({ error: 'Method Not Allowed' }) })
  475. })
  476. await page.getByRole('option').filter({ hasText: '第二个会话' }).click()
  477. await expect(page).toHaveURL(/\/chat\/session-second\?profile=yaoyao/)
  478. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  479. expect(pageErrors).toEqual([])
  480. })
  481. test('syncs the blue fast-mode shortcut with the iOS-compatible session config', async ({ page }) => {
  482. await page.request.post('http://127.0.0.1:19119/__test/rpc-requests/reset')
  483. await page.goto('/chat/session-demo')
  484. const fast = page.getByRole('button', { name: '快速模式:已关闭' })
  485. await expect(fast).toHaveAttribute('aria-pressed', 'false')
  486. await fast.click()
  487. const enabled = page.getByRole('button', { name: '快速模式:已开启' })
  488. await expect(enabled).toHaveAttribute('aria-pressed', 'true')
  489. await expect(enabled).toHaveCSS('color', 'rgb(22, 119, 255)')
  490. await page.getByRole('textbox', { name: '输入消息,Enter 发送,Shift + Enter 换行' }).fill('使用快速模式')
  491. await page.getByRole('button', { name: '发送消息' }).click()
  492. await expect(page.getByText('这是来自假 Gateway 的流式回复。', { exact: true })).toBeVisible()
  493. const payload = await (await page.request.get('http://127.0.0.1:19119/__test/rpc-requests')).json() as { requests: Array<{ method: string; params: Record<string, unknown> }> }
  494. const fastConfigIndex = payload.requests.findIndex(request => request.method === 'config.set' && request.params.key === 'fast')
  495. const promptIndex = payload.requests.findIndex(request => request.method === 'prompt.submit')
  496. expect(fastConfigIndex).toBeGreaterThanOrEqual(0)
  497. expect(promptIndex).toBeGreaterThan(fastConfigIndex)
  498. expect(payload.requests[fastConfigIndex]?.params).toMatchObject({ key: 'fast', value: 'fast', scope: 'session' })
  499. await enabled.click()
  500. await expect(page.getByRole('button', { name: '快速模式:已关闭' })).toHaveAttribute('aria-pressed', 'false')
  501. await expect.poll(async () => {
  502. const next = await (await page.request.get('http://127.0.0.1:19119/__test/rpc-requests')).json() as typeof payload
  503. return next.requests.filter(request => request.method === 'config.set' && request.params.key === 'fast').at(-1)?.params.value
  504. }).toBe('normal')
  505. })
  506. test('reconciles an iOS fast-mode selection from the resumed 9119 session', async ({ page }) => {
  507. await page.request.post('http://127.0.0.1:19119/__test/rpc-requests/reset')
  508. await page.goto('/chat/session-yaoer?profile=yaoer')
  509. await expect(page.getByRole('button', { name: '快速模式:已关闭' })).toBeVisible()
  510. await page.getByRole('textbox', { name: '输入消息,Enter 发送,Shift + Enter 换行' }).fill('读取 iOS 快速模式')
  511. await page.getByRole('button', { name: '发送消息' }).click()
  512. await expect(page.getByRole('button', { name: '快速模式:已开启' })).toHaveCSS('color', 'rgb(22, 119, 255)')
  513. const payload = await (await page.request.get('http://127.0.0.1:19119/__test/rpc-requests')).json() as { requests: Array<{ method: string; params: Record<string, unknown> }> }
  514. expect(payload.requests.some(request => request.method === 'session.resume' && request.params.session_id === 'session-yaoer')).toBe(true)
  515. expect(payload.requests.some(request => request.method === 'config.set' && request.params.key === 'fast')).toBe(false)
  516. })
  517. test('keeps the show-thinking preference across sessions of the same Agent', async ({ page }) => {
  518. await page.goto('/chat/session-demo')
  519. await expect(page.locator('.turn-trace')).toHaveCount(1)
  520. await page.locator('.composer-tool[aria-label="设置"]').click()
  521. const setting = page.getByRole('switch', { name: /显示思考/ })
  522. await expect(setting).toHaveAttribute('aria-checked', 'true')
  523. await setting.click()
  524. await expect(page.locator('.turn-trace')).toHaveCount(0)
  525. await page.getByRole('option').filter({ hasText: '第二个会话' }).click()
  526. await expect(page.locator('.turn-trace')).toHaveCount(0)
  527. await page.locator('.composer-tool[aria-label="设置"]').click()
  528. await page.getByRole('switch', { name: /显示思考/ }).click()
  529. await expect(page.locator('.turn-trace')).toHaveCount(1)
  530. })
  531. test('restores a legacy session link under its owning Agent profile', async ({ page }) => {
  532. await page.goto('/chat/session-yaoer')
  533. await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()
  534. await expect(page).toHaveURL(/\/chat\/session-yaoer\?profile=yaoer/)
  535. await page.reload()
  536. await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()
  537. })
  538. test('renders historical assistant MEDIA as Markdown in chat and group chat', async ({ page }) => {
  539. await page.goto('/chat/session-demo')
  540. const image = page.locator('.markdown img[alt="夭夭 Logo"]')
  541. await expect(image).toBeVisible()
  542. await image.click()
  543. const mediaDialog = page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })
  544. await expect(mediaDialog).toBeVisible()
  545. await expect(mediaDialog.getByRole('button', { name: '下一张媒体' })).toBeVisible()
  546. await mediaDialog.getByRole('button', { name: '下一张媒体' }).click()
  547. await expect(mediaDialog.locator('img')).toHaveAttribute('src', /variant=2/)
  548. await page.keyboard.press('ArrowLeft')
  549. await expect(mediaDialog.locator('img')).not.toHaveAttribute('src', /variant=2/)
  550. await expect(mediaDialog.getByRole('link', { name: /下载 AppIcon-1024\.png/ })).toBeVisible()
  551. await page.keyboard.press('Escape')
  552. await expect(page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })).toBeHidden()
  553. await image.click()
  554. const reopenedMediaDialog = page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })
  555. await reopenedMediaDialog.getByRole('button', { name: '添加到聊天' }).click()
  556. await expect(reopenedMediaDialog).toBeHidden()
  557. await expect(page.locator('.composer-attachments img[alt="AppIcon-1024.png"]')).toBeVisible()
  558. await page.getByRole('button', { name: '团队' }).click()
  559. await expect(page.locator('.markdown img[alt="AppIcon-1024.png"]')).toBeVisible()
  560. })
  561. test('selects existing group topics and creates a new protocol v4 topic on first send', async ({ page }) => {
  562. const roomId = '22222222-2222-4222-8222-222222222222'
  563. const existingTopicId = '88888888-8888-4888-8888-888888888888'
  564. const existingTopicSidebarId = `topic:${roomId}:${existingTopicId}`
  565. await page.getByRole('button', { name: '团队' }).click()
  566. const sidebar = page.locator('.desktop-sidebar')
  567. const existingTopic = sidebar.locator(`[data-sidebar-id="${existingTopicSidebarId}"]`)
  568. await expect(sidebar.getByRole('button', { name: '返回对话' })).toBeVisible()
  569. await expect(sidebar.getByRole('button', { name: '折叠侧边栏' })).toBeVisible()
  570. await expect(sidebar.getByText('话题列表', { exact: true })).toBeVisible()
  571. await expect(sidebar.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  572. await expect(sidebar.getByRole('button', { name: '新建话题' })).toBeVisible()
  573. await expect(sidebar.getByRole('button', { name: '新建团队' })).toBeVisible()
  574. await expect(sidebar.getByRole('button', { name: '对话', exact: true })).toBeVisible()
  575. await expect(sidebar.locator('.sidebar-footer')).toBeVisible()
  576. await expect(existingTopic).toContainText('发布检查')
  577. await expect(existingTopic).toHaveClass(/sidebar-item--topic/)
  578. const existingTopicRequest = page.waitForRequest(request => {
  579. const url = new URL(request.url())
  580. return request.method() === 'GET'
  581. && url.pathname === `/api/app/groups/rooms/${roomId}/messages`
  582. && url.searchParams.get('topicId') === existingTopicId
  583. })
  584. const existingTopicRead = page.waitForRequest(request => {
  585. const url = new URL(request.url())
  586. return request.method() === 'PATCH'
  587. && url.pathname === `/api/app/groups/rooms/${roomId}/topics/${existingTopicId}/read`
  588. })
  589. await existingTopic.click()
  590. await existingTopicRequest
  591. expect((await existingTopicRead).postDataJSON()).toMatchObject({ throughSeq: 3 })
  592. await expect(page).toHaveURL(new RegExp(`/groups/${roomId}/${existingTopicId}$`))
  593. const timeline = page.locator('.message-stack')
  594. await expect(timeline.getByText('请核对发布话题的独立历史。', { exact: true })).toBeVisible()
  595. await expect(timeline.getByText('大家好,检查一下群聊输入框。', { exact: true })).toHaveCount(0)
  596. await sidebar.getByRole('button', { name: '新建话题' }).click()
  597. const teamPicker = page.getByRole('dialog', { name: '选择团队' })
  598. await expect(teamPicker).toBeVisible()
  599. await teamPicker.locator('.topic-team-picker__choose').filter({ hasText: '设计与工程协作' }).click()
  600. const draftTopic = sidebar.locator('.sidebar-item--topic').filter({ hasText: '新话题' })
  601. await expect(draftTopic).toBeVisible()
  602. const draftSidebarId = await draftTopic.getAttribute('data-sidebar-id')
  603. const newTopicId = draftSidebarId?.split(':').at(-1) || ''
  604. expect(newTopicId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
  605. expect(newTopicId).not.toBe(existingTopicId)
  606. await expect(page).toHaveURL(new RegExp(`/groups/${roomId}/${newTopicId}$`))
  607. const content = '新的发布验收话题'
  608. const sendRequestPromise = page.waitForRequest(request => {
  609. const url = new URL(request.url())
  610. return request.method() === 'POST' && url.pathname === `/api/app/groups/rooms/${roomId}/messages`
  611. })
  612. await page.getByRole('textbox', { name: '发消息给团队,输入 @ 提及 Agent' }).fill(content)
  613. await page.getByRole('button', { name: '发送消息' }).click()
  614. const sendRequest = await sendRequestPromise
  615. const sentPayload = sendRequest.postDataJSON() as { topicId: string; content: string; clientMessageId: string }
  616. expect(sentPayload).toMatchObject({ topicId: newTopicId, content })
  617. const createdTopic = sidebar.locator(`[data-sidebar-id="topic:${roomId}:${newTopicId}"]`)
  618. const sentMessage = page.locator(`[data-message-id="${sentPayload.clientMessageId}"]`)
  619. await expect(createdTopic).toContainText(content)
  620. await expect(sentMessage).toContainText(content)
  621. await page.reload()
  622. await expect(createdTopic).toContainText(content)
  623. await expect(sentMessage).toContainText(content)
  624. })
  625. test('renders persisted user file markers as attachment cards', async ({ page }) => {
  626. await page.goto('/chat/session-demo?profile=yaoyao')
  627. const userMessage = page.locator('[data-message-id="message-user-file"]')
  628. await expect(userMessage).toContainText('查看附件')
  629. await expect(userMessage.getByRole('button', { name: /测试报告\.docx/ })).toBeVisible()
  630. await expect(userMessage).not.toContainText('@file:')
  631. await expect(userMessage).not.toContainText('用户附加文件')
  632. })
  633. test('renders persisted user image markers as direct images instead of file cards', async ({ page }) => {
  634. await page.goto('/chat/session-demo?profile=yaoyao')
  635. const userMessage = page.locator('[data-message-id="message-user-image"]')
  636. const imageAttachment = userMessage.locator('.message__attachment--image')
  637. await expect(imageAttachment).toBeVisible()
  638. await expect(imageAttachment.locator('img[alt="测试图片.png"]')).toBeVisible()
  639. await expect(imageAttachment.locator('strong')).toHaveCount(0)
  640. await expect(imageAttachment).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  641. await expect(userMessage).not.toContainText('@image:')
  642. await expect(userMessage).not.toContainText('[screenshot]')
  643. await imageAttachment.click()
  644. await expect(page.getByRole('dialog', { name: '预览 测试图片.png' })).toBeVisible()
  645. })
  646. test('folds tool result rows into their expandable tool call', async ({ page }) => {
  647. await page.goto('/chat/session-demo')
  648. const trace = page.locator('.turn-trace').first()
  649. await expect(trace).not.toHaveAttribute('open', '')
  650. await expect(trace).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  651. await expect(trace.locator('summary')).toContainText('思考与工具')
  652. await expect(trace.locator('summary')).toContainText('2 段思考 · 2 个工具')
  653. await expect(trace.locator('summary > :last-child')).toHaveClass(/turn-trace__caret/)
  654. await trace.locator('summary').click()
  655. await expect(trace).not.toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  656. await expect(trace.locator('.turn-trace__reasoning')).toHaveCount(2)
  657. await expect(trace.locator('.tool-trace')).toHaveCount(2)
  658. await expect(trace.locator('.tool-trace > button > :last-child.tool-trace__caret')).toHaveCount(2)
  659. await expect(trace.locator('.tool-trace__details')).toHaveCount(2)
  660. await expect(trace.locator('.tool-trace__details').filter({ hasText: '/tmp/demo-report.pdf' })).toBeVisible()
  661. await expect(trace.locator('.tool-trace__details pre').first()).toHaveCSS('max-height', 'none')
  662. await expect(trace.locator('.tool-trace__details pre').first()).toHaveCSS('overflow-y', 'visible')
  663. const traceContent = trace.locator('.turn-trace__content')
  664. await expect(traceContent).toHaveCSS('overflow-y', 'auto')
  665. await expect(traceContent.locator(':scope > .turn-trace__item')).toHaveCount(4)
  666. const layout = await traceContent.evaluate(element => {
  667. const items = [...element.children] as HTMLElement[]
  668. return {
  669. maxHeight: Number.parseFloat(getComputedStyle(element).maxHeight),
  670. leftOffsets: items.map(item => item.offsetLeft),
  671. }
  672. })
  673. expect(layout.maxHeight).toBeLessThanOrEqual(420)
  674. expect(new Set(layout.leftOffsets).size).toBe(1)
  675. const toolAlignment = await trace.locator('.tool-trace').first().evaluate(element => {
  676. const tool = element as HTMLElement
  677. const button = tool.querySelector<HTMLElement>(':scope > button')
  678. const detail = tool.querySelector<HTMLElement>('.tool-trace__details > section')
  679. return {
  680. toolLeft: tool.getBoundingClientRect().left,
  681. buttonLeft: button?.getBoundingClientRect().left,
  682. detailLeft: detail?.getBoundingClientRect().left,
  683. }
  684. })
  685. expect(toolAlignment.buttonLeft).toBeCloseTo(toolAlignment.toolLeft, 0)
  686. expect(toolAlignment.detailLeft).toBeCloseTo(toolAlignment.toolLeft, 0)
  687. await expect(page.locator('[data-message-id="message-tool-call"]')).toHaveCount(0)
  688. await expect(page.locator('.message--tool')).toHaveCount(0)
  689. })
  690. test('renders subtask completion as a collapsed timeline event', async ({ page }) => {
  691. await page.goto('/chat/session-demo')
  692. await expect(page.getByText('子任务已完成', { exact: true })).toBeVisible()
  693. const delegation = page.locator('.delegation-event').filter({ hasText: '子任务已完成' })
  694. await expect(delegation).toContainText('2 个子任务 · 2 已完成')
  695. await expect(delegation).not.toHaveAttribute('open', '')
  696. })
  697. test('renders background process exits as collapsed system events', async ({ page }) => {
  698. await page.goto('/chat/session-demo')
  699. const event = page.locator('[data-message-id="message-background-process"] .background-process-event')
  700. const detail = event.locator('.markdown')
  701. await expect(event).toContainText('后台子任务已终止 · SIGTERM')
  702. await expect(event).not.toHaveAttribute('open', '')
  703. await expect(detail).toBeHidden()
  704. await event.locator('summary').click()
  705. await expect(detail).toBeVisible()
  706. await expect(detail).toContainText('Command: ./run_mac.sh')
  707. await expect(page.locator('[data-message-id="message-background-process"]')).toHaveClass(/message--system/)
  708. })
  709. test('renders context compaction as a collapsed timeline event', async ({ page }) => {
  710. await page.goto('/chat/session-demo')
  711. const compaction = page.locator('[data-message-id="message-compaction"] .compaction-event')
  712. await expect(compaction).toContainText('上下文已压缩')
  713. await expect(compaction).toContainText('压缩摘要已归档 · 点击查看')
  714. await expect(compaction).not.toHaveAttribute('open', '')
  715. await expect(compaction.getByText('Historical Task Snapshot', { exact: true })).toBeHidden()
  716. await compaction.locator('summary').click()
  717. await expect(compaction.getByText('Historical Task Snapshot', { exact: true })).toBeVisible()
  718. await expect(page.locator('[data-message-id="message-compaction"]')).toHaveClass(/message--system/)
  719. })
  720. test('renders model changes as a collapsed system event', async ({ page }) => {
  721. await page.goto('/chat/session-demo')
  722. const modelEvent = page.locator('.system-event').filter({ hasText: '模型已切换:gpt-5.6-terra' })
  723. await expect(modelEvent.getByText('模型已切换:gpt-5.6-terra', { exact: true })).toBeVisible()
  724. await expect(modelEvent).not.toHaveAttribute('open', '')
  725. })
  726. test('opens a local message file link as a floating preview card', async ({ page }) => {
  727. await page.route('**/Users/samien/Agents/%E6%96%B9%E6%A1%88%E8%8D%89%E7%A8%BF.md', route => route.fulfill({
  728. status: 200,
  729. contentType: 'text/markdown',
  730. body: '# 会话文件\n\n这是会话中的文本文件。',
  731. }))
  732. await page.goto('/chat/session-demo')
  733. const card = page.getByRole('link', { name: '预览文件 方案草稿.md' })
  734. await expect(card).toHaveClass(/file-link-card/)
  735. await card.click()
  736. const dialog = page.getByRole('dialog', { name: '预览 方案草稿.md' })
  737. await expect(dialog).toBeVisible()
  738. await expect(dialog.locator('.preview-text')).toBeVisible()
  739. const textPadding = await dialog.locator('.preview-text').evaluate(element => {
  740. const style = getComputedStyle(element)
  741. return { left: Number.parseFloat(style.paddingLeft), right: Number.parseFloat(style.paddingRight) }
  742. })
  743. expect(textPadding.left).toBeGreaterThanOrEqual(24)
  744. expect(textPadding.right).toBeGreaterThanOrEqual(24)
  745. const stageHeight = await dialog.locator('.preview-stage').evaluate(stage => stage.getBoundingClientRect().height)
  746. expect(stageHeight).toBeGreaterThan(500)
  747. })
  748. test('shows a thinking animation after submit until output starts', async ({ page }) => {
  749. await page.goto('/chat/session-demo?profile=yaoyao')
  750. await page.locator('.composer-textarea').fill('请开始思考')
  751. await page.getByRole('button', { name: '发送消息' }).click()
  752. await expect(page.locator('.thinking-indicator')).toBeVisible()
  753. await expect(page.getByText('这是来自假 Gateway 的流式回复。', { exact: true })).toBeVisible()
  754. await expect(page.locator('.thinking-indicator')).toHaveCount(0)
  755. })
  756. test('uses HTTP commands and SSE for chat and team events without opening client WebSockets', async ({ page }, testInfo) => {
  757. const sockets: string[] = [], paths: string[] = []
  758. page.on('websocket', socket => sockets.push(socket.url()))
  759. page.on('request', request => paths.push(new URL(request.url()).pathname))
  760. await page.goto('/chat/session-demo?profile=yaoyao')
  761. await page.locator('.composer-textarea').fill('验证 HTTP SSE 入口')
  762. await page.getByRole('button', { name: '发送消息' }).click()
  763. await expect(page.getByText('这是来自假 Gateway 的流式回复。', { exact: true })).toBeVisible()
  764. expect(paths.some(path => /^\/api\/realtime\/channels\/[^/]+\/commands$/.test(path))).toBe(true)
  765. expect(paths.some(path => /^\/api\/realtime\/channels\/[^/]+\/events$/.test(path))).toBe(true)
  766. await page.screenshot({ path: testInfo.outputPath('http-sse-chat.png'), fullPage: true })
  767. await page.getByRole('button', { name: '团队', exact: true }).click()
  768. await page.getByRole('option').filter({ hasText: '设计验收' }).click()
  769. await expect(page.getByRole('heading', { name: '设计验收' })).toBeVisible()
  770. expect(sockets).toEqual([])
  771. await page.screenshot({ path: testInfo.outputPath('http-sse-team.png'), fullPage: true })
  772. })
  773. test('keeps streamed text below sealed interim commentary and its tool trace', async ({ page }) => {
  774. await page.goto('/chat/session-demo?profile=yaoyao')
  775. await page.locator('.composer-textarea').fill('验证流式分段')
  776. await page.getByRole('button', { name: '发送消息' }).click()
  777. const interim = page.locator('.message--assistant').filter({ hasText: '我先检查配置。' }).last()
  778. const current = page.locator('.message--assistant').filter({ hasText: '配置检查完成。' }).last()
  779. const trace = page.locator('.turn-trace').last()
  780. await expect(interim).toBeVisible()
  781. await expect(trace).toHaveClass(/turn-trace--running/)
  782. await expect(page.locator('.thinking-indicator')).toBeVisible()
  783. await expect(current).toBeVisible()
  784. const [interimBox, traceBox, currentBox] = await Promise.all([
  785. interim.boundingBox(), trace.boundingBox(), current.boundingBox(),
  786. ])
  787. expect(interimBox?.y).toBeLessThan(traceBox?.y ?? 0)
  788. expect(traceBox?.y).toBeLessThan(currentBox?.y ?? 0)
  789. await expect(trace).toHaveClass(/turn-trace--success/)
  790. await expect(page.getByText('配置检查完成。', { exact: true })).toHaveCount(1)
  791. })
  792. test('keeps the canonical logo and yaoyao-webui composer geometry', async ({ page }) => {
  793. const logo = page.locator('.rail__brand img')
  794. await expect(logo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  795. const emptyLogo = page.locator('.new-chat-empty__logo')
  796. await expect(emptyLogo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  797. await expect(page.getByText('聊点什么', { exact: true })).toBeVisible()
  798. await expect(page.locator('.timeline-header')).toHaveClass(/timeline-header--transparent/)
  799. await expect(page.locator('.composer-context')).toContainText('剩余 256.0k')
  800. await page.getByRole('button', { name: '推理强度:默认' }).click()
  801. await expect(page.locator('.composer-popover--reasoning')).toBeVisible()
  802. await page.getByRole('button', { name: '设置', exact: true }).click()
  803. await expect(page.locator('.composer-popover--settings')).toBeVisible()
  804. await expect(page.getByText('语音输入设置', { exact: true })).toBeVisible()
  805. await page.locator('.composer-shell').click()
  806. await page.getByRole('option').first().click()
  807. await expect(page.locator('.timeline')).toHaveCSS('background-color', 'rgb(255, 255, 255)')
  808. await expect(page.locator('.message--assistant .message__avatar')).toHaveCount(0)
  809. await expect(page.locator('.message--assistant .message__meta')).toHaveCount(0)
  810. const assistantMessage = page.locator('.message--assistant-anonymous:not(.message--tool-only)').first()
  811. await page.mouse.move(1200, 20)
  812. await expect(assistantMessage.locator('.message__actions')).toHaveCSS('opacity', '0')
  813. await assistantMessage.hover()
  814. await expect(assistantMessage.locator('.message__actions')).toHaveCSS('opacity', '1')
  815. await expect(page.locator('.message--tool-only .message__actions')).toHaveCount(0)
  816. await expect(page.locator('[data-message-id="message-thinking-tool"]')).toHaveCount(0)
  817. await expect(page.locator('.turn-trace')).toHaveCount(1)
  818. const userMessageMeta = page.locator('.message--user .message__meta')
  819. await expect(userMessageMeta).not.toHaveCount(0)
  820. expect(await userMessageMeta.evaluateAll(elements => elements.every(element => getComputedStyle(element).display === 'none'))).toBe(true)
  821. await expect(page.getByRole('button', { name: '会话操作' })).toBeVisible()
  822. await page.getByRole('button', { name: '会话操作' }).click()
  823. const sessionMenu = page.getByRole('menu', { name: '会话操作' })
  824. await expect(sessionMenu.getByText('会话大纲', { exact: true })).toBeVisible()
  825. await sessionMenu.getByText('会话大纲', { exact: true }).click()
  826. const outline = page.getByRole('navigation', { name: '会话大纲' })
  827. await expect(outline).toBeVisible()
  828. await expect(outline.getByText('请检查今天生成的产物。MEDIA:/brand/AppIcon-1024.png', { exact: true })).toBeVisible()
  829. await expect(outline.getByText('验收摘要', { exact: true })).toBeVisible()
  830. await outline.getByRole('button', { name: '跳转到 验收摘要' }).click()
  831. await expect(page.locator('[data-message-id="message-assistant"]')).toHaveClass(/message--revealed/)
  832. await page.getByRole('button', { name: '关闭会话大纲' }).click()
  833. await expect(outline).toBeHidden()
  834. await page.getByRole('button', { name: '会话操作' }).click()
  835. await expect(sessionMenu.getByText('取消置顶', { exact: true })).toBeVisible()
  836. const unpinIcon = sessionMenu.getByRole('menuitem', { name: '取消置顶' }).locator('.app-icon')
  837. await expect(unpinIcon.locator('path')).toHaveCount(2)
  838. await expect(unpinIcon.locator('path').last()).toHaveAttribute('d', 'M4 4l16 16')
  839. await expect(page.locator('.desktop-sidebar .sidebar-item--single-line').first().locator('.app-icon path')).toHaveAttribute('fill', 'currentColor')
  840. await expect(sessionMenu.getByText('重命名', { exact: true })).toBeVisible()
  841. await expect(sessionMenu.getByText('删除会话', { exact: true })).toBeVisible()
  842. await expect(page.getByText('置顶会话', { exact: true })).toHaveCount(0)
  843. const menuBox = await sessionMenu.evaluate(element => element.getBoundingClientRect().toJSON())
  844. expect(menuBox.width).toBeLessThanOrEqual(220)
  845. expect(menuBox.height).toBeLessThan(165)
  846. await expect(page.locator('.session-action-layer')).toHaveCount(0)
  847. await sessionMenu.getByText('取消置顶', { exact: true }).click()
  848. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toHaveCount(0)
  849. await page.getByRole('button', { name: '会话操作' }).click()
  850. await sessionMenu.getByText('置顶会话', { exact: true }).click()
  851. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toBeVisible()
  852. const compactSession = page.locator('.desktop-sidebar .sidebar-item--single-line').first()
  853. const compactMetrics = await compactSession.evaluate(element => {
  854. const title = element.querySelector('strong')
  855. return {
  856. height: element.getBoundingClientRect().height,
  857. weight: title ? Number(getComputedStyle(title).fontWeight) : 0,
  858. }
  859. })
  860. expect(compactMetrics.height).toBeLessThanOrEqual(31)
  861. expect(compactMetrics.weight).toBeLessThan(500)
  862. await compactSession.click({ button: 'right' })
  863. await expect(sessionMenu).toBeVisible()
  864. await page.keyboard.press('Escape')
  865. const composer = page.locator('.composer-shell')
  866. await expect(composer).toBeVisible()
  867. const geometry = await composer.evaluate(element => {
  868. const rect = element.getBoundingClientRect()
  869. const style = getComputedStyle(element)
  870. return { width: rect.width, minHeight: style.minHeight, radius: style.borderRadius }
  871. })
  872. expect(geometry.width).toBeLessThanOrEqual(760)
  873. expect(geometry.minHeight).toBe('72px')
  874. expect(geometry.radius).toBe('18px')
  875. const send = page.getByRole('button', { name: '发送消息' })
  876. await expect(send).toHaveCSS('width', '34px')
  877. await expect(send).toHaveCSS('height', '34px')
  878. })
  879. test('uses the unified Grok-style sidebar, search trigger, and persistent collapse', async ({ page }) => {
  880. const sidebar = page.locator('.desktop-sidebar')
  881. await expect(sidebar).toBeVisible()
  882. await expect(sidebar).toHaveCSS('width', '264px')
  883. await expect(sidebar.locator('.brand-mark__name')).toHaveCount(0)
  884. await expect(sidebar.locator('.profile-switcher')).toHaveCount(0)
  885. await expect(sidebar.locator('.sidebar-account-switcher')).toHaveCount(1)
  886. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  887. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  888. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  889. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toHaveCSS('font-weight', '650')
  890. await expect(sidebar.getByText('历史记录', { exact: true })).toBeVisible()
  891. const searchTrigger = page.getByRole('button', { name: '搜索', exact: true })
  892. await searchTrigger.click()
  893. const searchDialog = page.getByRole('dialog', { name: '搜索会话' })
  894. await expect(searchDialog).toBeVisible()
  895. const search = searchDialog.getByPlaceholder('搜索会话')
  896. await expect(search).toBeVisible()
  897. await expect(sidebar.locator('.sidebar-search')).toHaveCount(0)
  898. const originalSessionCount = await sidebar.getByRole('option').count()
  899. await search.fill('验收')
  900. const sessionResult = searchDialog.getByRole('option', { name: /夭夭 Web 验收会话/ })
  901. await expect(sessionResult).toBeVisible()
  902. await expect(sidebar.getByRole('option')).toHaveCount(originalSessionCount)
  903. await sessionResult.click()
  904. await expect(page).toHaveURL(/\/chat\/session-demo\?profile=yaoyao/)
  905. await expect(searchDialog).toBeHidden()
  906. await expect(searchTrigger).toBeVisible()
  907. await expect(searchTrigger).toHaveAttribute('aria-expanded', 'false')
  908. await page.getByRole('button', { name: '折叠侧边栏' }).click()
  909. await expect(sidebar).toHaveCSS('width', '68px')
  910. const collapseBox = await page.getByRole('button', { name: '展开侧边栏' }).boundingBox()
  911. const accountBox = await sidebar.locator('.sidebar-account-switcher__main').boundingBox()
  912. expect(collapseBox?.y).toBeLessThan(accountBox?.y ?? 0)
  913. await expect(sidebar.getByText('历史记录', { exact: true })).toBeHidden()
  914. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  915. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  916. await page.reload()
  917. await expect(sidebar).toHaveCSS('width', '68px')
  918. await page.getByRole('button', { name: '搜索', exact: true }).click()
  919. await expect(sidebar).toHaveCSS('width', '264px')
  920. await expect(page.getByRole('dialog', { name: '搜索会话' })).toBeVisible()
  921. })
  922. test('uses the mobile composer and keeps the closed drawer inert', async ({ page }) => {
  923. await page.setViewportSize({ width: 390, height: 844 })
  924. await page.reload()
  925. await expect(page.getByRole('navigation')).not.toBeVisible()
  926. const drawer = page.locator('.mobile-drawer')
  927. await expect(drawer).toHaveAttribute('aria-hidden', 'true')
  928. await expect(drawer).toHaveAttribute('inert', '')
  929. await expect(page.locator('.mobile-header .brand-mark__plate')).toBeVisible()
  930. await expect(page.locator('.mobile-header .brand-mark__name')).toHaveCount(0)
  931. await page.getByRole('button', { name: '打开导航' }).click()
  932. await expect(drawer.locator('.brand-mark__plate')).toBeVisible()
  933. await expect(drawer.locator('.brand-mark__name')).toHaveCount(0)
  934. await expect(page.locator('.composer-shell')).toHaveCSS('min-height', '118px')
  935. await expect(page.locator('.composer-textarea')).toHaveCSS('font-size', '16px')
  936. })
  937. test('renders the Kanban snapshot and mobile status control without page overflow', async ({ page }) => {
  938. await page.getByRole('button', { name: '看板', exact: true }).click()
  939. await expect(page).toHaveURL(/\/kanban\/default$/)
  940. await expect(page).toHaveTitle('产品研发 · 夭夭')
  941. await expect(page.getByRole('heading', { name: '产品研发', exact: true })).toBeVisible()
  942. await expect(page.getByRole('article', { name: /完成 Web 看板验收/ })).toBeVisible()
  943. await expect(page.locator('.kanban-column')).toHaveCount(8)
  944. await page.getByRole('article', { name: /完成 Web 看板验收/ }).click()
  945. await expect(page.getByRole('heading', { name: '完成 Web 看板验收', exact: true })).toBeVisible()
  946. await expect(page.getByText('请保留真实浏览器验收证据。', { exact: true })).toBeVisible()
  947. await expect(page.locator('.kanban-task-drawer').getByText('正在执行浏览器验收', { exact: true }).first()).toBeVisible()
  948. await page.getByRole('button', { name: '关闭任务详情' }).click()
  949. await page.setViewportSize({ width: 390, height: 844 })
  950. await page.reload()
  951. await expect(page.getByRole('button', { name: '立即调度', exact: true })).toBeVisible()
  952. const card = page.getByRole('article', { name: /完成 Web 看板验收/ })
  953. await expect(card).toBeVisible()
  954. await expect(card.locator('.kanban-card__mobile-status select')).toBeVisible()
  955. const geometry = await page.evaluate(() => ({
  956. viewport: window.innerWidth,
  957. page: document.documentElement.scrollWidth,
  958. board: document.querySelector('.kanban-columns')?.scrollWidth || 0,
  959. }))
  960. expect(geometry.page).toBe(geometry.viewport)
  961. expect(geometry.board).toBeGreaterThan(geometry.viewport)
  962. })