workspace.spec.ts 64 KB

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