hub-roles-first-write-guard.test.mjs
44 lines 1.4 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 11 days ago
1 /**
2 * First write to hub_roles.json must keep the acting user as admin so local operators
3 * are not locked out of Team / POST /api/v1/roles (see hub/roles.mjs + hub/server.mjs).
4 */
5 import { test } from 'node:test';
6 import assert from 'node:assert/strict';
7 import { ensureActorAdminOnFirstRolesPopulation } from '../hub/roles.mjs';
8
9 test('first population: adds actor as admin alongside new row', () => {
10 const out = ensureActorAdminOnFirstRolesPopulation(
11 0,
12 { 'google:999': 'viewer' },
13 'google:111',
14 );
15 assert.deepEqual(out, {
16 'google:999': 'viewer',
17 'google:111': 'admin',
18 });
19 });
20
21 test('first population: actor already in map keeps admin if set', () => {
22 const out = ensureActorAdminOnFirstRolesPopulation(
23 0,
24 { 'google:111': 'admin', 'google:999': 'editor' },
25 'google:111',
26 );
27 assert.equal(out['google:111'], 'admin');
28 assert.equal(out['google:999'], 'editor');
29 });
30
31 test('subsequent writes: does not inject admin row', () => {
32 const out = ensureActorAdminOnFirstRolesPopulation(
33 2,
34 { 'google:111': 'admin', 'google:999': 'evaluator' },
35 'google:111',
36 );
37 assert.deepEqual(out, { 'google:111': 'admin', 'google:999': 'evaluator' });
38 });
39
40 test('empty actor sub: unchanged', () => {
41 const row = { 'google:999': 'viewer' };
42 assert.deepEqual(ensureActorAdminOnFirstRolesPopulation(0, row, ''), row);
43 assert.deepEqual(ensureActorAdminOnFirstRolesPopulation(0, row, ' '), row);
44 });
File History 3 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 11 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 31 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 50 days ago