chunk.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
11 days 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
4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
11 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b
fix(7C-L1b): route hosted delegation proposals through cani…
Human
minor
⚠
31 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91
fix: repair endpoint now sets has_active_subscription when …
Human
minor
⚠
51 days ago
sha256:6a102aafafdfe7e70a24f4e59740200f0ee713ce7915f1b53e9d4ba5ee8b4410
Initial Muse snapshot
Human
83 days ago