@bongos/core 1.19.184 → 1.19.186

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.bongos-core.json +68 -63
  2. package/clients/bongos-client/bongos-client.global.js +19 -19
  3. package/clients/bongos-client/index.cjs +19 -19
  4. package/clients/bongos-client/index.d.ts +29 -29
  5. package/clients/bongos-client/index.mjs +19 -19
  6. package/docs/adr/0157-archon-is-rank-and-identity-only.md +2 -2
  7. package/docs/api/openapi.json +121 -121
  8. package/docs/api-reference.md +10 -10
  9. package/docs/canonical-permissions.md +6 -6
  10. package/modules/dev-box/app/src/vendor/bongos-client.cjs +19 -19
  11. package/modules/government/catalog.js +9 -9
  12. package/modules/government/db.js +9 -9
  13. package/modules/government/migrations/government_002_rename_permission_keys.sql +112 -0
  14. package/modules/government/module.json +1 -1
  15. package/modules/government/protected-surfaces.json +0 -1
  16. package/modules/government/ranks.js +13 -13
  17. package/modules/government/routes/{governance.js → government.js} +109 -84
  18. package/modules/government/routes/rank-sync.js +2 -2
  19. package/modules/hall-ui/public/gate.js +3 -3
  20. package/modules/hall-ui/public/{governance.css → government.css} +10 -10
  21. package/modules/hall-ui/public/{governance.html → government.html} +14 -14
  22. package/modules/hall-ui/public/{governance.js → government.js} +117 -117
  23. package/modules/hall-ui/public/harbor.js +3 -3
  24. package/modules/hall-ui/public/shell.js +21 -17
  25. package/modules/hall-ui/public/watch.js +2 -2
  26. package/modules/lifecycle/routes/gate-approvals.js +1 -1
  27. package/package-lock.json +2 -2
  28. package/package.json +1 -1
  29. package/scripts/gds/publish-manifest.js +0 -2
  30. package/scripts/gds/seed-governance-tasks.js +1 -1
  31. package/scripts/hall-preview/server.js +1 -1
  32. package/src/bongos/auth.js +13 -13
  33. package/src/bongos/module-scope-map.js +7 -22
  34. package/src/bongos/route-rank-check.js +12 -18
  35. package/src/bongos/serve-internal.js +10 -10
  36. package/src/module-api.js +6 -2
  37. package/tests/auth_resolve_failure.mjs +4 -4
  38. package/tests/governance_abuse_matrix.mjs +35 -35
  39. package/tests/governance_catalog.mjs +3 -3
  40. package/tests/governance_fold.mjs +2 -2
  41. package/tests/governance_fold_bench.mjs +2 -2
  42. package/tests/governance_live_proof.mjs +4 -4
  43. package/tests/governance_ownership_scope.mjs +1 -1
  44. package/tests/governance_page_gates.mjs +12 -12
  45. package/tests/governance_principals.mjs +2 -2
  46. package/tests/governance_protected_surfaces.mjs +41 -16
  47. package/tests/governance_require_permission.mjs +5 -5
  48. package/tests/governance_resolver.mjs +2 -2
  49. package/tests/governance_role_sync.mjs +23 -23
  50. package/tests/governance_routes.mjs +96 -96
  51. package/tests/governance_seed.mjs +24 -9
  52. package/tests/governance_session_scope.mjs +4 -4
  53. package/tests/hall_nav.mjs +8 -7
  54. package/tests/hall_page_gate_map.mjs +8 -8
@@ -44,7 +44,7 @@ const EMPTY = process.argv.includes('--empty');
44
44
  // --rank: view the hall as a different rank — the /me fixture's builder.rank is
45
45
  // overridden in the response, so the Archon-gated pages (watch, harbor, gate)
46
46
  // render their real content instead of the sealed notice. Preview-only theatre:
47
- // the real pages are server-gated (requireGovernancePage / ADR 0016).
47
+ // the real pages are server-gated (requireGovernmentPage / ADR 0016).
48
48
  const RANK_OVERRIDE = arg('--rank');
49
49
  const MODULES_OFF = String(arg('--modules-off') || '').split(',').map((s) => s.trim()).filter(Boolean);
50
50
  // --modules-on: force-report modules as enabled — a dev box's local config
