feat: AI 会话支持按轮保存完整笔记
This commit is contained in:
@@ -651,6 +651,41 @@ test('笔记可更新且必需保留正文或引用', () => {
|
||||
assert.strictEqual(s.updateNote('e1', 'nt_missing', { title: 'x' }), null);
|
||||
});
|
||||
|
||||
test('普通读书笔记新增与更新均完整保留超长正文', () => {
|
||||
const d = tmp();
|
||||
let s = storeAt(d);
|
||||
const addedText = '新增正文'.repeat(6000);
|
||||
const updatedText = '更新正文'.repeat(6500);
|
||||
const note = s.addNote('e1', { text: addedText, source: 'manual' });
|
||||
assert.strictEqual(note.text, addedText);
|
||||
assert.strictEqual(s.getState('e1').notes[0].text, addedText);
|
||||
|
||||
s = storeAt(d);
|
||||
assert.strictEqual(s.getState('e1').notes[0].text, addedText);
|
||||
const updated = s.updateNote('e1', note.id, { text: updatedText });
|
||||
assert.strictEqual(updated.text, updatedText);
|
||||
|
||||
s = storeAt(d);
|
||||
assert.strictEqual(s.getState('e1').notes[0].text, updatedText);
|
||||
});
|
||||
|
||||
test('富文本派生的普通笔记正文不截断', () => {
|
||||
const s = freshStore();
|
||||
const addedText = '富文本新增'.repeat(5000);
|
||||
const updatedText = '富文本更新'.repeat(5500);
|
||||
const note = s.addNote('e1', {
|
||||
richContent: { version: 2, ops: [{ insert: `${addedText}\n` }] }
|
||||
});
|
||||
assert.strictEqual(note.text, addedText);
|
||||
assert.strictEqual(note.richContent.ops[0].insert, `${addedText}\n`);
|
||||
|
||||
const updated = s.updateNote('e1', note.id, {
|
||||
richContent: { version: 2, ops: [{ insert: `${updatedText}\n` }] }
|
||||
});
|
||||
assert.strictEqual(updated.text, updatedText);
|
||||
assert.strictEqual(updated.richContent.ops[0].insert, `${updatedText}\n`);
|
||||
});
|
||||
|
||||
test('笔记本名称不区分大小写去重,删除后笔记移入未分类', () => {
|
||||
const s = freshStore();
|
||||
const collection = s.addCollection({ name: 'Research' });
|
||||
@@ -726,6 +761,7 @@ test('无关联笔记独立持久化且不计入书库卡片笔记数', () => {
|
||||
test('旧版 reader.json 安全迁移为 v6 并保留阅读数据', () => {
|
||||
const d = tmp();
|
||||
const file = path.join(d, 'reader.json');
|
||||
const legacyText = '旧版超长正文'.repeat(4000);
|
||||
const legacy = {
|
||||
entries: {
|
||||
e1: {
|
||||
@@ -733,7 +769,7 @@ test('旧版 reader.json 安全迁移为 v6 并保留阅读数据', () => {
|
||||
bookmarks: [{ id: 'bm_old', locator: { page: 8 }, at: 11 }],
|
||||
notes: [{
|
||||
id: 'nt_old',
|
||||
text: '旧笔记',
|
||||
text: legacyText,
|
||||
quote: '旧引用',
|
||||
kind: 'ai',
|
||||
at: 123,
|
||||
@@ -748,6 +784,7 @@ test('旧版 reader.json 安全迁移为 v6 并保留阅读数据', () => {
|
||||
assert.deepStrictEqual(state.progress, legacy.entries.e1.progress);
|
||||
assert.deepStrictEqual(state.bookmarks, legacy.entries.e1.bookmarks);
|
||||
assert.strictEqual(state.notes[0].id, 'nt_old');
|
||||
assert.strictEqual(state.notes[0].text, legacyText);
|
||||
assert.strictEqual(state.notes[0].source, 'ai');
|
||||
assert.strictEqual(state.notes[0].createdAt, 123);
|
||||
assert.strictEqual(state.notes[0].updatedAt, 123);
|
||||
@@ -778,7 +815,7 @@ test('字段限制、来源校验和安全 ID 校验生效', () => {
|
||||
text: 'x'.repeat(25000),
|
||||
tags: Array.from({ length: 40 }, (_, i) => `tag-${i}`)
|
||||
});
|
||||
assert.strictEqual(note.text.length, 20000);
|
||||
assert.strictEqual(note.text.length, 25000);
|
||||
assert.strictEqual(note.tags.length, 30);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user