systemMessageNotice.test.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { describe, expect, it, vi } from 'vitest'
  2. import { nextTick } from 'vue'
  3. import { mount } from '@vue/test-utils'
  4. import { systemMessageNotice } from '@/utils/systemMessageNotice'
  5. import WorkspaceMessageTimeline from '@/components/workspace/WorkspaceMessageTimeline.vue'
  6. import type { UiMessage } from '@/components/messages/types'
  7. const assignment: UiMessage = { id: 'assigned', role: 'system', content: '由管理员分派的子任务:终审文章\n\n- 核验来源\n- 检查配图' }
  8. describe('system event disclosures', () => {
  9. it('classifies role-only assignments without treating real replies as notices', () => {
  10. expect(systemMessageNotice(assignment)).toEqual({ title: '已分派子任务', icon: 'branch' })
  11. expect(systemMessageNotice({ ...assignment, role: 'assistant' })).toBeUndefined()
  12. expect(systemMessageNotice({ ...assignment, role: 'user' })).toBeUndefined()
  13. expect(systemMessageNotice({ ...assignment, communication: { direction: 'incoming', peerId: 'p', peerName: '竹儿', peerAvatar: '', peerKind: 'agent', content: assignment.content } })).toBeUndefined()
  14. })
  15. it('distinguishes background completion, interruption and missing exit status', () => {
  16. const message: UiMessage = { id: 'process', role: 'system', content: 'process', timelineKind: 'background-process' }
  17. expect(systemMessageNotice(message)?.title).toBe('后台子任务已结束')
  18. expect(systemMessageNotice({ ...message, timelineMetadata: { exit_code: null } })?.title).toBe('后台子任务已结束')
  19. expect(systemMessageNotice({ ...message, timelineMetadata: { exit_code: 0 } })?.title).toBe('后台子任务已完成')
  20. expect(systemMessageNotice({ ...message, timelineMetadata: { exit_code: 1 } })?.title).toBe('后台子任务失败')
  21. expect(systemMessageNotice({ ...message, timelineMetadata: { exit_code: 143, signal: 'SIGTERM' } })?.title).toBe('后台子任务已终止')
  22. })
  23. it.each([WorkspaceMessageTimeline])('keeps full requirements behind a short title in both timelines', async component => {
  24. vi.stubGlobal('ResizeObserver', class { observe() {} disconnect() {} })
  25. Element.prototype.scrollTo = vi.fn()
  26. const wrapper = mount(component, { props: { identity: 'test', messages: [assignment] }, global: { stubs: { AgentAvatar: true, MarkdownContent: { props: ['content'], template: '<p>{{ content }}</p>' } } } })
  27. expect(wrapper.get('summary').text()).toBe('已分派子任务')
  28. expect(wrapper.get('details').attributes('open')).toBeUndefined()
  29. expect(wrapper.get('.system-message-notice__details').text()).toContain('核验来源')
  30. expect(wrapper.find('.message__content').exists()).toBe(false)
  31. await nextTick()
  32. wrapper.unmount()
  33. vi.unstubAllGlobals()
  34. })
  35. })