@@ -1437,9 +1437,9 @@ function signInWithReturn(req) {
1437
1437
  // ranks (catalog.RANK_ORDER):
1438
1438
  // requireBuilderPage was "any session" floor xenos → page.view.public
1439
1439
  // requireNonXenosPage was rank !== 'xenos' floor thetes → page.view.builder
1440
- // requireGovernancePage was rank === 'archon' floor archon → page.view.governance
1440
+ // requireGovernmentPage was rank === 'archon' floor archon → page.view.government
1441
1441
  // That third gate was spelled `requireArchonPage` until ADR 0157 lowered
1442
- // page.view.governance's floor archon→metic and the name stopped being true; the
1442
+ // page.view.government's floor archon→metic and the name stopped being true; the
1443
1443
  // floor now lives in modules/government/catalog.js, not in the function's name.
1444
1444
  // The one accepted divergence is the one governance_002 already documents
1445
1445
  // (tests/governance_parity.mjs Part D): a builder on a reserved/divine rank holds
@@ -1456,8 +1456,8 @@ function signInWithReturn(req) {
1456
1456
  const PAGE_GATES = Object.freeze({
1457
1457
  requireBuilderPage: Object.freeze({ permission: 'page.view.public', deniedTo: '/builders' }),
1458
1458
  requireNonXenosPage: Object.freeze({ permission: 'page.view.builder', deniedTo: '/builders/not-ready' }),
1459
- requireGovernancePage: Object.freeze({ permission: 'page.view.governance', deniedTo: '/builders' }),
1460
- requireGovernanceManagePage: Object.freeze({ permission: 'governance.manage', deniedTo: '/builders' }),
1459
+ requireGovernmentPage: Object.freeze({ permission: 'page.view.government', deniedTo: '/builders' }),
1460
+ requireGovernmentManagePage: Object.freeze({ permission: 'government.manage', deniedTo: '/builders' }),
1461
1461
  requireProjectCuratePage: Object.freeze({ permission: 'project.curate', deniedTo: '/builders' }),
1462
1462
  });
1463
1463
 
@@ -1534,23 +1534,23 @@ async function requireBuilderPage(req, res, next) {
1534
1534
  }
1535
1535
 
1536
1536
  // The /watch monitoring surface, the /harbor dev-box page and the /gate page
1537
- // (#726, idea 257, task 1179) — Metic and up, per `page.view.governance`'s catalog
1537
+ // (#726, idea 257, task 1179) — Metic and up, per `page.view.government`'s catalog
1538
1538
  // floor. Named `requireArchonPage` until ADR 0157 lowered that floor archon→metic
1539
1539
  // (older ADRs still use the old name; this line is the trail). Defense-in-depth:
1540
1540
  // every data endpoint these pages call is independently gated server-side, so no
1541
1541
  // cross-builder data leaks even if this gate were bypassed; it keeps a builder
1542
1542
  // without the permission from ever seeing the page shell.
1543
- async function requireGovernancePage(req, res, next) {
1544
- return runPageGate('requireGovernancePage', req, res, next);
1543
+ async function requireGovernmentPage(req, res, next) {
1544
+ return runPageGate('requireGovernmentPage', req, res, next);
1545
1545
  }
1546
1546
 
1547
1547
  // The /governance roles-and-permissions tab (BV1.R113) — gated on the
1548
- // `governance.manage` ATOM itself (system, archon floor), the same key every
1548
+ // `government.manage` ATOM itself (system, archon floor), the same key every
1549
1549
  // /governance/* data route checks, so the page layer can never drift wider than
1550
1550
  // the API it fronts. Defense-in-depth as above: the data endpoints are all
1551
1551
  // independently gated; this keeps the tab shell from rendering for anyone else.
1552
- async function requireGovernanceManagePage(req, res, next) {
1553
- return runPageGate('requireGovernanceManagePage', req, res, next);
1552
+ async function requireGovernmentManagePage(req, res, next) {
1553
+ return runPageGate('requireGovernmentManagePage', req, res, next);
1554
1554
  }
1555
1555
 
1556
1556
  // The /people builder-directory page (task 1002577) — gated on the
@@ -1716,7 +1716,7 @@ function requireRank(...allowed) {
1716
1716
  // time — never hardcoded prose, which goes stale when a floor moves (the
1717
1717
  // D-16/N-3 failure shape ADR 0157 left behind).
1718
1718
  //
1719
- // Usage: router.post('/roles', auth.requireBuilder, auth.requirePermission('governance.manage'), handler)
1719
+ // Usage: router.post('/roles', auth.requireBuilder, auth.requirePermission('government.manage'), handler)
1720
1720
  function requirePermission(...perms) {
1721
1721
  const required = Object.freeze([...perms]);
1722
1722
  return async function permissionGate(req, res, next) {
@@ -1827,8 +1827,8 @@ module.exports = {
1827
1827
  SESSION_SCOPES,
1828
1828
  requireBuilder,
1829
1829
  requireBuilderPage,
1830
- requireGovernancePage,
1831
- requireGovernanceManagePage,
1830
+ requireGovernmentPage,
1831
+ requireGovernmentManagePage,
1832
1832
  requireNonXenosPage,
1833
1833
  requireProjectCuratePage,
1834
1834
  requireRank,
@@ -174,30 +174,15 @@ const MODULE_GLOBS = {
174
174
  // role templates (R96), listed here as goal territory; the module code lands in
175
175
  // R93+ (the carve precedes the feature — ADR 0086 §4). Written as exact paths,
176
176
  // not 'config/governance*.json' — the touches convention has no wildcards. ---
177
- // RENAMED governance → government (goal 1000068, task 1003003, ADR 0174).
178
- // Both keys live through the transition and BOTH carry BOTH sets of globs,
179
- // so the wall is identical whichever key a goal names and whichever name
180
- // the folder currently has on disk. The `government` key must land BEFORE
181
- // R04 moves the folder: goals carry scope_modules by KEY, so moving the
182
- // folder first would leave goal 1000068's own wall not matching the files
183
- // its remaining tasks need to touch, blocking the rename mid-goal.
184
- // `modules/government/` is registered in protected-surfaces.json in the
185
- // same change — `protected` DERIVES from that registry, so without it this
186
- // key would compute protected:false and silently drop the Archon gate.
177
+ // RENAMED governance → government (goal 1000068, ADR 0174). The
178
+ // transitional `governance` alias key was removed in R05 (task 1003006)
179
+ // together with the /governance/* route aliases — the same compatibility
180
+ // window. The three live goals that named the old key (1000030, 1000057,
181
+ // 1000068) had it removed from goals.scope_modules in the same change, so
182
+ // no stored row references a key the map no longer defines.
187
183
  government: [
188
- 'modules/government/', 'modules/governance/',
184
+ 'modules/government/',
189
185
  'config/government.json', 'config/government.neutral.json',
190
- 'config/governance.json', 'config/governance.neutral.json',
191
- ],
192
- // DEPRECATED ALIAS — kept for one release so goals and tasks already
193
- // scoped to `governance` keep resolving. Removed by goal 1000068 R05
194
- // (task 1003006), the release that drops the /governance/* route aliases;
195
- // the two removals are the same compatibility window and should land
196
- // together.
197
- governance: [
198
- 'modules/government/', 'modules/governance/',
199
- 'config/government.json', 'config/government.neutral.json',
200
- 'config/governance.json', 'config/governance.neutral.json',
201
186
  ],
202
187
  // --- the two web surfaces ---
203
188
  // BV1.R85: hall-UI graduated to modules/hall-ui/ — public-builders/ moved to
@@ -231,19 +231,18 @@ const EXPECTED_RANKS = {
231
231
  'GET /security/adr': 'metic+archon',
232
232
  };
233
233
 
234
- // The authz-core route pins, referenced by BOTH the `governance` and the
235
- // `government` module keys below while goal 1000068's rename is in flight
236
- // (ADR 0174, task 1003003). One object, two keys — never two literals.
234
+ // The authz-core route pins (ADR 0174). Paths and the gating atom were renamed
235
+ // governance→government in R05 (task 1003006); the module-key alias is gone.
237
236
  const GOVERNMENT_PINS = {
238
- 'GET /governance/roles': 'perm:governance.manage',
239
- 'GET /governance/permissions': 'perm:governance.manage',
240
- 'GET /governance/assignments': 'perm:governance.manage',
241
- 'POST /governance/roles': 'perm:governance.manage',
242
- 'PUT /governance/roles/:roleKey/permissions/:permissionKey': 'perm:governance.manage',
243
- 'DELETE /governance/roles/:roleKey/permissions/:permissionKey': 'perm:governance.manage',
244
- 'POST /governance/roles/:roleKey/reset': 'perm:governance.manage',
245
- 'POST /governance/assignments': 'perm:governance.manage',
246
- 'DELETE /governance/assignments/:builderId/:roleKey': 'perm:governance.manage',
237
+ 'GET /government/ranks': 'perm:government.manage',
238
+ 'GET /government/permissions': 'perm:government.manage',
239
+ 'GET /government/assignments': 'perm:government.manage',
240
+ 'POST /government/ranks': 'perm:government.manage',
241
+ 'PUT /government/ranks/:rankKey/permissions/:permissionKey': 'perm:government.manage',
242
+ 'DELETE /government/ranks/:rankKey/permissions/:permissionKey': 'perm:government.manage',
243
+ 'POST /government/ranks/:rankKey/reset': 'perm:government.manage',
244
+ 'POST /government/assignments': 'perm:government.manage',
245
+ 'DELETE /government/assignments/:builderId/:rankKey': 'perm:government.manage',
247
246
  };
248
247
 
249
248
  // Module-scoped privileged-rank pins: a privileged route that lives in a FEATURE
@@ -417,17 +416,12 @@ const MODULE_EXPECTED_RANKS = {
417
416
  },
418
417
  // The government tab's server half (BV1.R110, ADR 0151; renamed by ADR 0174) —
419
418
  // the routes that EDIT the rank/permission graph itself. Every route, the three
420
- // reads included, is pinned to the `governance.manage` ATOM rather than a rank:
419
+ // reads included, is pinned to the `government.manage` ATOM rather than a rank:
421
420
  // on this surface the atom IS the authority (it is the catalog's meta-escalation
422
421
  // key), and a downgrade here is the model's worst case — the routes that write
423
422
  // authority drifting below the wall that guards authority. Reads are pinned too
424
423
  // because the full rank/grant/assignment map is the authority model's blueprint.
425
424
  //
426
- // The ROUTE PATHS and the `governance.manage` key are renamed by R05 (task
427
- // 1003006), not here: R02 only makes the pins reachable under both module keys.
428
- // Renaming the paths before the routes move would pin routes that do not exist
429
- // and red the build for the whole window.
430
- governance: GOVERNMENT_PINS,
431
425
  // The same pins under the post-ADR-0174 module name (goal 1000068, task
432
426
  // 1003003). Pins are applied only when the module directory is IN SCOPE — at
433
427
  // least one route file was discovered under modules/<key>/ — so this entry is
@@ -749,9 +749,9 @@ function mountInternalSurfaces(app) {
749
749
  });
750
750
 
751
751
  // The /watch monitoring page and the /harbor dev-box management page (idea 257)
752
- // and the /gate page (task 1179) all sit behind `page.view.governance` — Metic
752
+ // and the /gate page (task 1179) all sit behind `page.view.government` — Metic
753
753
  // and up since ADR 0157. Same server-side page gate, same posture: a builder
754
- // without the permission never receives the shell (requireGovernancePage — named
754
+ // without the permission never receives the shell (requireGovernmentPage — named
755
755
  // requireArchonPage before ADR 0157 — redirects them to the hall, and an
756
756
  // unauthenticated visitor into sign-in). The subdomain shim above has already
757
757
  // rewritten the bare /watch + /harbor + /gate onto /builders/*. (Defense in
@@ -766,13 +766,13 @@ function mountInternalSurfaces(app) {
766
766
  // data never leaked (the route gate held), but the page was the one item in the
767
767
  // group without a wall. Gated here so the group is uniform (task 1002710).
768
768
  const SESSIONS_PAGE_RE = /^\/builders\/sessions(?:\.html)?\/?$/;
769
- // The /governance roles-and-permissions tab (BV1.R113) sits one floor higher:
770
- // the `governance.manage` atom itself (archon), the same key its data routes
771
- // check — requireGovernanceManagePage, not the metic-floored gate above.
772
- const GOVERNANCE_PAGE_RE = /^\/builders\/governance(?:\.html)?\/?$/;
769
+ // The /government ranks-and-permissions tab (BV1.R113) sits one floor higher:
770
+ // the `government.manage` atom itself (archon), the same key its data routes
771
+ // check — requireGovernmentManagePage, not the metic-floored gate above.
772
+ const GOVERNMENT_PAGE_RE = /^\/builders\/government(?:\.html)?\/?$/;
773
773
  // The /people builder directory (task 1002577): gated on `project.curate`, the
774
774
  // exact permission its data route (GET /scouting) checks — same posture as the
775
- // /governance tab above (the page can never drift wider than the API it fronts).
775
+ // /government tab above (the page can never drift wider than the API it fronts).
776
776
  const PEOPLE_PAGE_RE = /^\/builders\/people(?:\.html)?\/?$/;
777
777
  // /scouting is the LEGACY twin of /people — the same /api/gds/scouting directory,
778
778
  // left behind when task 1002577 graduated it into the hall. It has no nav entry
@@ -787,10 +787,10 @@ function mountInternalSurfaces(app) {
787
787
  const norm = path.posix.normalize(req.path);
788
788
  if (WATCH_PAGE_RE.test(norm) || HARBOR_PAGE_RE.test(norm) || GATE_PAGE_RE.test(norm)
789
789
  || SESSIONS_PAGE_RE.test(norm)) {
790
- return gdsAuth.requireGovernancePage(req, res, next);
790
+ return gdsAuth.requireGovernmentPage(req, res, next);
791
791
  }
792
- if (GOVERNANCE_PAGE_RE.test(norm)) {
793
- return gdsAuth.requireGovernanceManagePage(req, res, next);
792
+ if (GOVERNMENT_PAGE_RE.test(norm)) {
793
+ return gdsAuth.requireGovernmentManagePage(req, res, next);
794
794
  }
795
795
  if (PEOPLE_PAGE_RE.test(norm) || SCOUTING_PAGE_RE.test(norm)) {
796
796
  return gdsAuth.requireProjectCuratePage(req, res, next);
package/src/module-api.js CHANGED
@@ -390,7 +390,7 @@ const { validateOrRespond, LIMITS, parseId, asyncHandler, corsPublicGet, parsePa
390
390
  // ad7a262 and never packaged, so ~104 non-merge commits sat on main
391
391
  // reachable by no pin; this is the artifact that ships them. Headline:
392
392
  // the governance permission system's second half (R110 roles/perms/
393
- // assignments CRUD behind governance.manage, R113 the Roles nav +
393
+ // assignments CRUD behind government.manage, R113 the Roles nav +
394
394
  // page gate, R114 the C6 live proof, ADR 0157 delegating the
395
395
  // operational block from Archon to Metic, and the permission resolve
396
396
  // folded into the session load); the scan-before-install security
@@ -795,8 +795,12 @@ const { validateOrRespond, LIMITS, parseId, asyncHandler, corsPublicGet, parsePa
795
795
  // landed since 1.19.182 with no explicit bump. run 31973728179. (task 1002620)
796
796
  // 1.19.184 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
797
797
  // landed since 1.19.183 with no explicit bump. run 31974847472. (task 1002620)
798
+ // 1.19.185 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
799
+ // landed since 1.19.184 with no explicit bump. run 31976564067. (task 1002620)
800
+ // 1.19.186 — CI auto-patch (publish-on-merge, ADR 0161): carrier for merges
801
+ // landed since 1.19.185 with no explicit bump. run 31977207459. (task 1002620)
798
802
  // ---------------------------------------------------------------------------
799
- const CORE_VERSION = '1.19.184'; // CI auto-patch carrier (ADR 0161); see changelog above
803
+ const CORE_VERSION = '1.19.186'; // CI auto-patch carrier (ADR 0161); see changelog above
800
804
 
801
805
  // A namespaced logger so a module's log lines are attributable + consistent.
802
806
  // Usage: const log = api.logger('dev-box'); log.info('mounted');
@@ -93,17 +93,17 @@ test('AUDIT: every async middleware mounted directly on a router owns its reject
93
93
  // rot: a NEW bare `async function require*` added later fails this test.
94
94
  // requireBuilder — the API gate. Guarded here (BV1.R109-follow-up).
95
95
  // requireBuilderPage \
96
- // requireGovernancePage \
97
- // requireGovernanceManagePage > all five delegate to runPageGate, guarded by BV1.R107.
96
+ // requireGovernmentPage \
97
+ // requireGovernmentManagePage > all five delegate to runPageGate, guarded by BV1.R107.
98
98
  // requireNonXenosPage / (the R113 roles-tab gate; the /people curate gate)
99
99
  // requireProjectCuratePage /
100
100
  // Anything else async and router-mounted must be added with its own try/catch.
101
101
  const src = fs.readFileSync(path.join(ROOT, 'src', 'bongos', 'auth.js'), 'utf8');
102
102
  const asyncMw = [...src.matchAll(/^async function (require\w+|allow\w+)\s*\(req, res, next\)/gm)].map((m) => m[1]);
103
- assert.deepEqual(asyncMw.sort(), ['requireBuilder', 'requireBuilderPage', 'requireGovernanceManagePage', 'requireGovernancePage', 'requireNonXenosPage', 'requireProjectCuratePage'],
103
+ assert.deepEqual(asyncMw.sort(), ['requireBuilder', 'requireBuilderPage', 'requireGovernmentManagePage', 'requireGovernmentPage', 'requireNonXenosPage', 'requireProjectCuratePage'],
104
104
  'a new async router middleware appeared — give it a try/catch and add it here');
105
105
  // The page gates must actually delegate (that is WHY they are safe).
106
- for (const name of ['requireBuilderPage', 'requireGovernancePage', 'requireGovernanceManagePage', 'requireNonXenosPage', 'requireProjectCuratePage']) {
106
+ for (const name of ['requireBuilderPage', 'requireGovernmentPage', 'requireGovernmentManagePage', 'requireNonXenosPage', 'requireProjectCuratePage']) {
107
107
  const fn = src.slice(src.indexOf(`async function ${name}`));
108
108
  assert.match(sliceFn(fn), /runPageGate\(/, `${name} must delegate to the guarded runPageGate`);
109
109
  }
@@ -16,7 +16,7 @@
16
16
  // V3 HTTP: assign a seeded rank-role to a builder (rank is the only writer)
17
17
  // V4 HTTP: mass-assignment on role create (is_system / permissions in body)
18
18
  // V5 HTTP: every write vector 403s outright for a caller without
19
- // governance.manage (the low-trust builder's own attempt)
19
+ // government.manage (the low-trust builder's own attempt)
20
20
  // V6 config: a role template proposing system keys is stripped; a seeded
21
21
  // role's template grants are dropped wholesale; env overrides labels only
22
22
  // V7 session-scope: an allow-list naming a system or principal key THROWS
@@ -109,9 +109,9 @@ test('every system permission floors at archon or is a principal (never seeded l
109
109
  const calls = [];
110
110
  const stub = {
111
111
  getRoleByKey: async (k) => (SEEDED_ROLES.includes(k)
112
- ? { role_key: k, label: k, is_system: true, seeded_rank: k }
113
- : { role_key: k, label: k, is_system: false, seeded_rank: null }),
114
- createRole: async (a) => ({ role_key: a.roleKey, label: a.label, description: a.description ?? null, is_system: false, seeded_rank: null, created_by: a.createdBy, created_at: 't' }),
112
+ ? { rank_key: k, label: k, is_system: true, seeded_rank: k }
113
+ : { rank_key: k, label: k, is_system: false, seeded_rank: null }),
114
+ createRole: async (a) => ({ rank_key: a.rankKey, label: a.label, description: a.description ?? null, is_system: false, seeded_rank: null, created_by: a.createdBy, created_at: 't' }),
115
115
  grantRolePermission: async () => true,
116
116
  revokeRolePermission: async () => true,
117
117
  resetRoleGrants: async ({ permissionKeys }) => permissionKeys.length,
@@ -127,7 +127,7 @@ for (const k of Object.keys(stub)) {
127
127
  }
128
128
 
129
129
  // The attacker holds the MOST privileged legitimate session — an Archon with
130
- // governance.manage. The matrix must hold even against the admin misusing the
130
+ // government.manage. The matrix must hold even against the admin misusing the
131
131
  // API, not just against a low-trust caller (V5 covers that one).
132
132
  const realRequireBuilder = api.requireBuilder;
133
133
  api.requireBuilder = (req, res, next) => { req.builder = { id: 42, rank: 'archon' }; next(); };
@@ -136,9 +136,9 @@ function grant(keys) {
136
136
  seams._reset();
137
137
  seams.registerProvider('government', { resolveBuilderPermissions: async () => keys });
138
138
  }
139
- grant(['governance.manage']);
139
+ grant(['government.manage']);
140
140
 
141
- const buildGovernanceRouter = require(path.join(ROOT, 'modules', 'government', 'routes', 'governance.js'));
141
+ const buildGovernanceRouter = require(path.join(ROOT, 'modules', 'government', 'routes', 'government.js'));
142
142
  const app = express();
143
143
  app.use(express.json());
144
144
  app.use(attachFail);
@@ -168,7 +168,7 @@ async function call(method, p, body) {
168
168
 
169
169
  test('V1: EVERY system permission is refused onto a custom role, before the db', async () => {
170
170
  for (const k of SYSTEM_KEYS) {
171
- const r = await call('PUT', `/governance/roles/custom-role/permissions/${k}`);
171
+ const r = await call('PUT', `/government/ranks/custom-role/permissions/${k}`);
172
172
  assert.equal(r.status, 400, `${k} must be refused`);
173
173
  assert.equal(r.json.error.code, 'permission_not_grantable', k);
174
174
  assert.equal(calls.filter(([c]) => c === 'grantRolePermission').length, 0,
@@ -185,15 +185,15 @@ test('V1: EVERY system permission is refused onto a custom role, before the db',
185
185
  test('V2a: the ARCHON rank-role refuses EVERY write — grant, revoke and reset alike', async () => {
186
186
  for (const k of [...SYSTEM_KEYS, 'idea.triage']) {
187
187
  for (const method of ['PUT', 'DELETE']) {
188
- const r = await call(method, `/governance/roles/archon/permissions/${k}`);
188
+ const r = await call(method, `/government/ranks/archon/permissions/${k}`);
189
189
  assert.equal(r.status, 403, `archon ← ${method} ${k} must be refused`);
190
- assert.equal(r.json.error.code, 'archon_role_immutable', `archon ← ${method} ${k}`);
190
+ assert.equal(r.json.error.code, 'archon_rank_immutable', `archon ← ${method} ${k}`);
191
191
  assert.equal(calls.filter(([c]) => c === 'grantRolePermission' || c === 'revokeRolePermission').length, 0);
192
192
  }
193
193
  }
194
- const r = await call('POST', '/governance/roles/archon/reset');
194
+ const r = await call('POST', '/government/ranks/archon/reset');
195
195
  assert.equal(r.status, 403, 'reset must not be a back door into the archon role');
196
- assert.equal(r.json.error.code, 'archon_role_immutable');
196
+ assert.equal(r.json.error.code, 'archon_rank_immutable');
197
197
  assert.equal(calls.filter(([c]) => c === 'resetRoleGrants').length, 0);
198
198
  });
199
199
 
@@ -201,7 +201,7 @@ test('V2b: EVERY editable rank-role still refuses every SUBSTRATE and PRINCIPAL
201
201
  const neverGrantable = [...SUBSTRATE_KEYS, ...catalog.principalKeys()];
202
202
  for (const role of EDITABLE_RANK_ROLES) {
203
203
  for (const k of neverGrantable) {
204
- const r = await call('PUT', `/governance/roles/${role}/permissions/${k}`);
204
+ const r = await call('PUT', `/government/ranks/${role}/permissions/${k}`);
205
205
  assert.equal(r.status, 400, `${role} ← ${k} must be refused`);
206
206
  assert.equal(r.json.error.code, 'permission_not_grantable', `${role} ← ${k}`);
207
207
  assert.equal(calls.filter(([c]) => c === 'grantRolePermission').length, 0,
@@ -213,7 +213,7 @@ test('V2b: EVERY editable rank-role still refuses every SUBSTRATE and PRINCIPAL
213
213
  test('V2c: an editable rank-role ACCEPTS the in-app owner powers (the ADR 0172 lever)', async () => {
214
214
  for (const role of EDITABLE_RANK_ROLES) {
215
215
  for (const k of [...OWNER_POWERS, 'idea.triage']) {
216
- const r = await call('PUT', `/governance/roles/${role}/permissions/${k}`);
216
+ const r = await call('PUT', `/government/ranks/${role}/permissions/${k}`);
217
217
  assert.equal(r.status, 200, `${role} ← ${k} must be ACCEPTED — this delegation is the owner's decision (ADR 0172)`);
218
218
  assert.equal(calls.filter(([c]) => c === 'grantRolePermission').length, 1, `${role} ← ${k} must reach the db`);
219
219
  }
@@ -222,7 +222,7 @@ test('V2c: an editable rank-role ACCEPTS the in-app owner powers (the ADR 0172 l
222
222
 
223
223
  test('V2d: reset restores the CATALOG seed, never anything wider', async () => {
224
224
  for (const role of EDITABLE_RANK_ROLES) {
225
- const r = await call('POST', `/governance/roles/${role}/reset`);
225
+ const r = await call('POST', `/government/ranks/${role}/reset`);
226
226
  assert.equal(r.status, 200, `${role} must be resettable`);
227
227
  const [, args] = calls.find(([c]) => c === 'resetRoleGrants');
228
228
  assert.deepEqual([...args.permissionKeys].sort(), [...catalog.seedForRank(role)].sort(),
@@ -233,24 +233,24 @@ test('V2d: reset restores the CATALOG seed, never anything wider', async () => {
233
233
  }
234
234
  // A custom role has no catalog default, so reset is refused rather than silently
235
235
  // clearing its grants (which would be a destructive verb wearing a restore's name).
236
- const r = await call('POST', '/governance/roles/custom-role/reset');
236
+ const r = await call('POST', '/government/ranks/custom-role/reset');
237
237
  assert.equal(r.status, 400);
238
- assert.equal(r.json.error.code, 'role_has_no_default');
238
+ assert.equal(r.json.error.code, 'rank_has_no_default');
239
239
  assert.equal(calls.filter(([c]) => c === 'resetRoleGrants').length, 0);
240
240
  });
241
241
 
242
242
  test('V3: EVERY seeded rank-role refuses assignment (rank is the only writer — R95b)', async () => {
243
243
  for (const role of SEEDED_ROLES) {
244
- const r = await call('POST', '/governance/assignments', { builder_id: 7, role_key: role });
244
+ const r = await call('POST', '/government/assignments', { builder_id: 7, rank_key: role });
245
245
  assert.equal(r.status, 403, `assigning seeded role ${role} must be refused`);
246
- assert.equal(r.json.error.code, 'seeded_role_assignment_forbidden', role);
246
+ assert.equal(r.json.error.code, 'seeded_rank_assignment_forbidden', role);
247
247
  assert.equal(calls.filter(([c]) => c === 'assignRole').length, 0);
248
248
  }
249
249
  });
250
250
 
251
251
  test('V4: mass-assignment on role create is refused outright (strict schema)', async () => {
252
- const r = await call('POST', '/governance/roles', {
253
- role_key: 'sneaky-role',
252
+ const r = await call('POST', '/government/ranks', {
253
+ rank_key: 'sneaky-role',
254
254
  label: 'Sneaky',
255
255
  is_system: true,
256
256
  seeded_rank: 'archon',
@@ -262,32 +262,32 @@ test('V4: mass-assignment on role create is refused outright (strict schema)', a
262
262
  });
263
263
 
264
264
  test('V4: a clean role create is never system and carries no grants', async () => {
265
- const r = await call('POST', '/governance/roles', { role_key: 'sneaky-role', label: 'Sneaky' });
265
+ const r = await call('POST', '/government/ranks', { rank_key: 'sneaky-role', label: 'Sneaky' });
266
266
  assert.equal(r.status, 201);
267
- assert.equal(r.json.role.is_system, false, 'a created role is never system');
268
- assert.equal(r.json.role.seeded_rank, null);
269
- assert.deepEqual(r.json.role.permissions, [], 'creation carries no grants');
267
+ assert.equal(r.json.rank.is_system, false, 'a created role is never system');
268
+ assert.equal(r.json.rank.seeded_rank, null);
269
+ assert.deepEqual(r.json.rank.permissions, [], 'creation carries no grants');
270
270
  const c = calls.find(([k]) => k === 'createRole');
271
- assert.deepEqual(Object.keys(c[1]).sort(), ['createdBy', 'description', 'label', 'roleKey'],
271
+ assert.deepEqual(Object.keys(c[1]).sort(), ['createdBy', 'description', 'label', 'rankKey'],
272
272
  'nothing beyond the four whitelisted fields reaches the db');
273
273
  assert.equal(calls.filter(([k]) => k === 'grantRolePermission').length, 0);
274
274
  });
275
275
 
276
- test('V5: a caller without governance.manage cannot reach ANY write vector at all', async () => {
277
- grant(catalog.grantableKeys().filter((k) => k !== 'governance.manage'));
276
+ test('V5: a caller without government.manage cannot reach ANY write vector at all', async () => {
277
+ grant(catalog.grantableKeys().filter((k) => k !== 'government.manage'));
278
278
  for (const [method, p, body] of [
279
- ['POST', '/governance/roles', { role_key: 'x-role', label: 'X' }],
280
- ['PUT', '/governance/roles/custom-role/permissions/deploy.push_main', undefined],
281
- ['DELETE', '/governance/roles/custom-role/permissions/idea.triage', undefined],
282
- ['POST', '/governance/roles/metic/reset', undefined],
283
- ['POST', '/governance/assignments', { builder_id: 7, role_key: 'custom-role' }],
284
- ['DELETE', '/governance/assignments/7/custom-role', undefined],
279
+ ['POST', '/government/ranks', { rank_key: 'x-role', label: 'X' }],
280
+ ['PUT', '/government/ranks/custom-role/permissions/deploy.push_main', undefined],
281
+ ['DELETE', '/government/ranks/custom-role/permissions/idea.triage', undefined],
282
+ ['POST', '/government/ranks/metic/reset', undefined],
283
+ ['POST', '/government/assignments', { builder_id: 7, rank_key: 'custom-role' }],
284
+ ['DELETE', '/government/assignments/7/custom-role', undefined],
285
285
  ]) {
286
286
  const r = await call(method, p, body);
287
287
  assert.equal(r.status, 403, `${method} ${p} must deny — even holding every operational grant`);
288
288
  assert.equal(r.json.error.code, 'permission_forbidden', `${method} ${p}`);
289
289
  }
290
- grant(['governance.manage']);
290
+ grant(['government.manage']);
291
291
  });
292
292
 
293
293
  // ===========================================================================
@@ -57,7 +57,7 @@ test('substrate keys are the out-of-band three, and each implies system + archon
57
57
  assert.equal(byKey(k).floor, 'archon', `${k} must floor at archon`);
58
58
  assert.equal(byKey(k).principal, null, `${k} must not also be a principal key`);
59
59
  }
60
- assert.equal(cat.isSubstrate('governance.manage'), false, 'an in-app archon power is not substrate');
60
+ assert.equal(cat.isSubstrate('government.manage'), false, 'an in-app archon power is not substrate');
61
61
  assert.equal(cat.isSubstrate('nope.not.a.key'), false, 'unknown fails closed');
62
62
  });
63
63
 
@@ -67,7 +67,7 @@ test('isGrantableTo: a sub-Archon rank-role takes owner powers, a custom role do
67
67
  const custom = { is_system: false, seeded_rank: null };
68
68
 
69
69
  // The widening: an in-app archon power reaches a rank-role, never a custom one.
70
- for (const k of ['governance.manage', 'builder.rank.set', 'version.close']) {
70
+ for (const k of ['government.manage', 'builder.rank.set', 'version.close']) {
71
71
  assert.equal(cat.isGrantableTo(k, metic), true, `${k} → metic rank-role`);
72
72
  assert.equal(cat.isGrantableTo(k, custom), false, `${k} → custom role must stay refused`);
73
73
  }
@@ -173,7 +173,7 @@ test('an unknown/reserved rank resolves to no permissions (fail-closed; ADR 0151
173
173
  });
174
174
 
175
175
  test('byKey returns a frozen record or null', () => {
176
- const p = byKey('governance.manage');
176
+ const p = byKey('government.manage');
177
177
  assert.ok(p && p.system === true && p.floor === 'archon');
178
178
  assert.throws(() => { p.system = false; }, /Cannot assign|read only|frozen/i);
179
179
  assert.equal(byKey('nope'), null);
@@ -121,7 +121,7 @@ test('the kernel shape guard: the real fragment embeds; a malformed one degrades
121
121
  assert.equal(dbKernel.sessionPermsSelect(), '', 'a fragment with a statement separator is refused');
122
122
  // The REAL registered fragment passes the guard verbatim.
123
123
  seams._reset();
124
- const buildGovernanceRouter = require(path.join(ROOT, 'modules', 'government', 'routes', 'governance.js'));
124
+ const buildGovernanceRouter = require(path.join(ROOT, 'modules', 'government', 'routes', 'government.js'));
125
125
  buildGovernanceRouter();
126
126
  const real = seams.resolveOptional('session-grants-sql').selectFragment;
127
127
  assert.equal(dbKernel.sessionPermsSelect(), real, 'the shipped fragment embeds unchanged');
@@ -133,7 +133,7 @@ test('the module registers the capability-named SQL seam the kernel embeds', ()
133
133
  // §Decision #4); the governance route factory is what registers it. Pin the
134
134
  // registration and the column contract the kernel query depends on.
135
135
  seams._reset();
136
- const buildGovernanceRouter = require(path.join(ROOT, 'modules', 'government', 'routes', 'governance.js'));
136
+ const buildGovernanceRouter = require(path.join(ROOT, 'modules', 'government', 'routes', 'government.js'));
137
137
  buildGovernanceRouter();
138
138
  const provider = seams.resolveOptional('session-grants-sql');
139
139
  assert.ok(provider && typeof provider.selectFragment === 'string', 'fragment provider registered');
@@ -1,7 +1,7 @@
1
1
  // tests/governance_fold_bench.mjs — the task-1002556 benchmark, re-runnable.
2
2
  //
3
3
  // Measures end-to-end latency of a requireBuilder + requirePermission route
4
- // (GET /governance/roles) against a LIVE server, the way the fold was graded:
4
+ // (GET /government/ranks) against a LIVE server, the way the fold was graded:
5
5
  // point it at a stack before and after and compare. Asserts only route health
6
6
  // (every request 200) — the numbers are the deliverable, printed for the
7
7
  // operator to diff.
@@ -27,7 +27,7 @@ import { strict as assert } from 'node:assert';
27
27
  const BASE = (process.env.GDS_BASE_URL || '').replace(/\/$/, '');
28
28
  const TOKEN = process.env.BENCH_TOKEN || '';
29
29
  if (!BASE || !TOKEN) {
30
- console.log('governance_fold_bench.mjs SKIPPED — set GDS_BASE_URL and BENCH_TOKEN (a session token whose builder holds governance.manage).');
30
+ console.log('governance_fold_bench.mjs SKIPPED — set GDS_BASE_URL and BENCH_TOKEN (a session token whose builder holds government.manage).');
31
31
  process.exit(0);
32
32
  }
33
33
  const N = Number(process.env.BENCH_N) || 300;
@@ -142,7 +142,7 @@ try {
142
142
  'BEFORE: the thetes builder cannot triage (403 permission_forbidden)');
143
143
 
144
144
  // Act 2 — an Archon creates a custom role and grants the operational permission.
145
- r = await call(ARCHON_TOKEN, 'POST', '/governance/roles',
145
+ r = await call(ARCHON_TOKEN, 'POST', '/government/ranks',
146
146
  { role_key: ROLE_KEY, label: 'GLP demo triage role' });
147
147
  ok(r.status === 201, 'the Archon creates a custom role (201)');
148
148
  r = await call(ARCHON_TOKEN, 'PUT', `/governance/roles/${ROLE_KEY}/permissions/${OPERATIONAL_KEY}`);
@@ -153,13 +153,13 @@ try {
153
153
  r = await call(ARCHON_TOKEN, 'PUT', `/governance/roles/${ROLE_KEY}/permissions/${SYSTEM_KEY}`);
154
154
  ok(r.status === 400 && r.body.error.code === 'permission_not_grantable',
155
155
  `system '${SYSTEM_KEY}' is NOT grantable, even by the Archon (400 permission_not_grantable)`);
156
- r = await call(ARCHON_TOKEN, 'PUT', `/governance/roles/${ROLE_KEY}/permissions/governance.manage`);
156
+ r = await call(ARCHON_TOKEN, 'PUT', `/governance/roles/${ROLE_KEY}/permissions/government.manage`);
157
157
  ok(r.status === 400 && r.body.error.code === 'permission_not_grantable',
158
- 'the meta-escalation (governance.manage) is refused the same way');
158
+ 'the meta-escalation (government.manage) is refused the same way');
159
159
 
160
160
  // Act 4 — assign, then the same builder performs the action: no re-login, no
161
161
  // restart — the per-request, uncached resolve (ADR 0016) picks the role up.
162
- r = await call(ARCHON_TOKEN, 'POST', '/governance/assignments',
162
+ r = await call(ARCHON_TOKEN, 'POST', '/government/assignments',
163
163
  { builder_id: THETES, role_key: ROLE_KEY });
164
164
  ok(r.status === 201, 'the Archon assigns the custom role to the thetes builder (201)');
165
165
  r = await call(THETES_TOKEN, 'PATCH', `/inbox/${ideaId}`, { status: 'discarded' });
@@ -397,7 +397,7 @@ test('G2: the role resolve is untouched — own-scoped keys still resolve, princ
397
397
  });
398
398
 
399
399
  test('G3: the kernel port carries the ownership axis on the ONE governance port', () => {
400
- const { governancePort } = require(path.join(GOV, 'routes', 'governance.js'));
400
+ const { governancePort } = require(path.join(GOV, 'routes', 'government.js'));
401
401
  for (const name of ['authorizeOwned', 'authorizeOwnedOrAny', 'sameOwner', 'isOwnershipScoped', 'crossOwnerKeysFor']) {
402
402
  assert.equal(typeof governancePort[name], 'function', `the port must expose ${name}`);
403
403
  }