workspace.spec.ts 56 KB

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