openpencil/tests/engine/app/diagnostics/recorder.test.ts
Danila Poyarkov 5f8a373b2b
feat(diagnostics): add local usage and diagnostics foundation
Supersedes #572. Adds local structured AI usage and diagnostics history, typed diagnostic events, localized Usage/Diagnostics settings, shared IndexedDB lifecycle, and consolidated button/dialog primitives.
2026-08-24 16:56:40 +03:00

28 lines
839 B
TypeScript

import { beforeEach, describe, expect, test } from 'bun:test'
import { diagnostics, recordChatCompleted } from '@/app/diagnostics'
import { isDiagnosticsEnabled } from '@/app/diagnostics/settings'
void isDiagnosticsEnabled
describe('diagnostics recorder', () => {
beforeEach(async () => {
await diagnostics.clear()
})
test('records structured events and exports them', async () => {
recordChatCompleted({ finishReason: 'stop' })
const events = await diagnostics.list()
expect(events).toHaveLength(1)
expect(events[0]?.name).toBe('chat.completed')
expect(await diagnostics.export()).toContain('chat.completed')
})
test('clears recorded events', async () => {
recordChatCompleted({ finishReason: 'stop' })
await diagnostics.clear()
expect(await diagnostics.list()).toHaveLength(0)
})
})