agent-delegation-stress.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
10 days ago
| 1 | /** |
| 2 | * Tier 4 — STRESS: concurrent mints, action_count atomicity, no bearer in list under load. |
| 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 | handleDelegationGrantListRequest, |
| 13 | handleDelegationAuditAppendRequest, |
| 14 | seedDelegationFixtures, |
| 15 | } from '../lib/agent/delegation.mjs'; |
| 16 | import { |
| 17 | writeDelegationPolicy, |
| 18 | makeAgentIdentity, |
| 19 | makeDelegationConsent, |
| 20 | TEST_PRINCIPAL_REF, |
| 21 | } from './fixtures/agent/delegation-helpers.mjs'; |
| 22 | |
| 23 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 24 | const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-agent-delegation-stress'); |
| 25 | |
| 26 | describe('Agent delegation — stress', () => { |
| 27 | const dataDir = path.join(tmpRoot, 'data'); |
| 28 | const vaultId = 'default'; |
| 29 | |
| 30 | beforeEach(() => { |
| 31 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 32 | fs.mkdirSync(dataDir, { recursive: true }); |
| 33 | writeDelegationPolicy(dataDir); |
| 34 | process.env.DELEGATION_ENABLED = '1'; |
| 35 | const identity = makeAgentIdentity(); |
| 36 | const consent = makeDelegationConsent({ taskIds: [], flowIds: [] }); |
| 37 | seedDelegationFixtures(dataDir, vaultId, identity, consent); |
| 38 | }); |
| 39 | |
| 40 | afterEach(() => { |
| 41 | fs.rmSync(tmpRoot, { recursive: true, force: true }); |
| 42 | delete process.env.DELEGATION_ENABLED; |
| 43 | }); |
| 44 | |
| 45 | it('50 concurrent mints produce distinct grants; list has no bearer', async () => { |
| 46 | const consent = makeDelegationConsent({ taskIds: [], flowIds: [] }); |
| 47 | const identity = makeAgentIdentity(); |
| 48 | const results = await Promise.all( |
| 49 | Array.from({ length: 50 }, () => |
| 50 | Promise.resolve( |
| 51 | handleDelegationGrantMintRequest({ |
| 52 | dataDir, |
| 53 | vaultId, |
| 54 | consentId: consent.consent_id, |
| 55 | actorAgentId: identity.agent_id, |
| 56 | }), |
| 57 | ), |
| 58 | ), |
| 59 | ); |
| 60 | assert.equal(results.every((r) => r.ok), true); |
| 61 | const ids = new Set(results.map((r) => r.payload.grant.grant_id)); |
| 62 | assert.equal(ids.size, 50); |
| 63 | const list = handleDelegationGrantListRequest({ dataDir, vaultId }); |
| 64 | assert.equal(list.payload.grants.length, 50); |
| 65 | assert.equal(JSON.stringify(list.payload).includes('bearer'), false); |
| 66 | }); |
| 67 | |
| 68 | it('audit append increments action_count', () => { |
| 69 | const consent = makeDelegationConsent({ taskIds: [], flowIds: [] }); |
| 70 | const identity = makeAgentIdentity(); |
| 71 | const mint = handleDelegationGrantMintRequest({ |
| 72 | dataDir, |
| 73 | vaultId, |
| 74 | consentId: consent.consent_id, |
| 75 | actorAgentId: identity.agent_id, |
| 76 | maxActions: 5, |
| 77 | }); |
| 78 | assert.equal(mint.ok, true); |
| 79 | for (let i = 0; i < 3; i++) { |
| 80 | const audit = handleDelegationAuditAppendRequest({ |
| 81 | dataDir, |
| 82 | vaultId, |
| 83 | grantId: mint.payload.grant.grant_id, |
| 84 | actorAgentId: identity.agent_id, |
| 85 | principalRef: TEST_PRINCIPAL_REF, |
| 86 | action: 'advance_step', |
| 87 | evidenceRefs: [`proposal:stress_${i}`], |
| 88 | }); |
| 89 | assert.equal(audit.ok, true); |
| 90 | } |
| 91 | const list = handleDelegationGrantListRequest({ dataDir, vaultId }); |
| 92 | const grant = list.payload.grants.find((g) => g.grant_id === mint.payload.grant.grant_id); |
| 93 | assert.equal(grant.action_count, 3); |
| 94 | }); |
| 95 | }); |
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