test: complete P4.1 LM Studio coverage and fix auto/wizard handoff
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { DatabaseSync } from 'node:sqlite'
|
||||
import { migrate } from '../../src/main/db/migrate'
|
||||
import { AiSessionRepository } from '../../src/main/db/repositories/ai-session.repo'
|
||||
import { InteractiveRepository } from '../../src/main/db/repositories/interactive.repo'
|
||||
import { AutoWritingService } from '../../src/main/services/auto-writing.service'
|
||||
import { AiClientService } from '../../src/main/services/ai-client.service'
|
||||
import { DEFAULT_AI_CONFIG } from '../../src/shared/types'
|
||||
|
||||
const AI_TEST_CONFIG = { ...DEFAULT_AI_CONFIG, timeoutMs: 240_000, maxTokens: 4096 }
|
||||
const CONTEXT = '林远站在演武场中央,众人目光汇聚,等待入门考核开始。'
|
||||
|
||||
describe('AutoWritingService generate', () => {
|
||||
const service = (db: DatabaseSync) =>
|
||||
new AutoWritingService(db, new AiClientService(() => AI_TEST_CONFIG))
|
||||
|
||||
async function planFirstScene(db: DatabaseSync, svc: AutoWritingService, flowId: string): Promise<void> {
|
||||
await svc.planScenes(flowId, CONTEXT)
|
||||
}
|
||||
|
||||
it('IT-AUTO-02: generateNext writes non-empty scene', async () => {
|
||||
const db = new DatabaseSync(':memory:')
|
||||
migrate(db)
|
||||
const session = new AiSessionRepository(db).create('t', DEFAULT_AI_CONFIG.model)
|
||||
const svc = service(db)
|
||||
const flow = svc.start(session.id)
|
||||
svc.setGoal(flow.id, {
|
||||
chapterGoal: '林远通过入门考核,展现天赋震惊众人',
|
||||
wordMin: 800,
|
||||
wordMax: 1500
|
||||
})
|
||||
await planFirstScene(db, svc, flow.id)
|
||||
|
||||
let afterGen = await svc.generateNext(flow.id, CONTEXT, () => {})
|
||||
if (afterGen.step === 'naming_pause' && afterGen.namingPending) {
|
||||
afterGen = await svc.resolveNaming(
|
||||
flow.id,
|
||||
afterGen.namingPending.options[0]!,
|
||||
CONTEXT,
|
||||
() => {}
|
||||
)
|
||||
}
|
||||
|
||||
const scenes = new InteractiveRepository(db).listScenes(flow.id)
|
||||
expect(scenes.length).toBeGreaterThanOrEqual(1)
|
||||
expect(scenes[0]!.contentHtml.replace(/<[^>]+>/g, '').trim().length).toBeGreaterThan(20)
|
||||
db.close()
|
||||
}, 240_000)
|
||||
|
||||
it('IT-AUTO-03: pause and resume update step', async () => {
|
||||
const db = new DatabaseSync(':memory:')
|
||||
migrate(db)
|
||||
const session = new AiSessionRepository(db).create('t', DEFAULT_AI_CONFIG.model)
|
||||
const svc = service(db)
|
||||
const flow = svc.start(session.id)
|
||||
svc.setGoal(flow.id, {
|
||||
chapterGoal: '林远通过入门考核',
|
||||
wordMin: 800,
|
||||
wordMax: 1500
|
||||
})
|
||||
await planFirstScene(db, svc, flow.id)
|
||||
|
||||
const paused = svc.pause(flow.id)
|
||||
expect(paused.step).toBe('paused')
|
||||
|
||||
const resumed = svc.resume(flow.id)
|
||||
expect(resumed.step).toBe('auto_generate')
|
||||
db.close()
|
||||
}, 240_000)
|
||||
})
|
||||
Reference in New Issue
Block a user