hub-delegation-self-hosted-route.test.mjs
sha256:dc02e0ce2c9c3616e8ce241f8a700e1558caae53cb1af50daeffdb2685cf9c3d
feat(delegation): 7C-L1 live gate smoke + hosted bridge/gat…
Human
minor
⚠ breaking
31 days ago
| 1 | /** |
| 2 | * Self-hosted Hub delegation routes — contract tests (Phase 7C-L1). |
| 3 | */ |
| 4 | import { describe, it } 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 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 11 | const repoRoot = path.dirname(__dirname); |
| 12 | |
| 13 | function readRepoFile(relativePath) { |
| 14 | return fs.readFileSync(path.join(repoRoot, relativePath), 'utf8'); |
| 15 | } |
| 16 | |
| 17 | describe('self-hosted Hub delegation routes', () => { |
| 18 | it('unit: registers delegation routes gated by DELEGATION_ENABLED handlers', () => { |
| 19 | const src = readRepoFile('hub/server.mjs'); |
| 20 | assert.match(src, /Agent delegation \(Phase 7C-6\)/); |
| 21 | assert.match(src, /handleAgentIdentityRegisterProposeRequest/); |
| 22 | assert.match(src, /handleDelegationConsentProposeRequest/); |
| 23 | assert.match(src, /handleDelegationGrantMintRequest/); |
| 24 | assert.match(src, /handleDelegationAuditAppendRequest/); |
| 25 | assert.match(src, /app\.post\('\/api\/v1\/agents\/identities'/); |
| 26 | assert.match(src, /app\.post\('\/api\/v1\/delegation\/consents'/); |
| 27 | assert.match(src, /app\.post\('\/api\/v1\/delegation\/grants'/); |
| 28 | assert.match(src, /app\.post\('\/api\/v1\/delegation\/audit'/); |
| 29 | }); |
| 30 | |
| 31 | it('integration: proposal approve path wires delegation apply on hub', () => { |
| 32 | const src = readRepoFile('hub/server.mjs'); |
| 33 | assert.match(src, /precheckApprovedDelegationProposal/); |
| 34 | assert.match(src, /applyDelegationProposalToIndex/); |
| 35 | }); |
| 36 | |
| 37 | it('end-to-end: OpenAPI documents delegation endpoints', () => { |
| 38 | const api = readRepoFile('docs/openapi.yaml'); |
| 39 | assert.match(api, /\/agents\/identities:/); |
| 40 | assert.match(api, /\/delegation\/consents:/); |
| 41 | assert.match(api, /\/delegation\/grants:/); |
| 42 | assert.match(api, /\/delegation\/audit:/); |
| 43 | assert.match(api, /DELEGATION_ENABLED/); |
| 44 | }); |
| 45 | |
| 46 | it('security: routes require authenticated role; audit uses session principal fallback', () => { |
| 47 | const src = readRepoFile('hub/server.mjs'); |
| 48 | assert.match( |
| 49 | src, |
| 50 | /app\.post\('\/api\/v1\/delegation\/audit', requireRole\('viewer', 'editor', 'admin', 'evaluator'\)/, |
| 51 | ); |
| 52 | assert.match(src, /hashPrincipalRef\(req\.user\?\.sub/); |
| 53 | }); |
| 54 | }); |
File History
1 commit
sha256:dc02e0ce2c9c3616e8ce241f8a700e1558caae53cb1af50daeffdb2685cf9c3d
feat(delegation): 7C-L1 live gate smoke + hosted bridge/gat…
Human
minor
⚠
31 days ago