62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import type { NativeChatMessage } from '../../../src/shared/native-chat-types'
|
|
import { isNoiseMessage, stripNoiseMessages } from './mobile-native-chat-noise'
|
|
|
|
function msg(
|
|
role: NativeChatMessage['role'],
|
|
text: string,
|
|
blocks?: NativeChatMessage['blocks']
|
|
): NativeChatMessage {
|
|
return {
|
|
id: text.slice(0, 8),
|
|
role,
|
|
blocks: blocks ?? [{ type: 'text', text }],
|
|
timestamp: 0,
|
|
source: 'transcript'
|
|
}
|
|
}
|
|
|
|
describe('isNoiseMessage', () => {
|
|
it('flags task-notification and system-reminder user turns', () => {
|
|
expect(isNoiseMessage(msg('user', '<task-notification>\n<task-id>x</task-id>'))).toBe(true)
|
|
expect(isNoiseMessage(msg('user', '<system-reminder>\nbe careful'))).toBe(true)
|
|
expect(
|
|
isNoiseMessage(
|
|
msg(
|
|
'user',
|
|
'Caveat: The messages below were generated by the user while running local commands'
|
|
)
|
|
)
|
|
).toBe(true)
|
|
expect(isNoiseMessage(msg('user', '[Request interrupted by user]'))).toBe(true)
|
|
})
|
|
|
|
it('flags inter-agent harness turns (teammate/agent messages)', () => {
|
|
expect(isNoiseMessage(msg('user', '<teammate-message>ping</teammate-message>'))).toBe(true)
|
|
expect(isNoiseMessage(msg('user', '<agent-message>status update'))).toBe(true)
|
|
})
|
|
|
|
it('keeps real user messages', () => {
|
|
expect(isNoiseMessage(msg('user', 'make it work for codex'))).toBe(false)
|
|
// A genuine custom tag is not a known harness tag, so it stays a user turn.
|
|
expect(isNoiseMessage(msg('user', '<bash-brothers> is my band'))).toBe(false)
|
|
})
|
|
|
|
it('keeps assistant and tool turns', () => {
|
|
expect(isNoiseMessage(msg('assistant', '<system-reminder> in prose'))).toBe(false)
|
|
})
|
|
|
|
it('keeps a user turn that carries tool results', () => {
|
|
expect(isNoiseMessage(msg('user', '', [{ type: 'tool-result', output: 'ok' }]))).toBe(false)
|
|
})
|
|
|
|
it('stripNoiseMessages removes only the noise', () => {
|
|
const out = stripNoiseMessages([
|
|
msg('user', 'hello'),
|
|
msg('user', '<task-notification>done'),
|
|
msg('assistant', 'hi')
|
|
])
|
|
expect(out.map((m) => m.role)).toEqual(['user', 'assistant'])
|
|
})
|
|
})
|