canister-export-env.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 { mkdirSync, readFileSync, writeFileSync, rmSync } from 'node:fs'; |
| 4 | import { join } from 'node:path'; |
| 5 | import { tmpdir } from 'node:os'; |
| 6 | import { fileURLToPath } from 'node:url'; |
| 7 | import { |
| 8 | hubBaseUrlFromCanisterIds, |
| 9 | parseBackupVaultIds, |
| 10 | resolveBackupS3Prefix, |
| 11 | resolveCanisterBackupBaseUrl, |
| 12 | } from '../lib/canister-export-env.mjs'; |
| 13 | |
| 14 | const __dirname = fileURLToPath(new URL('.', import.meta.url)); |
| 15 | const repoRoot = join(__dirname, '..'); |
| 16 | |
| 17 | describe('hubBaseUrlFromCanisterIds', () => { |
| 18 | it('reads hub.ic from canister_ids.json in this repo', () => { |
| 19 | const ids = JSON.parse(readFileSync(join(repoRoot, 'hub/icp/canister_ids.json'), 'utf8')); |
| 20 | const url = hubBaseUrlFromCanisterIds(repoRoot); |
| 21 | assert.match(url, /^https:\/\/.+\.raw\.icp0\.io$/); |
| 22 | assert.strictEqual(url, `https://${ids.hub.ic}.raw.icp0.io`); |
| 23 | }); |
| 24 | |
| 25 | it('throws when hub.ic is missing', () => { |
| 26 | const dir = join(tmpdir(), `knowt-ce-${Date.now()}`); |
| 27 | mkdirSync(join(dir, 'hub/icp'), { recursive: true }); |
| 28 | writeFileSync(join(dir, 'hub/icp/canister_ids.json'), JSON.stringify({ hub: {} })); |
| 29 | try { |
| 30 | assert.throws(() => hubBaseUrlFromCanisterIds(dir), /Missing hub\.ic/); |
| 31 | } finally { |
| 32 | rmSync(dir, { recursive: true, force: true }); |
| 33 | } |
| 34 | }); |
| 35 | }); |
| 36 | |
| 37 | describe('resolveBackupS3Prefix', () => { |
| 38 | it('defaults when unset or empty (GitHub empty var)', () => { |
| 39 | assert.strictEqual(resolveBackupS3Prefix({}), 'knowtation-canister-backups/'); |
| 40 | assert.strictEqual(resolveBackupS3Prefix({ KNOWTATION_CANISTER_BACKUP_S3_PREFIX: '' }), 'knowtation-canister-backups/'); |
| 41 | assert.strictEqual(resolveBackupS3Prefix({ KNOWTATION_CANISTER_BACKUP_S3_PREFIX: ' ' }), 'knowtation-canister-backups/'); |
| 42 | }); |
| 43 | |
| 44 | it('normalizes custom prefix to single trailing slash', () => { |
| 45 | assert.strictEqual(resolveBackupS3Prefix({ KNOWTATION_CANISTER_BACKUP_S3_PREFIX: 'my/prefix' }), 'my/prefix/'); |
| 46 | assert.strictEqual(resolveBackupS3Prefix({ KNOWTATION_CANISTER_BACKUP_S3_PREFIX: 'my/prefix//' }), 'my/prefix/'); |
| 47 | }); |
| 48 | }); |
| 49 | |
| 50 | describe('parseBackupVaultIds', () => { |
| 51 | it('defaults to default vault', () => { |
| 52 | assert.deepStrictEqual(parseBackupVaultIds({}), ['default']); |
| 53 | }); |
| 54 | |
| 55 | it('uses KNOWTATION_CANISTER_BACKUP_VAULT_ID when VAULT_IDS unset', () => { |
| 56 | assert.deepStrictEqual(parseBackupVaultIds({ KNOWTATION_CANISTER_BACKUP_VAULT_ID: 'team' }), [ |
| 57 | 'team', |
| 58 | ]); |
| 59 | }); |
| 60 | |
| 61 | it('splits KNOWTATION_CANISTER_BACKUP_VAULT_IDS on commas', () => { |
| 62 | assert.deepStrictEqual( |
| 63 | parseBackupVaultIds({ KNOWTATION_CANISTER_BACKUP_VAULT_IDS: ' default , second ' }), |
| 64 | ['default', 'second'], |
| 65 | ); |
| 66 | }); |
| 67 | |
| 68 | it('VAULT_IDS wins over single VAULT_ID', () => { |
| 69 | assert.deepStrictEqual( |
| 70 | parseBackupVaultIds({ |
| 71 | KNOWTATION_CANISTER_BACKUP_VAULT_IDS: 'a,b', |
| 72 | KNOWTATION_CANISTER_BACKUP_VAULT_ID: 'ignored', |
| 73 | }), |
| 74 | ['a', 'b'], |
| 75 | ); |
| 76 | }); |
| 77 | }); |
| 78 | |
| 79 | describe('resolveCanisterBackupBaseUrl', () => { |
| 80 | it('prefers KNOWTATION_CANISTER_URL', () => { |
| 81 | const u = resolveCanisterBackupBaseUrl( |
| 82 | { |
| 83 | KNOWTATION_CANISTER_URL: 'https://abc.icp0.io/', |
| 84 | KNOWTATION_CANISTER_BACKUP_URL: 'https://wrong.icp0.io', |
| 85 | KNOWTATION_CANISTER_BACKUP_USER_ID: 'x', |
| 86 | }, |
| 87 | repoRoot, |
| 88 | ); |
| 89 | assert.strictEqual(u, 'https://abc.icp0.io'); |
| 90 | }); |
| 91 | |
| 92 | it('uses KNOWTATION_CANISTER_BACKUP_URL when CANISTER_URL unset', () => { |
| 93 | const u = resolveCanisterBackupBaseUrl( |
| 94 | { |
| 95 | KNOWTATION_CANISTER_BACKUP_URL: 'https://xyz.icp0.io/', |
| 96 | KNOWTATION_CANISTER_BACKUP_USER_ID: 'x', |
| 97 | }, |
| 98 | repoRoot, |
| 99 | ); |
| 100 | assert.strictEqual(u, 'https://xyz.icp0.io'); |
| 101 | }); |
| 102 | |
| 103 | it('defaults from canister_ids when user id set and no URL', () => { |
| 104 | const ids = JSON.parse(readFileSync(join(repoRoot, 'hub/icp/canister_ids.json'), 'utf8')); |
| 105 | const u = resolveCanisterBackupBaseUrl( |
| 106 | { KNOWTATION_CANISTER_BACKUP_USER_ID: 'google:1' }, |
| 107 | repoRoot, |
| 108 | ); |
| 109 | assert.strictEqual(u, `https://${ids.hub.ic}.raw.icp0.io`); |
| 110 | }); |
| 111 | }); |
| 112 | |
| 113 | describe('canister-export-backup.sh', () => { |
| 114 | it('parses with bash -n', async () => { |
| 115 | const { spawnSync } = await import('node:child_process'); |
| 116 | const sh = join(repoRoot, 'scripts/canister-export-backup.sh'); |
| 117 | const r = spawnSync('bash', ['-n', sh], { encoding: 'utf8' }); |
| 118 | assert.strictEqual(r.status, 0, r.stderr || r.stdout); |
| 119 | }); |
| 120 | }); |
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