mcp-sampling-enrich.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | import { describe, it } from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { parseEnrichResponse } from '../mcp/tools/enrich.mjs'; |
| 4 | |
| 5 | describe('parseEnrichResponse', () => { |
| 6 | it('parses valid JSON response', () => { |
| 7 | const raw = '{"title":"My Note","project":"my-project","tags":["tag1","tag2"]}'; |
| 8 | const result = parseEnrichResponse(raw); |
| 9 | assert.equal(result.title, 'My Note'); |
| 10 | assert.equal(result.project, 'my-project'); |
| 11 | assert.deepEqual(result.tags, ['tag1', 'tag2']); |
| 12 | }); |
| 13 | |
| 14 | it('strips markdown code fences', () => { |
| 15 | const raw = '```json\n{"title":"Note","project":null,"tags":["a"]}\n```'; |
| 16 | const result = parseEnrichResponse(raw); |
| 17 | assert.equal(result.title, 'Note'); |
| 18 | assert.equal(result.project, null); |
| 19 | assert.deepEqual(result.tags, ['a']); |
| 20 | }); |
| 21 | |
| 22 | it('normalizes project slug to lowercase kebab-case', () => { |
| 23 | const raw = '{"title":"X","project":"My Project Name","tags":[]}'; |
| 24 | const result = parseEnrichResponse(raw); |
| 25 | assert.equal(result.project, 'my-project-name'); |
| 26 | }); |
| 27 | |
| 28 | it('lowercases tags and deduplicates', () => { |
| 29 | const raw = '{"title":"X","project":null,"tags":["Foo","BAR","foo"]}'; |
| 30 | const result = parseEnrichResponse(raw); |
| 31 | assert.deepEqual(result.tags, ['foo', 'bar', 'foo']); |
| 32 | }); |
| 33 | |
| 34 | it('caps tags at 10', () => { |
| 35 | const tags = Array.from({ length: 15 }, (_, i) => `tag${i}`); |
| 36 | const raw = JSON.stringify({ title: 'X', project: null, tags }); |
| 37 | const result = parseEnrichResponse(raw); |
| 38 | assert.equal(result.tags.length, 10); |
| 39 | }); |
| 40 | |
| 41 | it('returns fallback for invalid JSON', () => { |
| 42 | const result = parseEnrichResponse('not json at all'); |
| 43 | assert.equal(result.title, null); |
| 44 | assert.equal(result.project, null); |
| 45 | assert.deepEqual(result.tags, []); |
| 46 | }); |
| 47 | |
| 48 | it('returns fallback for null input', () => { |
| 49 | const result = parseEnrichResponse(null); |
| 50 | assert.equal(result.title, null); |
| 51 | assert.deepEqual(result.tags, []); |
| 52 | }); |
| 53 | |
| 54 | it('handles empty strings gracefully', () => { |
| 55 | const raw = '{"title":"","project":"","tags":[""]}'; |
| 56 | const result = parseEnrichResponse(raw); |
| 57 | assert.equal(result.title, null); |
| 58 | assert.equal(result.project, null); |
| 59 | assert.deepEqual(result.tags, []); |
| 60 | }); |
| 61 | }); |
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