workspace.spec.ts 49 KB

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