agent-credentials-performance.test.mjs
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
9 days ago
| 1 | /** |
| 2 | * Phase C + Lane D — performance: local exchange/verify budget with failure persist. |
| 3 | */ |
| 4 | |
| 5 | import { describe, it } from 'node:test'; |
| 6 | import assert from 'node:assert/strict'; |
| 7 | import { mintCredential, verifyCredential } from '../hub/lib/agent-credential-core.mjs'; |
| 8 | |
| 9 | describe('Phase C performance — agent credentials', () => { |
| 10 | it('1000 verifies complete under 250ms locally', () => { |
| 11 | const { records, credential } = mintCredential({}, { |
| 12 | sub: 'google:1', |
| 13 | name: 'perf', |
| 14 | vault_ids: ['default'], |
| 15 | scopes: ['propose', 'vault:read'], |
| 16 | }); |
| 17 | const t0 = performance.now(); |
| 18 | for (let i = 0; i < 1000; i += 1) { |
| 19 | const v = verifyCredential(records, credential); |
| 20 | assert.equal(v.ok, true); |
| 21 | } |
| 22 | const ms = performance.now() - t0; |
| 23 | assert.ok(ms < 250, `expected <250ms, got ${ms.toFixed(1)}ms`); |
| 24 | }); |
| 25 | |
| 26 | it('500 known-id failure persists stay under 250ms locally', () => { |
| 27 | const { records, credential, id } = mintCredential({}, { |
| 28 | sub: 'google:1', |
| 29 | name: 'perf-fail', |
| 30 | vault_ids: ['default'], |
| 31 | scopes: ['propose', 'vault:read'], |
| 32 | }); |
| 33 | const bad = credential.replace(/.$/, 'x'); |
| 34 | const t0 = performance.now(); |
| 35 | for (let i = 0; i < 500; i += 1) { |
| 36 | const v = verifyCredential(records, bad, { now: Date.now() + i }); |
| 37 | assert.equal(v.ok, false); |
| 38 | assert.equal(v.id, id); |
| 39 | assert.ok(v.records); |
| 40 | } |
| 41 | const ms = performance.now() - t0; |
| 42 | assert.ok(ms < 250, `expected <250ms, got ${ms.toFixed(1)}ms`); |
| 43 | }); |
| 44 | }); |
File History
1 commit
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
9 days ago