feat: ship v0.6.0 with cockpit, knowledge base, and chapter bridge
Deliver P5 writer workflow: writing cockpit, manual knowledge CRUD with review, chapter bridge with optional AI, publish status, and stock buffer reminders. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { describe, it, expect, afterEach } from 'vitest'
|
||||
import { DatabaseSync } from 'node:sqlite'
|
||||
import { migrate } from '../../src/main/db/migrate'
|
||||
import { VolumeRepository } from '../../src/main/db/repositories/volume.repo'
|
||||
import { ChapterRepository } from '../../src/main/db/repositories/chapter.repo'
|
||||
import { ChapterBridgeService } from '../../src/main/services/chapter-bridge.service'
|
||||
import { AiClientService } from '../../src/main/services/ai-client.service'
|
||||
import { DEFAULT_AI_CONFIG } from '../../src/shared/types'
|
||||
import type { SqliteDb } from '../../src/main/db/types'
|
||||
|
||||
const AI_TEST_CONFIG = { ...DEFAULT_AI_CONFIG, timeoutMs: 240_000, maxTokens: 4096 }
|
||||
|
||||
describe('ChapterBridgeService', () => {
|
||||
let db: SqliteDb
|
||||
afterEach(() => db?.close())
|
||||
|
||||
it('UT-BRIDGE-01: extracts tail and head', () => {
|
||||
db = new DatabaseSync(':memory:')
|
||||
migrate(db)
|
||||
const volId = new VolumeRepository(db).create('卷一', 0).id
|
||||
const chapterRepo = new ChapterRepository(db)
|
||||
chapterRepo.create(volId, '上一章', 0, `<p>${'甲'.repeat(400)}</p>`)
|
||||
const cur = chapterRepo.create(volId, '本章', 1, '<p>开头内容</p>')
|
||||
const service = new ChapterBridgeService(db)
|
||||
const result = service.extract(cur.id)
|
||||
expect(result.previousTail.length).toBeLessThanOrEqual(300)
|
||||
expect(result.previousTail.length).toBeGreaterThan(50)
|
||||
expect(result.currentHead).toContain('开头')
|
||||
})
|
||||
|
||||
it('IT-BRIDGE-01: getBridge returns aiSuggestion from LM Studio', async () => {
|
||||
db = new DatabaseSync(':memory:')
|
||||
migrate(db)
|
||||
const volId = new VolumeRepository(db).create('卷一', 0).id
|
||||
const chapterRepo = new ChapterRepository(db)
|
||||
chapterRepo.create(
|
||||
volId,
|
||||
'上一章',
|
||||
0,
|
||||
'<p>林远站在演武场中央,众人目光汇聚,他知道从这一刻起一切都将不同。</p>'
|
||||
)
|
||||
const cur = chapterRepo.create(
|
||||
volId,
|
||||
'本章',
|
||||
1,
|
||||
'<p>晨光透过竹帘,林远深吸一口气推开了门。</p>'
|
||||
)
|
||||
const aiClient = new AiClientService(() => AI_TEST_CONFIG)
|
||||
const service = new ChapterBridgeService(db, aiClient)
|
||||
const result = await service.getBridge(cur.id, true)
|
||||
expect(result.aiSuggestion?.trim().length).toBeGreaterThan(10)
|
||||
}, 240_000)
|
||||
})
|
||||
Reference in New Issue
Block a user