Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Test that commands added since the base refuse under enforced member mode

garrytanc47fb542b8ef
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index 4ca1950983..9b1726eb41 100644
--- a/scripts/structural-suites.tsv
+++ b/scripts/structural-suites.tsv
@@ -156,7 +156,7 @@ test/e2e/segmented-rls-scope.test.ts (file-level) 5 readFileSync
test/e2e/workspace-generic-compat.test.ts generic agent-workspace compat (INSTALL_FOR_AGENTS.md flow) 6 readFileSync
test/embedding-dim-check-facts.test.ts doctor checkFactsEmbeddingWidthConsistency wiring (T6) 4 doctor-source-helper
test/embedding-dim-check-facts.test.ts postgres-engine fact insert cast (T6, codex #20) 1 source-surface-helper
-test/enforced-member-classes.test.ts enforced member allow-list 4 readFileSync
+test/enforced-member-classes.test.ts enforced member allow-list 6 readFileSync
test/env-trust-protected-keys.test.ts CWD_DOTENV_PROTECTED_KEYS covers every suspicious GBRAIN_* env read in src/ 3 readFileSync
test/error-catalogue.test.ts error code registry (agent contract v1) 5 readFileSync
test/error-registry-6317-contract.test.ts #6317 codes are registered with a full envelope 3 readFileSync
diff --git a/test/enforced-member-classes.test.ts b/test/enforced-member-classes.test.ts
index e047a2c751..8c9a050b56 100644
--- a/test/enforced-member-classes.test.ts
+++ b/test/enforced-member-classes.test.ts
@@ -14,6 +14,7 @@ import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { CLI_COMMANDS } from '../src/cli/command-table.ts';
import { OPERATION_MANIFEST } from '../src/cli/op-manifest.ts';
+import { ROUTERS } from '../src/cli/subcommands.ts';
import { CLI_COMMAND_CLASSES, OPERATION_CLASSES, OPERATION_SUBCOMMANDS, enforcedClassOf } from '../src/cli/enforced-member-classes.ts';
const CLASSES_SRC = readFileSync(join(import.meta.dir, '..', 'src', 'cli', 'enforced-member-classes.ts'), 'utf8');
@@ -38,6 +39,27 @@ describe('enforced member allow-list', () => {
for (const name of Object.keys(OPERATION_SUBCOMMANDS)) expect({ name, op: opNames.has(name), cliOnly: cliOnly.has(name) }).toEqual({ name, op: true, cliOnly: false });
});
+ test('every router subcommand in the live registry has a class, and a refused command refuses every subcommand', () => {
+ const opByCli = new Map(OPERATION_MANIFEST.flatMap(o => [o.cliHints?.name ?? o.name, ...(o.cliHints?.aliases ?? [])].map(n => [n, o.name] as const)));
+ const classes = new Set(['read', 'write', 'allowed', 'silent', 'refused']);
+ for (const [command, router] of Object.entries(ROUTERS)) {
+ const known = CLI_COMMAND_CLASSES[command] !== undefined || opByCli.has(command);
+ expect({ command, known }).toEqual({ command, known: true });
+ const whole = enforcedClassOf(command, [], opByCli.get(command));
+ for (const sub of router.subcommands) {
+ const cls = enforcedClassOf(command, [sub], opByCli.get(command));
+ expect({ command, sub, classified: classes.has(cls), refusedWithParent: whole !== 'refused' || cls === 'refused' }).toEqual({ command, sub, classified: true, refusedWithParent: true });
+ }
+ }
+ });
+
+ test('the commands and flags added since the mode landed are refused', () => {
+ for (const [command, args] of [
+ ['access', ['rule', 'add', '--slug', 'notes/x-example', '--readers', 'alice-example']], ['access', ['owner', 'reads-restricted', 'on']],
+ ['access', ['owner', 'reads-restricted', 'off']], ['repair', ['visibility', '--slug', 'notes/x-example']], ['trust', ['backfill', '--label-lowerings']],
+ ] as const) expect({ command, args: args.join(' '), cls: enforcedClassOf(command, args, undefined) }).toEqual({ command, args: args.join(' '), cls: 'refused' });
+ });
+
test('an unknown command or operation resolves to refused', () => {
expect(enforcedClassOf('no-such-command-example', [], undefined)).toBe('refused');
expect(enforcedClassOf('no-such-command-example', [], 'no_such_op_example')).toBe('refused');
diff --git a/test/enforced-member.serial.test.ts b/test/enforced-member.serial.test.ts
index 06a909a502..b2138c084a 100644
--- a/test/enforced-member.serial.test.ts
+++ b/test/enforced-member.serial.test.ts
@@ -233,6 +233,8 @@ for (const kind of testBackends()) {
[['upgrade'], 'upgrade'], [['autopilot', 'status'], 'autopilot'], [['repair', 'frontmatter'], 'repair'], [['delete', PAGES.open.slug], 'delete'],
[['reindex'], 'reindex'], [['embed', '--stale'], 'embed'], [['dream'], 'dream'], [['write-requests'], 'write-requests'],
[['sources', 'writer', 'status'], 'sources writer'], [['recall', '--since-last-run', '--json'], 'recall'],
+ [['access', 'owner', 'reads-restricted', 'on'], 'access'], [['access', 'rule', 'add', '--slug', PAGES.open.slug, '--readers', MEMBER], 'access'],
+ [['repair', 'visibility', '--slug', PAGES.open.slug], 'repair'], [['trust', 'backfill', '--label-lowerings'], 'trust'],
];
for (const [args, command] of cases) {
const r = await cli(args);