chunk.test.mjs
57 lines 2.0 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 1 day ago
1 /**
2 * Chunk tests: chunkNote produces stable ids, metadata on each chunk, split by heading/size.
3 */
4 import { describe, it } from 'node:test';
5 import assert from 'node:assert';
6 import { chunkNote, stableChunkId } from '../lib/chunk.mjs';
7
8 describe('chunkNote', () => {
9 it('returns chunks with id, text, path, project, tags, date', () => {
10 const note = {
11 body: '# First\n\nParagraph one.\n\n## Second\n\nParagraph two.',
12 path: 'inbox/one.md',
13 project: 'foo',
14 tags: ['a', 'b'],
15 date: '2025-03-01',
16 };
17 const chunks = chunkNote(note);
18 assert(Array.isArray(chunks));
19 assert(chunks.length >= 1);
20 for (const c of chunks) {
21 assert.strictEqual(typeof c.id, 'string');
22 assert(c.id.length > 0);
23 assert.strictEqual(c.path, 'inbox/one.md');
24 assert.strictEqual(c.project, 'foo');
25 assert.deepStrictEqual(c.tags, ['a', 'b']);
26 assert.strictEqual(c.date, '2025-03-01');
27 assert.strictEqual(typeof c.text, 'string');
28 }
29 });
30
31 it('produces stable chunk ids for same path and index', () => {
32 const id1 = stableChunkId('inbox/foo.md', 0);
33 const id2 = stableChunkId('inbox/foo.md', 0);
34 assert.strictEqual(id1, id2);
35 assert.notStrictEqual(stableChunkId('inbox/foo.md', 1), id1);
36 assert.notStrictEqual(stableChunkId('inbox/bar.md', 0), id1);
37 });
38
39 it('splits by heading when possible', () => {
40 const note = {
41 body: '## A\n\nText A.\n\n## B\n\nText B.',
42 path: 'p.md',
43 };
44 const chunks = chunkNote(note);
45 assert(chunks.length >= 2);
46 assert(chunks.some((c) => c.text.includes('Text A')));
47 assert(chunks.some((c) => c.text.includes('Text B')));
48 });
49
50 it('respects chunkSize option for long content', () => {
51 const long = 'x'.repeat(3000);
52 const note = { body: long, path: 'p.md' };
53 const chunks = chunkNote(note, { chunkSize: 500, chunkOverlap: 50 });
54 assert(chunks.length >= 2);
55 chunks.forEach((c) => assert(c.text.length <= 600));
56 });
57 });
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