import { describe, it, expect } from 'vitest' import { AiClientService } from '../../src/main/services/ai-client.service' import { buildNamingPrompt, collectChaptersPlain, parseNamingJson } from '../../src/main/services/naming-check.service' import { DEFAULT_AI_CONFIG } from '../../src/shared/types' const AI_TEST_CONFIG = { ...DEFAULT_AI_CONFIG, timeoutMs: 240_000 } describe('naming check integration', () => { const client = new AiClientService(() => AI_TEST_CONFIG) it('IT-NAME-01: detects 林远 vs 林悦 from LM Studio', async () => { const prompt = buildNamingPrompt( ['林远'], collectChaptersPlain([{ title: '第一章', content: '
林悦走进院子,环顾四周。
' }]), [] ) let response = await client.chat([{ role: 'user', content: prompt }]) let rows try { rows = parseNamingJson(response) } catch { response = await client.chat([ { role: 'user', content: `${prompt}\n\n仅返回 JSON 数组,不要 markdown 或其它说明。` } ]) rows = parseNamingJson(response) } expect(rows.length).toBeGreaterThan(0) const hit = rows.some( (r) => (r.termA.includes('林远') && r.termB.includes('林悦')) || (r.termA.includes('林悦') && r.termB.includes('林远')) ) expect(hit).toBe(true) }, 180_000) })