hub-delegation-self-hosted-route.test.mjs
67 lines 2.9 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 10 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: self-hosted hub approve path wires delegation apply', () => {
32 const src = readRepoFile('hub/server.mjs');
33 assert.match(src, /precheckApprovedDelegationProposal/);
34 assert.match(src, /applyDelegationProposalToIndex/);
35 });
36
37 it('integration: bridge registers canister proposal create + apply-approved routes', () => {
38 const bridgeRoutes = readRepoFile('hub/bridge/delegation-routes.mjs');
39 assert.match(bridgeRoutes, /createDelegationProposalOnCanister/);
40 assert.match(bridgeRoutes, /applyApprovedDelegationProposalFromCanister/);
41 assert.match(bridgeRoutes, /\/api\/v1\/delegation\/proposals\/:proposal_id\/apply-approved/);
42 });
43
44 it('integration: gateway wires post-approve delegation apply hook', () => {
45 const gw = readRepoFile('hub/gateway/server.mjs');
46 assert.match(gw, /maybeApplyHostedDelegationAfterApprove/);
47 assert.match(gw, /mergeDelegationApplyIntoApproveResponse/);
48 });
49
50 it('end-to-end: OpenAPI documents delegation endpoints', () => {
51 const api = readRepoFile('docs/openapi.yaml');
52 assert.match(api, /\/agents\/identities:/);
53 assert.match(api, /\/delegation\/consents:/);
54 assert.match(api, /\/delegation\/grants:/);
55 assert.match(api, /\/delegation\/audit:/);
56 assert.match(api, /DELEGATION_ENABLED/);
57 });
58
59 it('security: routes require authenticated role; audit uses session principal fallback', () => {
60 const src = readRepoFile('hub/server.mjs');
61 assert.match(
62 src,
63 /app\.post\('\/api\/v1\/delegation\/audit', requireRole\('viewer', 'editor', 'admin', 'evaluator'\)/,
64 );
65 assert.match(src, /hashPrincipalRef\(req\.user\?\.sub/);
66 });
67 });
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