Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(lane-h): exit 2 for invalid_params on the persistence lane (A3); routing expectations; lint baseline

garrytan16fc3853010e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0410463103..8edf345531 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -66,7 +66,7 @@ Scripts that parse exit codes or `--json` output should read the [behavior chang
| Unpriced model (no per-token rate known) | refused whenever a cap was set | warns and runs under a derived or default cap; under a user cap refuses with a fix to look up the rate and run `gbrain pricing set` | register the rate, then retry |
| `gbrain reindex-frontmatter --json` | `--json` skipped the confirmation | `--json` never implies consent | pass the authorization the payload names |
| `gbrain jobs submit` on PGLite | queued with no worker to run it | refuses with `no_worker` unless `--follow` or `--queue-only` | add `--follow` (run it now) or `--queue-only` |
-| Invalid input: `autopilot --interval`, `serve --port`, `dream --phase`, `init --mcp-only` missing flags, `delta --since` | exit 1 | exit 2 (`invalid_params`) | treat 2 as "fix the command" |
+| Invalid input: `autopilot --interval`, `serve --port`, `dream --phase`, `init --mcp-only` missing flags, `delta --since`, `gbrain call` with invalid params, thin-client `takes add/update/resolve/supersede` missing flags and `recall --budget-policy`, `sources remove/archive default` | exit 1 | exit 2 (`invalid_params`) | treat 2 as "fix the command" |
| `gbrain doctor --json` with no brain configured | human text or nothing | one `no_brain` envelope with the `gbrain init` fix | parse the document |
| `gbrain serve` on a brain another serve holds, or with no brain | exited before the MCP handshake | completes the handshake in status-only mode with one `gbrain_status` tool; `--fail-fast` (or `GBRAIN_SERVE_FAIL_FAST=1`) restores the early exit for supervisors | read `gbrain_status`; supervisors pass `--fail-fast` |
| Error envelopes | `error`, `message`, `suggestion` | adds `code`, `fix`, `class`, `retryable`, `docs_cmd`, `contract_version`; `error` unchanged (legacy values frozen) | read `code`, fall back to `error` |
diff --git a/src/commands/init-first-run.ts b/src/commands/init-first-run.ts
index 988b4e65c7..02bbd95dcc 100644
--- a/src/commands/init-first-run.ts
+++ b/src/commands/init-first-run.ts
@@ -121,7 +121,7 @@ export function buildInitFirstRunNotices(inputs: InitFirstRunInputs): Notice[] {
export function deferredEmbeddingHint(cfg: GBrainConfig): string {
const enable = embeddingEnablement(cfg);
const step = enable.argv ? shellQuote(enable.argv) : 'gbrain doctor --only embeddings --json';
- return ` --no-embedding: deferred setup — enable later with \`${step}\` (\`config set embedding_model\` is refused by design)`;
+ return ` --no-embedding: deferred setup — enable later with \`${step}\` (setting embedding_model through \`gbrain config set\` is refused by design)`;
}
/** init's bundle for this brain: reads the writeback gate and the agent workspace's missing skills. */
diff --git a/test/doctor-remediate-consent.test.ts b/test/doctor-remediate-consent.test.ts
index 78eff2ded2..94c2b6b83f 100644
--- a/test/doctor-remediate-consent.test.ts
+++ b/test/doctor-remediate-consent.test.ts
@@ -52,9 +52,10 @@ test('unauthorized and --json-only runs change nothing and exit 3 with the conse
expect(r.exit).toBe(3);
const payload = JSON.parse(r.stdout);
expect(payload).toMatchObject({ status: 'confirmation_required', code: 'confirmation_required', effects: ['paid', 'destructive'], actor: 'agent', contract_version: 1 });
- expect(payload.fix.argv).toEqual(['gbrain', 'doctor', '--remediate', '--include-repairs', '--json', '--yes', '--expect', hash]);
+ // A1 explicit routing: the approved command names the brain it was previewed on.
+ expect(payload.fix.argv).toEqual(['gbrain', 'doctor', '--remediate', '--include-repairs', '--json', '--brain', 'host', '--yes', '--expect', hash]);
expect(payload.fix.next).toBe('ask_user');
- expect(payload.preview.argv).toEqual(['gbrain', 'doctor', '--remediation-plan', '--target-score', '90', '--json']);
+ expect(payload.preview.argv).toEqual(['gbrain', 'doctor', '--remediation-plan', '--target-score', '90', '--json', '--brain', 'host']);
expect(payload.user_message).toContain('Run the brain remediation now');
expect(payload.user_message).toContain('timeline: 1');
expect(await timeline(engine)).toEqual(before);
diff --git a/test/fixtures/goldens/cli/thin-client-routing.json b/test/fixtures/goldens/cli/thin-client-routing.json
index 6f0949c753..93d97c1115 100644
--- a/test/fixtures/goldens/cli/thin-client-routing.json
+++ b/test/fixtures/goldens/cli/thin-client-routing.json
@@ -23,7 +23,7 @@
},
{
"argv": "takes add alice-example",
- "exitCode": 1,
+ "exitCode": 2,
"stderr": [
"Error [invalid_params]: Missing --claim."
],
diff --git a/test/readiness-advice-lint.test.ts b/test/readiness-advice-lint.test.ts
index c030bf75fa..dc003f162f 100644
--- a/test/readiness-advice-lint.test.ts
+++ b/test/readiness-advice-lint.test.ts
@@ -21,7 +21,7 @@ const EXEMPT = new Set(['src/core/readiness.ts', 'src/core/cli-flag-registry.gen
/** Shrink-only baseline: file → allowed hit count, with the owner that removes it. */
const ALLOWLIST: Record<string, { count: number; reason: string }> = {
'src/commands/doctor/checks/embedding-health.ts': { count: 1, reason: 'Lane E1: doctor fixes become readiness Actions' },
- 'src/commands/init.ts': { count: 2, reason: 'Lane E/G5: init deferred-setup hint renders embeddingEnablement' },
+ 'src/commands/init.ts': { count: 1, reason: 'Lane E/G5: init deferred-setup hint renders embeddingEnablement' },
'src/commands/models.ts': { count: 1, reason: 'Lane E: models dims hint' },
'src/commands/reindex-code.ts': { count: 2, reason: 'Lane E: reindex-code embedding hint' },
'src/commands/reinit-pglite.ts': { count: 2, reason: 'usage examples of reinit-pglite\'s own --embedding-model flag' },
diff --git a/test/recall-budget-policy-thin-cli.test.ts b/test/recall-budget-policy-thin-cli.test.ts
index f9669fcaf7..cdc026dc81 100644
--- a/test/recall-budget-policy-thin-cli.test.ts
+++ b/test/recall-budget-policy-thin-cli.test.ts
@@ -83,7 +83,8 @@ test.each([
['--budget-policy', 'query_first', '--watch', '10', '--json'],
].map(args => [args]))('thin CLI rejects invalid policy requests before local or remote work: %j', async args => {
const result = await thinCall('postgres', args);
- expect(result.exitCode).toBe(1);
+ // A3: an invalid request is a usage error, exit 2.
+ expect(result.exitCode).toBe(2);
expect(JSON.parse(result.stdout)).toMatchObject({ error: 'invalid_params' });
expect(result.calls).toEqual([]);
expect(result.localStoreCreated).toBe(false);
diff --git a/test/thin-client-routing.test.ts b/test/thin-client-routing.test.ts
index b49cb7bf9d..04067641a0 100644
--- a/test/thin-client-routing.test.ts
+++ b/test/thin-client-routing.test.ts
@@ -218,7 +218,7 @@ describe('routeThinClientCommand — (b) host-bound forms return false', () => {
}
});
-describe('routeThinClientCommand — (c) malformed routable forms print usage + exit 1', () => {
+describe('routeThinClientCommand — (c) malformed routable forms print usage and exit non-zero (2 for invalid_params)', () => {
async function expectUsageExit(command: string, args: string[]): Promise<void> {
const exitSpy = spyOn(process, 'exit').mockImplementation(((code?: number) => {
throw new Error(`EXIT:${code}`);
@@ -234,7 +234,8 @@ describe('routeThinClientCommand — (c) malformed routable forms print usage +
}
if (command === 'takes' && ['add', 'update', 'resolve', 'supersede'].includes(args[0])) {
expect(exited).toBeNull();
- expect(currentExitCode()).toBe(1);
+ // A3: invalid_params is a usage error, exit 2 (the persistence write lane used to return 1).
+ expect(currentExitCode()).toBe(2);
expect(errs.join('\n')).toContain('Error [invalid_params]');
} else {
expect(exited).toBe('EXIT:1');