mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
Release version 0.16.3
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { normalizeDecryptedMessage } from './normalize'
|
||||
import type { DecryptedMessage } from '@/types/api'
|
||||
|
||||
function makeMessage(content: unknown): DecryptedMessage {
|
||||
return {
|
||||
id: 'msg-1',
|
||||
seq: 1,
|
||||
localId: null,
|
||||
content,
|
||||
createdAt: 1_742_372_800_000
|
||||
}
|
||||
}
|
||||
|
||||
describe('normalizeDecryptedMessage', () => {
|
||||
it('drops unsupported Claude system output records', () => {
|
||||
const message = makeMessage({
|
||||
role: 'agent',
|
||||
content: {
|
||||
type: 'output',
|
||||
data: {
|
||||
type: 'system',
|
||||
subtype: 'stop_hook_summary',
|
||||
uuid: 'sys-1'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
expect(normalizeDecryptedMessage(message)).toBeNull()
|
||||
})
|
||||
|
||||
it('drops Claude init system output records', () => {
|
||||
const message = makeMessage({
|
||||
role: 'agent',
|
||||
content: {
|
||||
type: 'output',
|
||||
data: {
|
||||
type: 'system',
|
||||
subtype: 'init',
|
||||
uuid: 'sys-init',
|
||||
session_id: 'session-1'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
expect(normalizeDecryptedMessage(message)).toBeNull()
|
||||
})
|
||||
|
||||
it('keeps known Claude system subtypes as normalized events', () => {
|
||||
const message = makeMessage({
|
||||
role: 'agent',
|
||||
content: {
|
||||
type: 'output',
|
||||
data: {
|
||||
type: 'system',
|
||||
subtype: 'turn_duration',
|
||||
uuid: 'sys-2',
|
||||
durationMs: 1200
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
expect(normalizeDecryptedMessage(message)).toMatchObject({
|
||||
id: 'msg-1',
|
||||
role: 'event',
|
||||
isSidechain: false,
|
||||
content: {
|
||||
type: 'turn-duration',
|
||||
durationMs: 1200
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps the stringify fallback for unknown non-system agent payloads', () => {
|
||||
const message = makeMessage({
|
||||
role: 'agent',
|
||||
content: {
|
||||
type: 'output',
|
||||
data: {
|
||||
type: 'assistant',
|
||||
foo: 'bar'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const normalized = normalizeDecryptedMessage(message)
|
||||
|
||||
expect(normalized).toMatchObject({
|
||||
id: 'msg-1',
|
||||
role: 'agent',
|
||||
isSidechain: false
|
||||
})
|
||||
|
||||
expect(normalized?.role).toBe('agent')
|
||||
if (!normalized || normalized.role !== 'agent') {
|
||||
throw new Error('Expected agent message')
|
||||
}
|
||||
const firstBlock = normalized.content[0]
|
||||
expect(firstBlock).toMatchObject({
|
||||
type: 'text',
|
||||
})
|
||||
if (firstBlock.type !== 'text') {
|
||||
throw new Error('Expected fallback text block')
|
||||
}
|
||||
expect(firstBlock.text).toContain('"foo": "bar"')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user