hub-delegation-self-hosted-route.test.mjs
67 lines 2.9 KB
Raw
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0 feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes… Human minor ⚠ breaking 11 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 1 commit
sha256:93bcf8f9bd56d8c5b9339f4ec73b9ebd66571398d56262d38eedc2cfa9db9882 fix(test): align Band B landing assertion with desktop MCP … Human 11 days ago