list-notes.test.mjs
92 lines 3.5 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 1 day ago
1 /**
2 * List-notes tests: runListNotes with folder, project, tag, since/until, limit, order, fields, countOnly.
3 */
4 import { describe, it, before, after } from 'node:test';
5 import assert from 'node:assert';
6 import path from 'path';
7 import { fileURLToPath } from 'url';
8 import { loadConfig } from '../lib/config.mjs';
9 import { runListNotes } from '../lib/list-notes.mjs';
10
11 const __dirname = path.dirname(fileURLToPath(import.meta.url));
12 const fixturesDir = path.join(__dirname, 'fixtures');
13
14 describe('runListNotes', () => {
15 let config;
16 const envBackup = {
17 KNOWTATION_VAULT_PATH: process.env.KNOWTATION_VAULT_PATH,
18 KNOWTATION_DATA_DIR: process.env.KNOWTATION_DATA_DIR,
19 };
20 const fixtureVaultAbs = path.join(fixturesDir, 'vault-fs');
21 before(() => {
22 // Pin vault so parallel test files or shell KNOWTATION_VAULT_PATH cannot skew this suite.
23 process.env.KNOWTATION_VAULT_PATH = fixtureVaultAbs;
24 delete process.env.KNOWTATION_DATA_DIR;
25 config = loadConfig(fixturesDir);
26 });
27 after(() => {
28 if (envBackup.KNOWTATION_VAULT_PATH !== undefined) {
29 process.env.KNOWTATION_VAULT_PATH = envBackup.KNOWTATION_VAULT_PATH;
30 } else {
31 delete process.env.KNOWTATION_VAULT_PATH;
32 }
33 if (envBackup.KNOWTATION_DATA_DIR !== undefined) {
34 process.env.KNOWTATION_DATA_DIR = envBackup.KNOWTATION_DATA_DIR;
35 } else {
36 delete process.env.KNOWTATION_DATA_DIR;
37 }
38 });
39
40 it('returns notes with total', () => {
41 const result = runListNotes(config, { limit: 10 });
42 assert(typeof result.total === 'number');
43 assert(Array.isArray(result.notes));
44 assert(result.notes.length <= 10);
45 if (result.notes.length) {
46 const n = result.notes[0];
47 assert(n.path);
48 assert(n.project !== undefined || n.tags !== undefined || n.date !== undefined);
49 }
50 });
51
52 it('filters by folder', () => {
53 const result = runListNotes(config, { folder: 'inbox', limit: 10 });
54 assert(result.notes.every((n) => n.path === 'inbox' || n.path.startsWith('inbox/')));
55 });
56
57 it('filters by project', () => {
58 const result = runListNotes(config, { project: 'foo', limit: 10 });
59 assert(result.notes.every((n) => n.project === 'foo'));
60 });
61
62 it('filters by tag', () => {
63 const result = runListNotes(config, { tag: 'b', limit: 10 });
64 assert(result.notes.every((n) => Array.isArray(n.tags) && n.tags.includes('b')));
65 });
66
67 it('respects limit and offset', () => {
68 const all = runListNotes(config, { limit: 100 });
69 const page1 = runListNotes(config, { limit: 1, offset: 0 });
70 const page2 = runListNotes(config, { limit: 1, offset: 1 });
71 assert.strictEqual(page1.notes.length, 1);
72 assert.strictEqual(page2.notes.length, Math.min(1, all.total - 1));
73 if (all.total >= 2) assert.notStrictEqual(page1.notes[0].path, page2.notes[0].path);
74 });
75
76 it('countOnly returns total only', () => {
77 const result = runListNotes(config, { countOnly: true });
78 assert(typeof result.total === 'number');
79 assert.strictEqual(result.notes, undefined);
80 });
81
82 it('content_scope approval_logs returns only paths under approvals/', () => {
83 const result = runListNotes(config, { content_scope: 'approval_logs', limit: 100 });
84 assert(result.notes.length >= 1);
85 assert(result.notes.every((n) => n.path === 'approvals' || n.path.startsWith('approvals/')));
86 });
87
88 it('content_scope notes excludes approval log paths', () => {
89 const result = runListNotes(config, { content_scope: 'notes', limit: 100 });
90 assert(result.notes.every((n) => n.path !== 'approvals' && !n.path.startsWith('approvals/')));
91 });
92 });
File History 2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor 1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6 docs: accept Calendar Events v0 spec with Phase 0 security … Human 1 day ago