agent-ecosystem/test/shared/utils/inboxNoise.test.ts
iliya 94fc564bf5 feat: UI improvements, bug fixes, and protocol noise filtering
- Fix incorrect error message when attaching files to team lead while team is offline
- Kanban columns: color only on headers, body with 30% alpha tint per user preference
- Worktree projects now correctly detected on Dashboard via path-based detection
- Filter raw protocol messages (idle_notification, teammate-message) from lead thoughts
- Consistent text styles in Attachments section (From original message / From comments)
- Secondary sort for teams by lastActivity timestamp with alphabetical fallback
- Remove colored background from team cards, keep only left border
- Dynamic member color in Add Members dialog based on next available palette color
- Stylized @-mentions in task comments with colored MemberBadge
- Refactor CLI env resolution to shared utility
2026-03-24 17:47:15 +02:00

126 lines
4.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
isInboxNoiseMessage,
isOnlyTeammateMessageBlocks,
isThoughtProtocolNoise,
stripTeammateMessageBlocks,
} from '../../../src/shared/utils/inboxNoise';
describe('stripTeammateMessageBlocks', () => {
it('removes a single teammate-message block', () => {
const text =
'<teammate-message teammate_id="alice" color="#f00" summary="hi">Hello world</teammate-message>';
expect(stripTeammateMessageBlocks(text)).toBe('');
});
it('removes multiple teammate-message blocks', () => {
const text = [
'<teammate-message teammate_id="alice" color="#f00" summary="hi">Hello</teammate-message>',
'<teammate-message teammate_id="bob" color="#0f0" summary="ok">OK</teammate-message>',
].join('\n');
expect(stripTeammateMessageBlocks(text)).toBe('');
});
it('preserves normal text around teammate-message blocks', () => {
const text =
'Before\n<teammate-message teammate_id="alice" color="#f00" summary="hi">Hello</teammate-message>\nAfter';
expect(stripTeammateMessageBlocks(text)).toBe('Before\n\nAfter');
});
it('returns text unchanged when no blocks are present', () => {
const text = 'Just some normal text without protocol blocks.';
expect(stripTeammateMessageBlocks(text)).toBe(text);
});
});
describe('isOnlyTeammateMessageBlocks', () => {
it('returns true for a single block', () => {
expect(
isOnlyTeammateMessageBlocks(
'<teammate-message teammate_id="alice" color="#f00" summary="hi">Hello</teammate-message>'
)
).toBe(true);
});
it('returns true for multiple blocks with whitespace', () => {
const text = [
'<teammate-message teammate_id="a" color="" summary="">X</teammate-message>',
' ',
'<teammate-message teammate_id="b" color="" summary="">Y</teammate-message>',
].join('\n');
expect(isOnlyTeammateMessageBlocks(text)).toBe(true);
});
it('returns false when there is also regular text', () => {
const text =
'Hello\n<teammate-message teammate_id="a" color="" summary="">X</teammate-message>';
expect(isOnlyTeammateMessageBlocks(text)).toBe(false);
});
it('returns false for plain text', () => {
expect(isOnlyTeammateMessageBlocks('Just a normal message')).toBe(false);
});
});
describe('isThoughtProtocolNoise', () => {
it('detects idle_notification JSON', () => {
expect(
isThoughtProtocolNoise('{"type":"idle_notification","message":"alice is idle"}')
).toBe(true);
});
it('detects shutdown_request JSON', () => {
expect(
isThoughtProtocolNoise('{"type":"shutdown_request","reason":"done"}')
).toBe(true);
});
it('detects shutdown_approved JSON', () => {
expect(isThoughtProtocolNoise('{"type":"shutdown_approved"}')).toBe(true);
});
it('detects teammate_terminated JSON', () => {
expect(isThoughtProtocolNoise('{"type":"teammate_terminated"}')).toBe(true);
});
it('detects pure teammate-message XML', () => {
expect(
isThoughtProtocolNoise(
'<teammate-message teammate_id="alice" color="#f00" summary="hi">Hello</teammate-message>'
)
).toBe(true);
});
it('returns false for normal text', () => {
expect(isThoughtProtocolNoise('Reviewing the PR now.')).toBe(false);
});
it('returns false for non-noise JSON', () => {
expect(
isThoughtProtocolNoise('{"type":"message","message":"Hello from lead"}')
).toBe(false);
});
it('returns false for text with teammate-message mixed with content', () => {
expect(
isThoughtProtocolNoise(
'Starting work.\n<teammate-message teammate_id="a" color="" summary="">X</teammate-message>'
)
).toBe(false);
});
});
describe('isInboxNoiseMessage', () => {
it('detects idle_notification', () => {
expect(isInboxNoiseMessage('{"type":"idle_notification"}')).toBe(true);
});
it('does not flag regular JSON messages', () => {
expect(isInboxNoiseMessage('{"type":"message","text":"hi"}')).toBe(false);
});
it('does not flag plain text', () => {
expect(isInboxNoiseMessage('Hello world')).toBe(false);
});
});