operator-canister-backup.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'; |
| 3 | import crypto from 'node:crypto'; |
| 4 | import { parseCanisterProposalGetBody } from '../lib/canister-proposal-response-parse.mjs'; |
| 5 | import { |
| 6 | OPERATOR_BACKUP_MAGIC, |
| 7 | buildOperatorVaultPayload, |
| 8 | decryptOperatorBackupToUtf8, |
| 9 | encryptOperatorBackupUtf8, |
| 10 | safeVaultFileToken, |
| 11 | utcBackupStamp, |
| 12 | } from '../lib/operator-canister-backup.mjs'; |
| 13 | |
| 14 | const SAMPLE_KEY_HEX = crypto.randomBytes(32).toString('hex'); |
| 15 | |
| 16 | describe('buildOperatorVaultPayload', () => { |
| 17 | it('includes format_version 2 and notes + proposals', () => { |
| 18 | const p = buildOperatorVaultPayload('default', [{ path: 'a.md' }], [{ proposal_id: 'p1' }]); |
| 19 | assert.strictEqual(p.format_version, 2); |
| 20 | assert.strictEqual(p.kind, 'knowtation-operator-vault-export'); |
| 21 | assert.strictEqual(p.vault_id, 'default'); |
| 22 | assert.strictEqual(p.notes.length, 1); |
| 23 | assert.strictEqual(p.proposals.length, 1); |
| 24 | assert.match(p.exported_at, /^\d{4}-\d{2}-\d{2}T/); |
| 25 | }); |
| 26 | }); |
| 27 | |
| 28 | describe('encryptOperatorBackupUtf8 / decryptOperatorBackupToUtf8', () => { |
| 29 | it('roundtrips JSON', () => { |
| 30 | const plain = JSON.stringify({ hello: 'world', n: 1 }); |
| 31 | const enc = encryptOperatorBackupUtf8(plain, SAMPLE_KEY_HEX); |
| 32 | assert.ok(enc.subarray(0, 4).equals(OPERATOR_BACKUP_MAGIC)); |
| 33 | const out = decryptOperatorBackupToUtf8(enc, SAMPLE_KEY_HEX); |
| 34 | assert.strictEqual(out, plain); |
| 35 | }); |
| 36 | |
| 37 | it('rejects wrong key length', () => { |
| 38 | assert.throws(() => encryptOperatorBackupUtf8('x', 'abcd'), /64 hex/); |
| 39 | }); |
| 40 | }); |
| 41 | |
| 42 | describe('safeVaultFileToken', () => { |
| 43 | it('replaces path separators', () => { |
| 44 | assert.strictEqual(safeVaultFileToken('a/b:c'), 'a_b_c'); |
| 45 | }); |
| 46 | }); |
| 47 | |
| 48 | describe('utcBackupStamp', () => { |
| 49 | it('matches YYYYMMDDTHHMMSSZ shape', () => { |
| 50 | const s = utcBackupStamp(new Date('2026-04-08T15:30:22.000Z')); |
| 51 | assert.strictEqual(s, '20260408T153022Z'); |
| 52 | }); |
| 53 | }); |
| 54 | |
| 55 | describe('parseCanisterProposalGetBody', () => { |
| 56 | it('parses valid JSON', () => { |
| 57 | const o = parseCanisterProposalGetBody('p1', '{"proposal_id":"p1","path":"a.md"}', {}); |
| 58 | assert.strictEqual(o.proposal_id, 'p1'); |
| 59 | assert.strictEqual(o.path, 'a.md'); |
| 60 | }); |
| 61 | |
| 62 | it('returns placeholder when canister response is invalid JSON', () => { |
| 63 | const bad = '{"proposal_id":"p1","suggested_labels":[broken}'; |
| 64 | const o = parseCanisterProposalGetBody('p1', bad, { path: 'inbox/x.md', status: 'proposed' }); |
| 65 | assert.strictEqual(o._knowtation_backup_json_unparseable, true); |
| 66 | assert.strictEqual(o.path, 'inbox/x.md'); |
| 67 | assert.strictEqual(o.status, 'proposed'); |
| 68 | assert.ok(String(o._knowtation_backup_upstream_preview).includes('broken')); |
| 69 | }); |
| 70 | }); |
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