Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(admin): route goldens cover the access admin routes; inline express.json so the runtime golden maps them

garrytan7475a815f704
diff --git a/src/commands/serve-http-access.ts b/src/commands/serve-http-access.ts
index e7d6141ce3..31bcce5781 100644
--- a/src/commands/serve-http-access.ts
+++ b/src/commands/serve-http-access.ts
@@ -13,13 +13,12 @@ import { executeRawJsonb } from '../core/sql-query.ts';
* gbrain access member add|disable|enable|link|unlink).
*/
export function mountAdminAccess(app: Express, requireAdmin: RequestHandler, engine: BrainEngine): void {
- const json = express.json();
app.get('/admin/api/access/members', requireAdmin, async (req, res) => {
await answer(res, false, async () => ({ members: await listMembers(engine, { includeRemoved: req.query.all === '1' || req.query.all === 'true' }) }));
});
- app.post('/admin/api/access/members', requireAdmin, json, async (req, res) => {
+ app.post('/admin/api/access/members', requireAdmin, express.json(), async (req, res) => {
const { action, id } = req.body ?? {};
if (action !== 'add' && action !== 'disable' && action !== 'enable') return refuse(res, 'action must be add, disable or enable.');
if (action === 'add' && req.body.name !== undefined && typeof req.body.name !== 'string') return refuse(res, 'name must be a string.');
@@ -41,7 +40,7 @@ export function mountAdminAccess(app: Express, requireAdmin: RequestHandler, eng
await answer(res, false, async () => ({ links: await listMemberLinks(engine, { member }) }));
});
- app.post('/admin/api/access/member-links', requireAdmin, json, async (req, res) => {
+ app.post('/admin/api/access/member-links', requireAdmin, express.json(), async (req, res) => {
const { action, member, externalId, dryRun } = req.body ?? {};
const system = req.body?.system ?? 'qm';
if (action !== 'link' && action !== 'unlink') return refuse(res, 'action must be link or unlink.');
@@ -54,7 +53,7 @@ export function mountAdminAccess(app: Express, requireAdmin: RequestHandler, eng
});
});
- app.post('/admin/api/access/attest', requireAdmin, json, async (req, res) => {
+ app.post('/admin/api/access/attest', requireAdmin, express.json(), async (req, res) => {
const { clientId, attestActor, attestOps, dryRun } = req.body ?? {};
if (typeof clientId !== 'string' || !clientId) return refuse(res, 'clientId required.');
if (attestActor === undefined && attestOps === undefined) return refuse(res, 'Pass attestActor (qm or null) and/or attestOps.');
diff --git a/test/fixtures/goldens/serve-http/routes-runtime.json b/test/fixtures/goldens/serve-http/routes-runtime.json
index dabcb5f177..0229075226 100644
--- a/test/fixtures/goldens/serve-http/routes-runtime.json
+++ b/test/fixtures/goldens/serve-http/routes-runtime.json
@@ -617,6 +617,49 @@
"method": "post",
"path": "/admin/api/rescope-client"
},
+ {
+ "handlers": [
+ "requireAdmin#4",
+ "<anonymous>"
+ ],
+ "method": "get",
+ "path": "/admin/api/access/members"
+ },
+ {
+ "handlers": [
+ "requireAdmin#4",
+ "jsonParser",
+ "<anonymous>"
+ ],
+ "method": "post",
+ "path": "/admin/api/access/members"
+ },
+ {
+ "handlers": [
+ "requireAdmin#4",
+ "<anonymous>"
+ ],
+ "method": "get",
+ "path": "/admin/api/access/member-links"
+ },
+ {
+ "handlers": [
+ "requireAdmin#4",
+ "jsonParser",
+ "<anonymous>"
+ ],
+ "method": "post",
+ "path": "/admin/api/access/member-links"
+ },
+ {
+ "handlers": [
+ "requireAdmin#4",
+ "jsonParser",
+ "<anonymous>"
+ ],
+ "method": "post",
+ "path": "/admin/api/access/attest"
+ },
{
"handlers": [
"requireAdmin#4",
@@ -1341,6 +1384,49 @@
"method": "post",
"path": "/admin/api/rescope-client"
},
+ {
+ "handlers": [
+ "requireAdmin#4",
+ "<anonymous>"
+ ],
+ "method": "get",
+ "path": "/admin/api/access/members"
+ },
+ {
+ "handlers": [
+ "requireAdmin#4",
+ "jsonParser",
+ "<anonymous>"
+ ],
+ "method": "post",
+ "path": "/admin/api/access/members"
+ },
+ {
+ "handlers": [
+ "requireAdmin#4",
+ "<anonymous>"
+ ],
+ "method": "get",
+ "path": "/admin/api/access/member-links"
+ },
+ {
+ "handlers": [
+ "requireAdmin#4",
+ "jsonParser",
+ "<anonymous>"
+ ],
+ "method": "post",
+ "path": "/admin/api/access/member-links"
+ },
+ {
+ "handlers": [
+ "requireAdmin#4",
+ "jsonParser",
+ "<anonymous>"
+ ],
+ "method": "post",
+ "path": "/admin/api/access/attest"
+ },
{
"handlers": [
"requireAdmin#4",
diff --git a/test/fixtures/goldens/serve-http/routes.json b/test/fixtures/goldens/serve-http/routes.json
index ce46c0055d..bc28666c85 100644
--- a/test/fixtures/goldens/serve-http/routes.json
+++ b/test/fixtures/goldens/serve-http/routes.json
@@ -454,6 +454,54 @@
"path": "/admin/api/rescope-client",
"when": []
},
+ {
+ "handlers": [
+ "requireAdmin",
+ "<inline>"
+ ],
+ "method": "get",
+ "path": "/admin/api/access/members",
+ "when": []
+ },
+ {
+ "handlers": [
+ "requireAdmin",
+ "express.json()",
+ "<inline>"
+ ],
+ "method": "post",
+ "path": "/admin/api/access/members",
+ "when": []
+ },
+ {
+ "handlers": [
+ "requireAdmin",
+ "<inline>"
+ ],
+ "method": "get",
+ "path": "/admin/api/access/member-links",
+ "when": []
+ },
+ {
+ "handlers": [
+ "requireAdmin",
+ "express.json()",
+ "<inline>"
+ ],
+ "method": "post",
+ "path": "/admin/api/access/member-links",
+ "when": []
+ },
+ {
+ "handlers": [
+ "requireAdmin",
+ "express.json()",
+ "<inline>"
+ ],
+ "method": "post",
+ "path": "/admin/api/access/attest",
+ "when": []
+ },
{
"handlers": [
"requireAdmin",