hub-roles-first-write-guard.test.mjs
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0
feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes…
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
1 commit
sha256:93bcf8f9bd56d8c5b9339f4ec73b9ebd66571398d56262d38eedc2cfa9db9882
fix(test): align Band B landing assertion with desktop MCP …
Human
11 days ago