Files
NianToB/tests/unit/chat-internal-message-filter.test.ts
inman 0abc48189c
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled
feat: prepare Zhinian desktop pilot
2026-05-07 21:49:20 +08:00

60 lines
2.7 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { isInternalMessage } from '@/stores/chat/helpers';
describe('chat internal message filter', () => {
it('filters runtime system injection bundle like async exec completion payload', () => {
const content = [
'System (untrusted): [2026-04-22 10:06:24 GMT+8] Exec completed (nimbler, code 0) ...',
'An async command you ran earlier has completed. The result is shown in the system messages above. Handle the result internally. Do not relay it to the user unless explicitly requested.',
'Current time: Wednesday, April 22nd, 2026 - 10:06 (Asia/Shanghai) / 2026-04-22 02:06 UTC',
].join('\n\n');
expect(isInternalMessage({ role: 'user', content })).toBe(true);
});
it('filters standalone current-time runtime ping', () => {
const content = 'Current time: Wednesday, April 22nd, 2026 - 10:06 (Asia/Shanghai) / 2026-04-22 02:06 UTC';
expect(isInternalMessage({ role: 'assistant', content })).toBe(true);
});
it('filters OpenClaw heartbeat poll user messages', () => {
expect(isInternalMessage({ role: 'user', content: '[OpenClaw heartbeat poll]' })).toBe(true);
expect(isInternalMessage({
role: 'user',
content: [
'Read HEARTBEAT.md if it exists (workspace context). Follow it strictly.',
'If nothing needs attention, reply HEARTBEAT_OK.',
'When reading HEARTBEAT.md, use workspace file /Users/test/.openclaw/workspace/HEARTBEAT.md.',
].join(' '),
})).toBe(true);
});
it('filters pure channel ingress metadata from Feishu', () => {
const content = 'System: [2026-04-27 11:09:29 GMT+8] Feishu[default] DM | ou_256bec6880a8c77271bc610c5e42fe89 [msg:om_x100b51d9784e2908c144d6c6cde19a6]';
expect(isInternalMessage({ role: 'user', content })).toBe(true);
});
it('does not filter user text that merely mentions a channel metadata line', () => {
const content = [
'System: [2026-04-27 11:09:29 GMT+8] Feishu[default] DM | ou_256bec6880a8c77271bc610c5e42fe89 [msg:om_x100b51d9784e2908c144d6c6cde19a6]',
'这条消息为什么会这样?',
].join('\n');
expect(isInternalMessage({ role: 'user', content })).toBe(false);
});
it('does not filter normal user message that starts with current time', () => {
const content = 'Current time: 北京现在几点?';
expect(isInternalMessage({ role: 'user', content })).toBe(false);
});
it('does not filter normal assistant text that mentions async completion phrase only', () => {
const content = 'The sentence "An async command you ran earlier has completed" is just an example in docs.';
expect(isInternalMessage({ role: 'assistant', content })).toBe(false);
});
});