Files

39 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

import assert from 'node:assert/strict';
import test from 'node:test';
import {
buildMindSpacePageSaveInstructions,
extractMindSpacePagePatch,
mergeMindSpacePagePatch,
} from './mindspace-page-patch.mjs';
test('extractMindSpacePagePatch parses assistant update block', () => {
const text = `好的,标题已更新。
\`\`\`mindspace-page-update
{"title":"新标题","summary":"新摘要"}
\`\`\``;
assert.deepEqual(extractMindSpacePagePatch(text), {
title: '新标题',
summary: '新摘要',
});
});
test('mergeMindSpacePagePatch keeps unchanged fields', () => {
assert.deepEqual(
mergeMindSpacePagePatch(
{ title: '旧标题', summary: '旧摘要', content: '正文' },
{ title: '新标题' },
),
{ title: '新标题', summary: '旧摘要', content: '正文' },
);
});
test('buildMindSpacePageSaveInstructions mentions page id and block format', () => {
const lines = buildMindSpacePageSaveInstructions({
id: 'page-1',
contentFormat: 'markdown',
});
assert.match(lines.join('\n'), /page-1/);
assert.match(lines.join('\n'), /mindspace-page-update/);
});