import { renderMsg, stripAttachmentTags, stripAllInternalTags } from './message'; describe('renderMsg', () => { it('should render message with reasoning and output tag adjacent correctly', () => { const problematicText = 'L\'utente vuole che io elenchi i parametri dell\'ALBERO ESISTENTE.\n\n\n\nRecupero tutti i 7 parametri dell\'ALBERO ESISTENTE...'; const result = renderMsg(problematicText, false, 'Reasoning...', true); expect(result.text).toBe( '
Reasoning...L\'utente vuole che io elenchi i parametri dell\'ALBERO ESISTENTE.
\n\n\n\n

Recupero tutti i 7 parametri dell\'ALBERO ESISTENTE...

' ); }); }); describe('stripAttachmentTags', () => { it('strips tags', () => { const input = 'hello some content world'; expect(stripAttachmentTags(input)).toBe('hello world'); }); it('strips tags', () => { const input = 'before \nhttps://example.com/file.txt\n after'; expect(stripAttachmentTags(input)).toBe('before after'); }); it('strips tags', () => { const input = 'before \nhttps://example.com/file.txt\n after'; expect(stripAttachmentTags(input)).toBe('before after'); }); it('returns the same string when no tags are present', () => { expect(stripAttachmentTags('plain text')).toBe('plain text'); }); }); describe('stripAllInternalTags', () => { it('strips wrapper tags', () => { expect(stripAllInternalTags('inner')) .toBe('inner'); }); it('strips wrapper tags', () => { expect(stripAllInternalTags('inner')) .toBe('inner'); }); it('strips wrapper tags', () => { expect(stripAllInternalTags('inner')) .toBe('inner'); }); it('strips wrapper tags', () => { expect(stripAllInternalTags('inner')) .toBe('inner'); }); it('strips self-closing document tags', () => { expect(stripAllInternalTags('before after')) .toBe('before after'); }); it('strips asset URLs', () => { const input = 'hello\n\nhttps://assets-staging.memori.ai/api/v2/asset/abc-123.md\n\nworld'; expect(stripAllInternalTags(input)).toBe('hello\n\nworld'); }); it('strips multiple asset URLs on separate lines', () => { const input = 'content\n\nhttps://assets-staging.memori.ai/api/v2/asset/abc.md\n\nhttps://assets-staging.memori.ai/api/v2/asset/def.txt'; expect(stripAllInternalTags(input)).toBe('content'); }); it('strips all tag types and asset URLs combined', () => { const input = [ '', '', 'User question here', '', '', 'https://example.com/source', 'https://example.com/link', 'https://assets-staging.memori.ai/api/v2/asset/file.md', ].join('\n'); expect(stripAllInternalTags(input)).toBe('User question here'); }); it('collapses excessive blank lines after stripping', () => { const input = 'hello\n\n\n\n\nworld'; expect(stripAllInternalTags(input)).toBe('hello\n\nworld'); }); it('returns empty string for input that is only tags', () => { expect(stripAllInternalTags('')).toBe(''); }); it('handles empty string', () => { expect(stripAllInternalTags('')).toBe(''); }); });