gateway-note-provenance.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | import { test } from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { |
| 4 | mergeHostedNoteBodyForCanister, |
| 5 | isPostApiV1Notes, |
| 6 | } from '../hub/gateway/apply-note-provenance.mjs'; |
| 7 | |
| 8 | test('mergeHostedNoteBodyForCanister leaves frontmatter as object for single JSON encode (Motoko-safe)', () => { |
| 9 | const out = mergeHostedNoteBodyForCanister( |
| 10 | { |
| 11 | path: 'inbox/a.md', |
| 12 | body: 'hello', |
| 13 | frontmatter: { title: 'T', source: 'hub' }, |
| 14 | }, |
| 15 | 'google:108077705743543803349' |
| 16 | ); |
| 17 | assert.equal(typeof out.frontmatter, 'object'); |
| 18 | const fm = /** @type {Record<string, string>} */ (out.frontmatter); |
| 19 | assert.equal(fm.title, 'T'); |
| 20 | assert.equal(fm.source, 'hub'); |
| 21 | assert.equal(fm.knowtation_editor, 'google:108077705743543803349'); |
| 22 | assert.equal(fm.author_kind, 'human'); |
| 23 | assert.match(fm.knowtation_edited_at, /^\d{4}-\d{2}-\d{2}T/); |
| 24 | }); |
| 25 | |
| 26 | test('mergeHostedNoteBodyForCanister strips client forged reserved keys', () => { |
| 27 | const out = mergeHostedNoteBodyForCanister( |
| 28 | { |
| 29 | path: 'x.md', |
| 30 | body: 'b', |
| 31 | frontmatter: { |
| 32 | note: 'ok', |
| 33 | knowtation_editor: 'evil:1', |
| 34 | knowtation_edited_at: '1970-01-01T00:00:00.000Z', |
| 35 | }, |
| 36 | }, |
| 37 | 'github:7612643' |
| 38 | ); |
| 39 | const fm = /** @type {Record<string, string>} */ (out.frontmatter); |
| 40 | assert.equal(fm.note, 'ok'); |
| 41 | assert.equal(fm.knowtation_editor, 'github:7612643'); |
| 42 | assert.notEqual(fm.knowtation_edited_at, '1970-01-01T00:00:00.000Z'); |
| 43 | }); |
| 44 | |
| 45 | test('mergeHostedNoteBodyForCanister parses string frontmatter input', () => { |
| 46 | const out = mergeHostedNoteBodyForCanister( |
| 47 | { |
| 48 | path: 'y.md', |
| 49 | body: 'b', |
| 50 | frontmatter: '{"project":"p"}', |
| 51 | }, |
| 52 | 'google:1' |
| 53 | ); |
| 54 | const fm = /** @type {Record<string, string>} */ (out.frontmatter); |
| 55 | assert.equal(fm.project, 'p'); |
| 56 | assert.equal(fm.knowtation_editor, 'google:1'); |
| 57 | }); |
| 58 | |
| 59 | test('mergeHostedNoteBodyForCanister preserves tags and project for canister wire', () => { |
| 60 | const out = mergeHostedNoteBodyForCanister( |
| 61 | { |
| 62 | path: 'inbox/n.md', |
| 63 | body: 'hello', |
| 64 | frontmatter: { title: 'T', tags: 'alpha, beta', project: 'my-app' }, |
| 65 | }, |
| 66 | 'google:123' |
| 67 | ); |
| 68 | const fm = /** @type {Record<string, string>} */ (out.frontmatter); |
| 69 | assert.equal(fm.title, 'T'); |
| 70 | assert.equal(fm.tags, 'alpha, beta'); |
| 71 | assert.equal(fm.project, 'my-app'); |
| 72 | assert.ok(fm.knowtation_edited_at); |
| 73 | }); |
| 74 | |
| 75 | test('POST wire nests frontmatter object so Motoko never uses broken string extract', () => { |
| 76 | const out = mergeHostedNoteBodyForCanister( |
| 77 | { path: 'inbox/wire.md', body: 'b', frontmatter: { title: 'Wire' } }, |
| 78 | 'google:9' |
| 79 | ); |
| 80 | const wire = JSON.stringify(out); |
| 81 | assert.match(wire, /"frontmatter":\{/); |
| 82 | assert.doesNotMatch(wire, /"frontmatter":"\{/); |
| 83 | const parsed = JSON.parse(wire); |
| 84 | assert.equal(parsed.frontmatter.title, 'Wire'); |
| 85 | assert.equal(parsed.frontmatter.author_kind, 'human'); |
| 86 | }); |
| 87 | |
| 88 | test('isPostApiV1Notes matches notes collection POST only', () => { |
| 89 | assert.equal(isPostApiV1Notes('POST', '/api/v1/notes'), true); |
| 90 | assert.equal(isPostApiV1Notes('POST', '/api/v1/notes/'), true); |
| 91 | assert.equal(isPostApiV1Notes('GET', '/api/v1/notes'), false); |
| 92 | assert.equal(isPostApiV1Notes('POST', '/api/v1/notes/inbox/x.md'), false); |
| 93 | }); |
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