import { describe, expect, it } from 'vitest'; import { parseTaskNotifications, sanitizeDisplayContent, } from '@shared/utils/contentSanitizer'; describe('contentSanitizer task notifications', () => { it('removes task-notification blocks and trailing output instructions from display text', () => { const content = [ 'Task finished.', '', 'task-123', 'completed', 'Background command "Run foo" completed (exit code 0)', '/tmp/task-123.log', '', 'Read the output file to retrieve the result: /tmp/task-123.log', ].join(''); expect(sanitizeDisplayContent(content)).toBe('Task finished.'); }); it('extracts task notifications from raw xml blocks', () => { const content = [ '', 'task-123', 'completed', 'Background command "Run foo" completed (exit code 0)', '/tmp/task-123.log', '', ].join(''); expect(parseTaskNotifications(content)).toEqual([ { taskId: 'task-123', status: 'completed', summary: 'Background command "Run foo" completed (exit code 0)', outputFile: '/tmp/task-123.log', }, ]); }); it('returns an empty array when no task notifications are present', () => { expect(parseTaskNotifications('normal user content')).toEqual([]); }); }); describe('contentSanitizer OpenCode delivery envelopes', () => { it('hides OpenCode delivery instructions and retry metadata while keeping inbound content', () => { const content = [ '', 'To make your reply visible in the app Messages UI, call MCP tool agent-teams_message_send.', '', '', '', '', 'This is retry attempt 3/3 for inbound app messageId "message-1".', '', '', 'New task assigned to you: #task-a Investigate failing command', '', ].join('\n'); expect(sanitizeDisplayContent(content)).toBe( 'New task assigned to you: #task-a Investigate failing command' ); }); });