Release version 0.16.3

This commit is contained in:
weishu
2026-03-20 12:17:35 +08:00
parent 9742522ee8
commit 32f05d99a0
5 changed files with 162 additions and 16 deletions
+107
View File
@@ -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"')
})
})