| 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { |
| 3 | normalizeThinkingAssistantReply, |
| 4 | normalizeThinkingMessages |
| 5 | } from '../../../src/main/thinking/reply-normalizer' |
| 6 | |
| 7 | describe('thinking reply normalizer', () => { |
| 8 | it('keeps ordinary user-facing replies', () => { |
| 9 | expect(normalizeThinkingAssistantReply(' 我已确认主题,可以继续规划。 ')).toBe( |
| 10 | '我已确认主题,可以继续规划。' |
| 11 | ) |
| 12 | }) |
| 13 | |
| 14 | it('drops workflow tool return text', () => { |
| 15 | expect(normalizeThinkingAssistantReply('context.md updated for stage collect.')).toBe('') |
| 16 | expect(normalizeThinkingAssistantReply('thinking.md updated')).toBe('') |
| 17 | }) |
| 18 | |
| 19 | it('strips streamed tool argument fragments before the visible reply', () => { |
| 20 | const raw = [ |
| 21 | '"topic": "2026年AI短剧的发展",', |
| 22 | ' "userIntent": "用户希望创建演示文稿",', |
| 23 | ' "confirmedDecisions": ["主题确定"],', |
| 24 | '}', |
| 25 | '', |
| 26 | '我已确认您的演示主题为**2026年AI短剧的发展**。' |
| 27 | ].join('\n') |
| 28 | |
| 29 | expect(normalizeThinkingAssistantReply(raw)).toBe( |
| 30 | '我已确认您的演示主题为**2026年AI短剧的发展**。' |
| 31 | ) |
| 32 | }) |
| 33 | |
| 34 | it('normalizes persisted message arrays without changing user messages', () => { |
| 35 | const messages = normalizeThinkingMessages([ |
| 36 | { role: 'user', content: '影视从业者,内部研讨' }, |
| 37 | { role: 'assistant', content: 'context.md updated for stage collect.' }, |
| 38 | { |
| 39 | role: 'assistant', |
| 40 | content: '"topic": "AI短剧",\n "userIntent": "规划演示"\n}\n\n可以开始规划。' |
| 41 | } |
| 42 | ]) |
| 43 | |
| 44 | expect(messages).toEqual([ |
| 45 | { role: 'user', content: '影视从业者,内部研讨' }, |
| 46 | { role: 'assistant', content: '可以开始规划。' } |
| 47 | ]) |
| 48 | }) |
| 49 | }) |
| 50 |