agent-delegation-performance.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 days ago
| 1 | /** |
| 2 | * Tier 6 — PERFORMANCE: validateChain and mint bounded on fixture store. |
| 3 | */ |
| 4 | import { describe, it, beforeEach, afterEach } from 'node:test'; |
| 5 | import assert from 'node:assert/strict'; |
| 6 | import fs from 'node:fs'; |
| 7 | import path from 'node:path'; |
| 8 | import { fileURLToPath } from 'node:url'; |
| 9 | |
| 10 | import { |
| 11 | handleDelegationGrantMintRequest, |
| 12 | validateChain, |
| 13 | seedDelegationFixtures, |
| 14 | } from '../lib/agent/delegation.mjs'; |
| 15 | import { |
| 16 | writeDelegationPolicy, |
| 17 | makeAgentIdentity, |
| 18 | makeDelegationConsent, |
| 19 | TEST_PRINCIPAL_REF, |
| 20 | } from './fixtures/agent/delegation-helpers.mjs'; |
| 21 | |
| 22 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 23 | const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-agent-delegation-performance'); |
| 24 | |
| 25 | describe('Agent delegation — performance', () => { |
| 26 | const dataDir = path.join(tmpRoot, 'data'); |
| 27 | const vaultId = 'default'; |
| 28 | |
| 29 | beforeEach(() => { |
| 30 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 31 | fs.mkdirSync(dataDir, { recursive: true }); |
| 32 | writeDelegationPolicy(dataDir); |
| 33 | process.env.DELEGATION_ENABLED = '1'; |
| 34 | const identity = makeAgentIdentity({ agentId: 'agent_perf_test01' }); |
| 35 | seedDelegationFixtures(dataDir, vaultId, identity); |
| 36 | for (let i = 0; i < 100; i++) { |
| 37 | const consent = makeDelegationConsent({ |
| 38 | consentId: `dcons_perf_${String(i).padStart(4, '0')}`, |
| 39 | agentId: identity.agent_id, |
| 40 | taskIds: [], |
| 41 | flowIds: [], |
| 42 | }); |
| 43 | seedDelegationFixtures(dataDir, vaultId, identity, consent); |
| 44 | } |
| 45 | }); |
| 46 | |
| 47 | afterEach(() => { |
| 48 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 49 | delete process.env.DELEGATION_ENABLED; |
| 50 | }); |
| 51 | |
| 52 | it('mint + validateChain p95 under 500ms on 100-consent fixture', () => { |
| 53 | const identity = makeAgentIdentity({ agentId: 'agent_perf_test01' }); |
| 54 | const samples = []; |
| 55 | for (let i = 0; i < 20; i++) { |
| 56 | const consentId = `dcons_perf_${String(i).padStart(4, '0')}`; |
| 57 | const t0 = performance.now(); |
| 58 | const mint = handleDelegationGrantMintRequest({ |
| 59 | dataDir, |
| 60 | vaultId, |
| 61 | consentId, |
| 62 | actorAgentId: identity.agent_id, |
| 63 | }); |
| 64 | assert.equal(mint.ok, true); |
| 65 | const chain = validateChain({ |
| 66 | dataDir, |
| 67 | vaultId, |
| 68 | actorAgentId: identity.agent_id, |
| 69 | principalRef: TEST_PRINCIPAL_REF, |
| 70 | grantId: mint.payload.grant.grant_id, |
| 71 | requireGrant: true, |
| 72 | }); |
| 73 | assert.equal(chain.ok, true); |
| 74 | samples.push(performance.now() - t0); |
| 75 | } |
| 76 | samples.sort((a, b) => a - b); |
| 77 | const p95 = samples[Math.floor(samples.length * 0.95)] ?? samples[samples.length - 1]; |
| 78 | assert.ok(p95 < 500, `p95 ${p95}ms exceeds 500ms budget`); |
| 79 | }); |
| 80 | }); |
File History
2 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
10 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b
fix(7C-L1b): route hosted delegation proposals through cani…
Human
minor
⚠
30 days ago