workspace.spec.ts 61 KB

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