workspace.spec.ts 57 KB

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