workspace.spec.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import { expect, test } from '@playwright/test'
  2. test.beforeEach(async ({ page }) => {
  3. await page.goto('/chat')
  4. if (await page.getByRole('heading', { name: '登录 Hermes' }).isVisible()) {
  5. await page.getByLabel('账号').fill('test')
  6. await page.getByLabel('密码').fill('test')
  7. await page.getByRole('button', { name: '登录' }).click()
  8. }
  9. await expect(page.getByRole('navigation')).toBeVisible()
  10. })
  11. test('navigates every 9119 workspace without blank transitions', async ({ page }) => {
  12. const consoleErrors: string[] = []
  13. page.on('console', message => { if (message.type() === 'error') consoleErrors.push(message.text()) })
  14. await expect(page.getByRole('option').first()).toContainText('夭夭 Web 验收会话')
  15. await expect(page.getByRole('option').first()).toContainText('夭夭')
  16. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toBeVisible()
  17. await page.getByRole('button', { name: '群聊' }).click()
  18. await expect(page.getByRole('heading', { name: '设计与工程协作' })).toBeVisible()
  19. await expect(page.getByRole('button', { name: '对话', exact: true })).toBeVisible()
  20. await expect(page.getByRole('button', { name: '群聊', exact: true })).toHaveCount(0)
  21. await expect(page.getByRole('button', { name: '文件库', exact: true })).toHaveCount(0)
  22. await expect(page.getByRole('button', { name: '产物', exact: true })).toHaveCount(0)
  23. await expect(page.getByRole('button', { name: '新建群聊' })).toBeVisible()
  24. await expect(page.getByRole('button', { name: '管理群聊' })).toBeVisible()
  25. await expect(page.getByRole('button', { name: '发送消息' })).toBeVisible()
  26. await page.goto('/files')
  27. await expect(page.getByRole('heading', { name: '文件库', exact: true }).last()).toBeVisible()
  28. await expect(page.getByText('demo-report.pdf')).toBeVisible()
  29. const firstFileCard = page.locator('.library-grid article').first()
  30. const cardGeometry = await firstFileCard.evaluate(element => {
  31. const card = element.getBoundingClientRect()
  32. const preview = element.querySelector('.library-thumb')?.getBoundingClientRect()
  33. return { width: card.width, previewHeight: preview?.height || 0 }
  34. })
  35. expect(cardGeometry.width).toBeGreaterThanOrEqual(220)
  36. expect(cardGeometry.previewHeight).toBe(154)
  37. await page.getByText('demo-report.pdf').click()
  38. await expect(page.getByRole('dialog', { name: /预览 demo-report.pdf/ })).toBeVisible()
  39. await expect(page.locator('.preview-meta')).toHaveCount(0)
  40. const previewDialog = page.getByRole('dialog', { name: /预览 demo-report.pdf/ })
  41. await expect(previewDialog.getByRole('link', { name: '下载' })).toBeVisible()
  42. await expect(previewDialog.getByRole('button', { name: '加入输入框' })).toBeVisible()
  43. await expect(previewDialog.locator('.preview-close')).toBeVisible()
  44. const modalHeight = await page.locator('.preview-modal').evaluate(element => element.getBoundingClientRect().height)
  45. expect(modalHeight).toBeGreaterThan(600)
  46. await previewDialog.locator('.preview-close').click()
  47. await page.goto('/artifacts')
  48. await expect(page).toHaveURL(/\/chat$/)
  49. await expect(page.getByRole('button', { name: '产物', exact: true })).toHaveCount(0)
  50. expect(consoleErrors).toEqual([])
  51. })
  52. test('keeps pins first and loads the next session page at the list bottom', async ({ page }) => {
  53. const sidebar = page.locator('.desktop-sidebar')
  54. const items = sidebar.locator('.sidebar-list [role="option"]')
  55. await expect(items).toHaveCount(100)
  56. await expect(items.first()).toContainText('夭夭 Web 验收会话')
  57. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toBeVisible()
  58. const list = sidebar.locator('.sidebar-list')
  59. await list.evaluate(element => {
  60. element.scrollTop = element.scrollHeight
  61. element.dispatchEvent(new Event('scroll'))
  62. })
  63. await expect(items).toHaveCount(103)
  64. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toHaveCount(0)
  65. })
  66. test('restores a routed conversation even when unread-count refresh fails', async ({ page }) => {
  67. await page.route('**/api/app/sessions/unread*', async route => {
  68. await route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'unread unavailable' }) })
  69. })
  70. await page.goto('/chat/session-demo')
  71. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  72. await page.reload()
  73. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  74. })
  75. test('opens a conversation even when marking it read is unsupported', async ({ page }) => {
  76. const pageErrors: string[] = []
  77. page.on('pageerror', error => pageErrors.push(error.message))
  78. await page.route('**/api/app/sessions/unread/*', async route => {
  79. await route.fulfill({ status: 405, contentType: 'application/json', body: JSON.stringify({ error: 'Method Not Allowed' }) })
  80. })
  81. await page.getByRole('option').filter({ hasText: '第二个会话' }).click()
  82. await expect(page).toHaveURL(/\/chat\/session-second\?profile=yaoyao/)
  83. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  84. expect(pageErrors).toEqual([])
  85. })
  86. test('restores a legacy session link under its owning Agent profile', async ({ page }) => {
  87. await page.goto('/chat/session-yaoer')
  88. await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()
  89. await expect(page).toHaveURL(/\/chat\/session-yaoer\?profile=yaoer/)
  90. await page.reload()
  91. await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()
  92. })
  93. test('renders historical assistant MEDIA as Markdown in chat and group chat', async ({ page }) => {
  94. await page.goto('/chat/session-demo')
  95. const image = page.locator('.markdown img[alt="夭夭 Logo"]')
  96. await expect(image).toBeVisible()
  97. await image.click()
  98. const mediaDialog = page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })
  99. await expect(mediaDialog).toBeVisible()
  100. await expect(mediaDialog.getByRole('button', { name: '下一张媒体' })).toBeVisible()
  101. await mediaDialog.getByRole('button', { name: '下一张媒体' }).click()
  102. await expect(mediaDialog.locator('img')).toHaveAttribute('src', /variant=2/)
  103. await page.keyboard.press('ArrowLeft')
  104. await expect(mediaDialog.locator('img')).not.toHaveAttribute('src', /variant=2/)
  105. await expect(mediaDialog.getByRole('link', { name: /下载 AppIcon-1024\.png/ })).toBeVisible()
  106. await page.keyboard.press('Escape')
  107. await expect(page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })).toBeHidden()
  108. await image.click()
  109. const reopenedMediaDialog = page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })
  110. await reopenedMediaDialog.getByRole('button', { name: '添加到聊天' }).click()
  111. await expect(reopenedMediaDialog).toBeHidden()
  112. await expect(page.locator('.composer-attachments img[alt="AppIcon-1024.png"]')).toBeVisible()
  113. await page.getByRole('button', { name: '群聊' }).click()
  114. await expect(page.locator('.markdown img[alt="AppIcon-1024.png"]')).toBeVisible()
  115. })
  116. test('folds tool result rows into their expandable tool call', async ({ page }) => {
  117. await page.goto('/chat/session-demo')
  118. const tool = page.locator('[data-message-id="message-tool-call"]').getByRole('button', { name: /file_search/ })
  119. await expect(tool).toBeVisible()
  120. await tool.click()
  121. await expect(page.locator('.tool-trace pre')).toContainText('/tmp/demo-report.pdf')
  122. await expect(page.locator('.message--tool')).toHaveCount(0)
  123. })
  124. test('renders subtask completion as a collapsed timeline event', async ({ page }) => {
  125. await page.goto('/chat/session-demo')
  126. await expect(page.getByText('子任务已完成', { exact: true })).toBeVisible()
  127. await expect(page.locator('.delegation-event')).toContainText('2 个子任务 · 2 已完成')
  128. await expect(page.locator('.delegation-event')).not.toHaveAttribute('open', '')
  129. })
  130. test('renders model changes as a collapsed system event', async ({ page }) => {
  131. await page.goto('/chat/session-demo')
  132. await expect(page.getByText('模型已切换:gpt-5.6-terra', { exact: true })).toBeVisible()
  133. await expect(page.locator('.system-event')).not.toHaveAttribute('open', '')
  134. })
  135. test('opens a local message file link as a floating preview card', async ({ page }) => {
  136. await page.goto('/chat/session-demo')
  137. const card = page.getByRole('link', { name: '预览文件 方案草稿.md' })
  138. await expect(card).toHaveClass(/file-link-card/)
  139. await card.click()
  140. const dialog = page.getByRole('dialog', { name: '预览 方案草稿.md' })
  141. await expect(dialog).toBeVisible()
  142. const stageHeight = await dialog.locator('.preview-stage').evaluate(stage => stage.getBoundingClientRect().height)
  143. expect(stageHeight).toBeGreaterThan(500)
  144. })
  145. test('keeps the canonical logo and yaoyao-webui composer geometry', async ({ page }) => {
  146. const logo = page.locator('.rail__brand img')
  147. await expect(logo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  148. const emptyLogo = page.locator('.new-chat-empty__logo')
  149. await expect(emptyLogo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  150. await expect(page.getByText('聊点什么', { exact: true })).toBeVisible()
  151. await expect(page.locator('.timeline-header')).toHaveClass(/timeline-header--transparent/)
  152. await expect(page.locator('.composer-context')).toContainText('剩余 256.0k')
  153. await page.getByRole('button', { name: '推理强度:默认' }).click()
  154. await expect(page.locator('.composer-popover--reasoning')).toBeVisible()
  155. await page.getByRole('button', { name: '设置' }).click()
  156. await expect(page.locator('.composer-popover--settings')).toBeVisible()
  157. await expect(page.getByText('语音输入设置', { exact: true })).toBeVisible()
  158. await page.locator('.composer-shell').click()
  159. await page.getByRole('option').first().click()
  160. await expect(page.locator('.timeline')).toHaveCSS('background-color', 'rgb(255, 255, 255)')
  161. await expect(page.locator('.message--assistant .message__avatar')).toHaveCount(0)
  162. await expect(page.locator('.message--assistant .message__meta')).toHaveCount(0)
  163. const assistantMessage = page.locator('.message--assistant-anonymous:not(.message--tool-only)').first()
  164. await page.mouse.move(1200, 20)
  165. await expect(assistantMessage.locator('.message__actions')).toHaveCSS('opacity', '0')
  166. await assistantMessage.hover()
  167. await expect(assistantMessage.locator('.message__actions')).toHaveCSS('opacity', '1')
  168. await expect(page.locator('.message--tool-only .message__actions')).toHaveCount(0)
  169. await expect(page.locator('[data-message-id="message-thinking-tool"] .message__actions')).toHaveCount(0)
  170. await expect(page.locator('[data-message-id="message-thinking-tool"]')).toHaveClass(/message--assistant-internal/)
  171. await expect(page.locator('.message--user .message__meta')).toHaveCSS('display', 'none')
  172. await expect(page.getByRole('button', { name: '会话操作' })).toBeVisible()
  173. await page.getByRole('button', { name: '会话操作' }).click()
  174. const sessionMenu = page.getByRole('menu', { name: '会话操作' })
  175. await expect(sessionMenu.getByText('重命名', { exact: true })).toBeVisible()
  176. await expect(sessionMenu.getByText('删除会话', { exact: true })).toBeVisible()
  177. await expect(page.getByText('置顶会话', { exact: true })).toHaveCount(0)
  178. const menuBox = await sessionMenu.evaluate(element => element.getBoundingClientRect().toJSON())
  179. expect(menuBox.width).toBeLessThanOrEqual(220)
  180. expect(menuBox.height).toBeLessThan(100)
  181. await expect(page.locator('.session-action-layer')).toHaveCount(0)
  182. await page.keyboard.press('Escape')
  183. const compactSession = page.locator('.desktop-sidebar .sidebar-item--single-line').first()
  184. const compactMetrics = await compactSession.evaluate(element => {
  185. const title = element.querySelector('strong')
  186. return {
  187. height: element.getBoundingClientRect().height,
  188. weight: title ? Number(getComputedStyle(title).fontWeight) : 0,
  189. }
  190. })
  191. expect(compactMetrics.height).toBeLessThanOrEqual(31)
  192. expect(compactMetrics.weight).toBeLessThan(500)
  193. await compactSession.click({ button: 'right' })
  194. await expect(sessionMenu).toBeVisible()
  195. await page.keyboard.press('Escape')
  196. const composer = page.locator('.composer-shell')
  197. await expect(composer).toBeVisible()
  198. const geometry = await composer.evaluate(element => {
  199. const rect = element.getBoundingClientRect()
  200. const style = getComputedStyle(element)
  201. return { width: rect.width, minHeight: style.minHeight, radius: style.borderRadius }
  202. })
  203. expect(geometry.width).toBeLessThanOrEqual(760)
  204. expect(geometry.minHeight).toBe('72px')
  205. expect(geometry.radius).toBe('18px')
  206. const send = page.getByRole('button', { name: '发送消息' })
  207. await expect(send).toHaveCSS('width', '34px')
  208. await expect(send).toHaveCSS('height', '34px')
  209. })
  210. test('uses the unified Grok-style sidebar, search trigger, and persistent collapse', async ({ page }) => {
  211. const sidebar = page.locator('.desktop-sidebar')
  212. await expect(sidebar).toBeVisible()
  213. await expect(sidebar).toHaveCSS('width', '264px')
  214. await expect(sidebar.locator('.brand-mark__name')).toHaveCount(0)
  215. await expect(sidebar.locator('.profile-switcher')).toHaveCount(0)
  216. await expect(sidebar.locator('.sidebar-account-switcher')).toHaveCount(1)
  217. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  218. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  219. await expect(sidebar.getByText('历史记录', { exact: true })).toBeVisible()
  220. const searchTrigger = page.getByRole('button', { name: '搜索', exact: true })
  221. const triggerBox = await searchTrigger.boundingBox()
  222. await searchTrigger.click()
  223. const search = page.getByPlaceholder('搜索会话').filter({ visible: true })
  224. await expect(search).toBeVisible()
  225. await page.waitForTimeout(150)
  226. const inputBox = await search.evaluate(element => {
  227. const rect = element.closest('label')?.getBoundingClientRect()
  228. return rect ? { y: rect.y, height: rect.height } : null
  229. })
  230. expect(inputBox?.y).toBe(triggerBox?.y)
  231. expect(inputBox?.height).toBe(triggerBox?.height)
  232. await search.fill('验收')
  233. await expect(page.getByRole('option', { name: /夭夭 Web 验收会话/ })).toBeVisible()
  234. await search.press('Escape')
  235. await expect(search).toBeHidden()
  236. await expect(searchTrigger).toBeVisible()
  237. await expect(searchTrigger).toHaveAttribute('aria-expanded', 'false')
  238. await page.getByRole('button', { name: '折叠侧边栏' }).click()
  239. await expect(sidebar).toHaveCSS('width', '68px')
  240. const collapseBox = await page.getByRole('button', { name: '展开侧边栏' }).boundingBox()
  241. const accountBox = await sidebar.locator('.sidebar-account-switcher__main').boundingBox()
  242. expect(collapseBox?.y).toBeLessThan(accountBox?.y ?? 0)
  243. await expect(sidebar.getByText('历史记录', { exact: true })).toBeHidden()
  244. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  245. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  246. await page.reload()
  247. await expect(sidebar).toHaveCSS('width', '68px')
  248. await page.getByRole('button', { name: '搜索', exact: true }).click()
  249. await expect(sidebar).toHaveCSS('width', '264px')
  250. await expect(page.getByPlaceholder('搜索会话').filter({ visible: true })).toBeVisible()
  251. })
  252. test('uses the mobile composer and keeps the closed drawer inert', async ({ page }) => {
  253. await page.setViewportSize({ width: 390, height: 844 })
  254. await page.reload()
  255. await expect(page.getByRole('navigation')).not.toBeVisible()
  256. const drawer = page.locator('.mobile-drawer')
  257. await expect(drawer).toHaveAttribute('aria-hidden', 'true')
  258. await expect(drawer).toHaveAttribute('inert', '')
  259. await expect(page.locator('.composer-shell')).toHaveCSS('min-height', '118px')
  260. await expect(page.locator('.composer-textarea')).toHaveCSS('font-size', '16px')
  261. })