companion-token-custody-performance.test.mjs
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0
feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes…
Human
minor
⚠ breaking
11 days 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
1 commit
sha256:93bcf8f9bd56d8c5b9339f4ec73b9ebd66571398d56262d38eedc2cfa9db9882
fix(test): align Band B landing assertion with desktop MCP …
Human
11 days ago