workspace.spec.ts 56 KB

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