canister-frontmatter.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 { |
| 4 | displayTitleFromHostedNote, |
| 5 | parseCanisterFrontmatter, |
| 6 | titleFromCanisterFrontmatter, |
| 7 | titleFromMarkdownBody, |
| 8 | titleFromPathStem, |
| 9 | } from '../lib/canister-frontmatter.mjs'; |
| 10 | |
| 11 | describe('canister frontmatter parsing', () => { |
| 12 | it('reads title from object frontmatter', () => { |
| 13 | assert.equal(titleFromCanisterFrontmatter({ title: ' A ', project: 'x' }), 'A'); |
| 14 | }); |
| 15 | |
| 16 | it('reads title from normal JSON string', () => { |
| 17 | const s = JSON.stringify({ title: 'Parity', source: 'hub' }); |
| 18 | assert.equal(titleFromCanisterFrontmatter(s), 'Parity'); |
| 19 | }); |
| 20 | |
| 21 | it('reads title from escaped-inner-json string (Motoko-style)', () => { |
| 22 | const s = '{\\"source\\":\\"hub\\",\\"title\\":\\"Provenance parity.\\"}'; |
| 23 | assert.equal(titleFromCanisterFrontmatter(s), 'Provenance parity.'); |
| 24 | const o = parseCanisterFrontmatter(s); |
| 25 | assert.equal(o?.source, 'hub'); |
| 26 | }); |
| 27 | |
| 28 | it('returns null when missing', () => { |
| 29 | assert.equal(titleFromCanisterFrontmatter('{}'), null); |
| 30 | assert.equal(titleFromCanisterFrontmatter(null), null); |
| 31 | }); |
| 32 | |
| 33 | it('titleFromMarkdownBody reads first ATX heading (# or ##)', () => { |
| 34 | assert.equal(titleFromMarkdownBody('# Hello world\n\nMore'), 'Hello world'); |
| 35 | assert.equal(titleFromMarkdownBody(' ## Not used\n# Real'), 'Not used'); |
| 36 | assert.equal(titleFromMarkdownBody('## Idempotency\n\nBody'), 'Idempotency'); |
| 37 | }); |
| 38 | |
| 39 | it('titleFromPathStem uses filename', () => { |
| 40 | assert.equal(titleFromPathStem('inbox/FINAL-PRE-LAUNCH.md'), 'FINAL PRE LAUNCH'); |
| 41 | }); |
| 42 | |
| 43 | it('displayTitleFromHostedNote prefers frontmatter then body then path', () => { |
| 44 | assert.equal( |
| 45 | displayTitleFromHostedNote({ |
| 46 | path: 'x/y.md', |
| 47 | frontmatter: '{}', |
| 48 | body: '# From body\n', |
| 49 | }), |
| 50 | 'From body' |
| 51 | ); |
| 52 | assert.equal( |
| 53 | displayTitleFromHostedNote({ |
| 54 | path: 'projects/foo/PARITY-PLAN.md', |
| 55 | frontmatter: '{}', |
| 56 | body: 'no heading', |
| 57 | }), |
| 58 | 'PARITY PLAN' |
| 59 | ); |
| 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
2 days ago