import { describe, it, expect } from 'vitest'; import { parseAiResponse } from '@main/ai/schema.js'; describe('parseAiResponse', () => { it('accepts valid Korean title, 3-line summary, kebab tags', () => { const r = parseAiResponse({ title: '회의 요약', summary: '첫 줄\n둘째 줄\n셋째 줄', tags: ['api-timeout', 'meeting'] }); expect(r.title).toBe('회의 요약'); expect(r.summary.split('\n')).toHaveLength(3); expect(r.tags).toEqual(['api-timeout', 'meeting']); }); it('rejects title without Korean', () => { expect(() => parseAiResponse({ title: 'English only', summary: 'a\nb\nc', tags: [] }) ).toThrow(/korean/i); }); it('pads short summary to 3 lines', () => { const r = parseAiResponse({ title: '제목', summary: '한 줄', tags: [] }); expect(r.summary.split('\n')).toHaveLength(3); }); it('compresses long summary to 3 lines', () => { const r = parseAiResponse({ title: '제목', summary: 'a\nb\nc\nd\ne', tags: [] }); const lines = r.summary.split('\n'); expect(lines).toHaveLength(3); expect(lines[2]).toBe('c d e'); }); it('filters invalid tags', () => { const r = parseAiResponse({ title: '제목', summary: 'a\nb\nc', tags: ['good-tag', 'BadCase', 'has space', 'ok2', ''] }); expect(r.tags).toEqual(['good-tag', 'ok2']); }); it('caps tags to 3', () => { const r = parseAiResponse({ title: '제목', summary: 'a\nb\nc', tags: ['a', 'b', 'c', 'd', 'e'] }); expect(r.tags).toHaveLength(3); }); it('rejects non-object input', () => { expect(() => parseAiResponse('nope')).toThrow(); }); });