companion-token-custody-performance.test.mjs
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d
docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge
Human
20 hours 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:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d
docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge
Human
20 hours ago