87 lines
3.4 KiB
TypeScript
87 lines
3.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { isInternalMessage, shouldDropMessageFromHistory } 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('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);
|
|
});
|
|
|
|
it('filters OpenClaw heartbeat poll user turns', () => {
|
|
expect(isInternalMessage({ role: 'user', content: '[OpenClaw heartbeat poll]' })).toBe(true);
|
|
});
|
|
|
|
it('filters inter-session routing payloads', () => {
|
|
expect(isInternalMessage({
|
|
role: 'user',
|
|
content: '[Inter-session message] sourceSession=image_generate:abc sourceTool=image_generate',
|
|
})).toBe(true);
|
|
});
|
|
|
|
it('filters OpenClaw runtime continuation prompts', () => {
|
|
expect(isInternalMessage({ role: 'user', content: 'Continue the OpenClaw runtime event.' })).toBe(true);
|
|
});
|
|
|
|
it('filters runtime continuation prompts stored on msg.text', () => {
|
|
expect(isInternalMessage({
|
|
role: 'user',
|
|
content: [],
|
|
text: 'Continue the OpenClaw runtime event.',
|
|
})).toBe(true);
|
|
});
|
|
|
|
it('filters interim image-generation status narration', () => {
|
|
expect(isInternalMessage({
|
|
role: 'assistant',
|
|
content: '生成中,稍等 👨🚀',
|
|
})).toBe(true);
|
|
});
|
|
|
|
it('keeps assistant tool-call turns in history even when narration is internal', () => {
|
|
expect(shouldDropMessageFromHistory({
|
|
role: 'assistant',
|
|
content: [
|
|
{ type: 'text', text: '生成中,稍等 👨🚀' },
|
|
{ type: 'tool_use', id: 'tool-image', name: 'image_generate', input: { prompt: 'astronaut' } },
|
|
],
|
|
})).toBe(false);
|
|
expect(isInternalMessage({
|
|
role: 'assistant',
|
|
content: [
|
|
{ type: 'text', text: '生成中,稍等 👨🚀' },
|
|
{ type: 'tool_use', id: 'tool-image', name: 'image_generate', input: { prompt: 'astronaut' } },
|
|
],
|
|
})).toBe(true);
|
|
});
|
|
|
|
it('filters assistant turns that only contain chain-of-thought', () => {
|
|
expect(isInternalMessage({
|
|
role: 'assistant',
|
|
content: [{ type: 'thinking', thinking: 'The user is asking me to continue with an OpenClaw runtime event.' }],
|
|
})).toBe(true);
|
|
});
|
|
});
|