aa2c7dfed3
Add semi-automatic knowledge suggestions and user-confirmed injection across chat, interactive, auto, and wizard modes; fix writing flows to persist full systemPrompt in contextJson. Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
import { mkdtempSync, rmSync } from 'fs'
|
|
import { join } from 'path'
|
|
import { tmpdir } from 'os'
|
|
import { BookRegistryService } from '../../src/main/services/book-registry'
|
|
import { buildFlowContextPayload } from '../../src/main/services/flow-context.util'
|
|
import { KnowledgeRepository } from '../../src/main/db/repositories/knowledge.repo'
|
|
|
|
describe('flow-context.util', () => {
|
|
let userDir: string
|
|
let registry: BookRegistryService
|
|
let bookId: string
|
|
|
|
beforeEach(() => {
|
|
userDir = mkdtempSync(join(tmpdir(), 'bilin-flow-ctx-'))
|
|
registry = new BookRegistryService(userDir)
|
|
bookId = registry.create({ name: '书', category: '玄幻' }).id
|
|
})
|
|
|
|
afterEach(() => rmSync(userDir, { recursive: true, force: true }))
|
|
|
|
it('buildFlowContextPayload stores systemPrompt and summary', () => {
|
|
const db = registry.getDb(bookId)
|
|
const entry = new KnowledgeRepository(db).create({
|
|
type: 'fact',
|
|
title: '测试知识',
|
|
content: '内容',
|
|
status: 'approved'
|
|
})
|
|
const payload = buildFlowContextPayload(
|
|
{
|
|
chapterIds: [],
|
|
outlineIds: [],
|
|
settingIds: [],
|
|
inspirationIds: [],
|
|
knowledgeIds: [entry.id]
|
|
},
|
|
registry,
|
|
bookId,
|
|
'作者'
|
|
)
|
|
expect(payload.systemPrompt).toContain('测试知识')
|
|
expect(payload.contextSummary).toContain('1')
|
|
db.close()
|
|
})
|
|
})
|