note-state-id.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
13 days ago
| 1 | /** |
| 2 | * @import { test } from 'node:test'; |
| 3 | * @import assert from 'node:assert/strict'; |
| 4 | */ |
| 5 | import { describe, it } from 'node:test'; |
| 6 | import assert from 'node:assert/strict'; |
| 7 | import { |
| 8 | absentNoteStateId, |
| 9 | fnv1a64Hex, |
| 10 | noteStateIdFromParts, |
| 11 | noteStateIdFromRawStrings, |
| 12 | noteStateIdFromHubNoteJson, |
| 13 | stableStringify, |
| 14 | } from '../lib/note-state-id.mjs'; |
| 15 | |
| 16 | describe('note-state-id', () => { |
| 17 | it('stableStringify sorts object keys', () => { |
| 18 | assert.equal(stableStringify({ b: 1, a: 2 }), '{"a":2,"b":1}'); |
| 19 | }); |
| 20 | |
| 21 | it('absentNoteStateId is stable kn1_ prefix', () => { |
| 22 | const a = absentNoteStateId(); |
| 23 | assert.ok(a.startsWith('kn1_')); |
| 24 | assert.equal(a.length, 4 + 16); |
| 25 | }); |
| 26 | |
| 27 | it('noteStateIdFromParts is deterministic', () => { |
| 28 | const x = noteStateIdFromParts({ title: 'Hi' }, 'body'); |
| 29 | const y = noteStateIdFromParts({ title: 'Hi' }, 'body'); |
| 30 | assert.equal(x, y); |
| 31 | }); |
| 32 | |
| 33 | it('noteStateIdFromRawStrings differs from reordered JSON object hash', () => { |
| 34 | const raw = '{"b":1,"a":2}'; |
| 35 | const fromRaw = noteStateIdFromRawStrings(raw, 'x'); |
| 36 | const fromObj = noteStateIdFromParts({ b: 1, a: 2 }, 'x'); |
| 37 | assert.notEqual(fromRaw, fromObj); |
| 38 | }); |
| 39 | |
| 40 | it('noteStateIdFromHubNoteJson handles object frontmatter', () => { |
| 41 | const id = noteStateIdFromHubNoteJson({ frontmatter: { z: 1 }, body: 'b' }); |
| 42 | assert.ok(id.startsWith('kn1_')); |
| 43 | }); |
| 44 | |
| 45 | it('noteStateIdFromHubNoteJson handles string frontmatter', () => { |
| 46 | const id = noteStateIdFromHubNoteJson({ frontmatter: '{"t":1}', body: 'b' }); |
| 47 | assert.ok(id.startsWith('kn1_')); |
| 48 | }); |
| 49 | |
| 50 | it('fnv1a64Hex matches single zero byte', () => { |
| 51 | const h = fnv1a64Hex(Buffer.from([0x00])); |
| 52 | assert.equal(h.length, 16); |
| 53 | }); |
| 54 | }); |
File History
4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
13 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b
fix(7C-L1b): route hosted delegation proposals through cani…
Human
minor
⚠
33 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91
fix: repair endpoint now sets has_active_subscription when …
Human
minor
⚠
52 days ago
sha256:6a102aafafdfe7e70a24f4e59740200f0ee713ce7915f1b53e9d4ba5ee8b4410
Initial Muse snapshot
Human
85 days ago