feat: ship v0.3.0 with P2.1 editor polish and P3 AI collaboration
Add chapter reorder, search replace, inspiration capture, and AI chat with context editing, settings, offline handling, and naming checks. Fix dev black screen by keeping process.env reads in the main process only. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } 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 type { SqliteDb } from '../../src/main/db/types'
|
||||
|
||||
describe('AiSessionRepository', () => {
|
||||
let db: SqliteDb
|
||||
let repo: AiSessionRepository
|
||||
|
||||
beforeEach(() => {
|
||||
db = new DatabaseSync(':memory:')
|
||||
migrate(db)
|
||||
repo = new AiSessionRepository(db)
|
||||
})
|
||||
|
||||
afterEach(() => db.close())
|
||||
|
||||
it('creates session with empty context', () => {
|
||||
const session = repo.create('对话一', 'gemma-4-e4b-it')
|
||||
expect(session.title).toBe('对话一')
|
||||
expect(session.model).toBe('gemma-4-e4b-it')
|
||||
expect(session.context.chapterIds).toEqual([])
|
||||
expect(session.archived).toBe(false)
|
||||
})
|
||||
|
||||
it('lists sessions excluding archived by default', () => {
|
||||
const active = repo.create('活跃')
|
||||
const archived = repo.create('归档')
|
||||
repo.update(archived.id, { archived: true })
|
||||
|
||||
const list = repo.list()
|
||||
expect(list.map((s) => s.id)).toEqual([active.id])
|
||||
expect(repo.list(true).map((s) => s.id).sort()).toEqual([active.id, archived.id].sort())
|
||||
})
|
||||
|
||||
it('persists messages in order', () => {
|
||||
const session = repo.create()
|
||||
repo.addMessage(session.id, 'user', '你好')
|
||||
const assistant = repo.addMessage(session.id, 'assistant', '你好,有什么可以帮你?')
|
||||
|
||||
const messages = repo.listMessages(session.id)
|
||||
expect(messages).toHaveLength(2)
|
||||
expect(messages[0].role).toBe('user')
|
||||
expect(messages[1].id).toBe(assistant.id)
|
||||
})
|
||||
|
||||
it('updates context binding', () => {
|
||||
const session = repo.create()
|
||||
const updated = repo.update(session.id, {
|
||||
context: {
|
||||
chapterIds: ['ch-1'],
|
||||
outlineIds: [],
|
||||
settingIds: ['st-1'],
|
||||
inspirationIds: []
|
||||
}
|
||||
})
|
||||
expect(updated.context.chapterIds).toEqual(['ch-1'])
|
||||
expect(updated.context.settingIds).toEqual(['st-1'])
|
||||
})
|
||||
|
||||
it('deletes session and messages', () => {
|
||||
const session = repo.create()
|
||||
repo.addMessage(session.id, 'user', 'test')
|
||||
repo.delete(session.id)
|
||||
expect(repo.get(session.id)).toBeNull()
|
||||
expect(repo.listMessages(session.id)).toEqual([])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user