companion-token-custody-performance.test.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | /** |
| 2 | * Tier 6 — PERFORMANCE: custody operations over the (in-memory) adapter are cheap. Real keychain |
| 3 | * latency is a Phase 5 concern; here we guard the module's own overhead against a regression. |
| 4 | */ |
| 5 | import { describe, it } from 'node:test'; |
| 6 | import assert from 'node:assert/strict'; |
| 7 | import { buildSessionMeta, createTokenCustody } from '../lib/companion-token-custody.mjs'; |
| 8 | import { makeSyncKeychain } from './helpers/companion-keychain-fake.mjs'; |
| 9 | |
| 10 | function timed(fn) { |
| 11 | const t0 = performance.now(); |
| 12 | return fn().then(() => performance.now() - t0); |
| 13 | } |
| 14 | |
| 15 | describe('Performance — bounds', () => { |
| 16 | it('100k buildSessionMeta calls in under 2s', () => { |
| 17 | const tr = { expiresIn: 3600, refreshToken: 'r', scope: 'vault:read', tokenType: 'Bearer' }; |
| 18 | const t0 = performance.now(); |
| 19 | for (let i = 0; i < 100_000; i++) buildSessionMeta(tr, { now: i, refreshTtlMs: 1000 }); |
| 20 | const ms = performance.now() - t0; |
| 21 | assert.ok(ms < 2000, `buildSessionMeta x100k took ${ms.toFixed(0)}ms`); |
| 22 | }); |
| 23 | |
| 24 | it('20k store+load cycles in under 3s', async () => { |
| 25 | const custody = createTokenCustody(makeSyncKeychain()); |
| 26 | const ms = await timed(async () => { |
| 27 | for (let i = 0; i < 20_000; i++) { |
| 28 | const meta = buildSessionMeta({ expiresIn: 60, refreshToken: 'r' + i, scope: null, tokenType: 'Bearer' }, { now: i, refreshTtlMs: 1000 }); |
| 29 | await custody.storeSession({ accessToken: 'jwt' + i, refreshToken: 'r' + i, meta }); |
| 30 | await custody.loadSession(); |
| 31 | } |
| 32 | }); |
| 33 | assert.ok(ms < 3000, `store+load x20k took ${ms.toFixed(0)}ms`); |
| 34 | }); |
| 35 | }); |
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