workspace.spec.ts 63 KB

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