note-state-id.test.mjs
54 lines 1.7 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 1 day 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 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