mcp-sampling-index-enrich.test.mjs
63 lines 2.1 KB
Raw
sha256:8d46372e39d2d5a54fd93a8b1c27922fe0d9b22a72197345f1d2c71701cc4ce2 feat(auth): persistent login system + C7 session introspection Human minor ⚠ breaking 17 days ago
1 import { describe, it, mock, beforeEach } from 'node:test';
2 import assert from 'node:assert/strict';
3
4 describe('enrichIndexedNotes', () => {
5 const mockNotes = [
6 { path: 'inbox/note1.md', body: 'Content of note 1', frontmatter: {} },
7 { path: 'inbox/note2.md', body: 'Content of note 2', frontmatter: {} },
8 { path: 'inbox/note3.md', body: 'Already enriched', frontmatter: { ai_summary: 'exists' } },
9 { path: 'inbox/empty.md', body: '', frontmatter: {} },
10 ];
11
12 function makeMockServer({ response = 'Summary text', sampling = true } = {}) {
13 return {
14 server: {
15 getClientCapabilities: () => (sampling ? { sampling: {} } : {}),
16 createMessage: async () => ({
17 content: { type: 'text', text: response },
18 model: 'mock',
19 role: 'assistant',
20 }),
21 },
22 };
23 }
24
25 it('skips notes with existing ai_summary', async () => {
26 const enrichableNotes = mockNotes.filter((n) => n.body && !n.frontmatter?.ai_summary);
27 assert.equal(enrichableNotes.length, 2);
28 const skippedNote = mockNotes.find((n) => n.frontmatter?.ai_summary);
29 assert.ok(skippedNote);
30 assert.equal(skippedNote.path, 'inbox/note3.md');
31 });
32
33 it('skips notes with empty body', async () => {
34 const enrichable = mockNotes.filter((n) => n.path && n.body && !n.frontmatter?.ai_summary);
35 assert.equal(enrichable.length, 2);
36 assert.ok(!enrichable.find((n) => n.path === 'inbox/empty.md'));
37 });
38
39 it('reports progress correctly', async () => {
40 const progressCalls = [];
41 const onProgress = async (done, total) => {
42 progressCalls.push({ done, total });
43 };
44
45 const notes = [
46 { path: 'a.md', body: 'content a', frontmatter: {} },
47 { path: 'b.md', body: 'content b', frontmatter: {} },
48 ];
49
50 for (let i = 0; i < notes.length; i++) {
51 await onProgress(i + 1, notes.length);
52 }
53
54 assert.equal(progressCalls.length, 2);
55 assert.deepEqual(progressCalls[0], { done: 1, total: 2 });
56 assert.deepEqual(progressCalls[1], { done: 2, total: 2 });
57 });
58
59 it('limits to max 200 notes', () => {
60 const limit = Math.min(300, 200);
61 assert.equal(limit, 200);
62 });
63 });
File History 2 commits
sha256:8d46372e39d2d5a54fd93a8b1c27922fe0d9b22a72197345f1d2c71701cc4ce2 feat(auth): persistent login system + C7 session introspection Human minor 17 days ago