Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(cli): cover -y=value, end-to-end scope and consent refusals, stray-target codes (#7619 ship coverage)
garrytanba28870a030e
diff --git a/test/cli-flag-equals.test.ts b/test/cli-flag-equals.test.tsindex 9e63cb8a49..551d76f4e9 100644--- a/test/cli-flag-equals.test.ts+++ b/test/cli-flag-equals.test.ts@@ -196,13 +196,33 @@ describe('#7619 refusals that keep consent, scope and targets right', () => {}});+ // Value: protects=a split value never becomes the first numeric/slug target (forget --purge --reason=3 34 must not hit fact 3); fails_when=a refusal turns into a split or keep; why_new=rows only asserted not-null; seam=none; no_claim=handler behavior after a split (argv-level only)test('a flag value never becomes the numeric or slug target of a mutating subcommand', async () => {for (const [command, args] of [['forget', ['--purge', '--reason=3', '34', '--dry-run']], ['forget', ['--purge', '--source=7', '34', '--yes', '--request-id', 'r1']],['edge-proposals', ['accept', '--limit=3', '7']], ['edge-proposals', ['accept', '--row=3', '7']],['decide', ['proposals', 'accept', '--limit=3', '7']],['loops', ['drop', '--note=7', '12']], ['pages', ['unpurge', '--source-id=people/alice-example', 'people/bob-example']],- ] as const) expect(await refusalFor(command, [...args])).not.toBeNull();+ ['takes', ['propose', '--accept', '7', '--weight=3']],+ ] as const) {+ const token = args.find(a => a.includes('='))!;+ const r = await cliOnlyFlagArgs(command, [...args]);+ expect('refusal' in r && r.refusal.code).toBe('invalid_params');+ expect('refusal' in r && r.refusal.message).toContain(`${token.split('=')[0]}=…`);+ expect('refusal' in r && r.refusal.message).not.toContain(token);+ }+ });++ // Value: protects=-y=<v> never reaches a handler as -y/--yes consent; fails_when=EQUALS_TOKEN or the split widens to single-dash and -y=n becomes -y + n; why_new=only --yes=n rows existed; seam=none; no_claim=entry refusal of -y=<v> (it is kept and ignored, see audit finding)+ test('a short -y=value is never turned into consent', async () => {+ for (const [command, args] of [+ ['reinit-pglite', ['-y=n']], ['reinit-pglite', ['-y=yes']], ['cache', ['clear', '-y=true']], ['reindex-code', ['-y=1']],+ ] as const) {+ const r = await cliOnlyFlagArgs(command, [...args]);+ if ('refusal' in r) continue;+ expect(r.args).not.toContain('-y');+ expect(r.args).not.toContain('--yes');+ }});test('subcommands with their own = parser get their argv unchanged', async () => {diff --git a/test/serve-flag-equals.test.ts b/test/serve-flag-equals.test.tsindex e35ca22094..e25de01153 100644--- a/test/serve-flag-equals.test.ts+++ b/test/serve-flag-equals.test.ts@@ -8,7 +8,7 @@*/import { afterAll, beforeAll, describe, expect, test } from 'bun:test';import { spawnSync } from 'node:child_process';-import { mkdtempSync, rmSync } from 'node:fs';+import { existsSync, mkdtempSync, readdirSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import { Client } from '@modelcontextprotocol/sdk/client/index.js';@@ -91,6 +91,35 @@ describe('serve --flag=value', () => {expect(r.stderr).not.toContain('cannot be combined');});+ // Value: protects=auth create --scopes=read exits 2 and mints no token (never a full-access one); fails_when=--scopes=… is dropped or kept and auth create runs; why_new=in-process rows never ran the handler or checked the token table; seam=none; no_claim=the separate-form --scopes path (PGLite brain)+ test('auth create --scopes=read refuses and mints no token', () => {+ const r = cli(['auth', 'create', 'bot-example', '--scopes=read']);+ expect(r.status).toBe(2);+ expect(r.stderr).toContain('reads --scopes only as a separate argument');+ expect(r.stderr).toContain('--scopes <value>');+ const list = cli(['auth', 'list']);+ expect(list.status).toBe(0);+ expect(list.stdout + list.stderr).not.toContain('bot-example');+ });++ // Value: protects=--yes=n refuses instead of consenting and a split value never retargets forget; brain left intact; fails_when=the entry drops or splits these tokens; why_new=in-process rows never checked the brain afterwards; seam=none; no_claim=a fact-level purge check (no facts in the hermetic brain)+ test('reinit-pglite --yes=n and forget --purge --reason=3 34 refuse before touching the brain', () => {+ const brainDir = join(home, '.gbrain');+ const before = readdirSync(brainDir).sort();+ expect(existsSync(join(brainDir, 'brain.pglite'))).toBe(true);+ for (const [args, message] of [+ [['reinit-pglite', '--yes=n'], 'Write --yes on its own'],+ [['forget', '--purge', '--reason=3', '34', '--yes'], 'reads --reason only as a separate argument'],+ ] as const) {+ const r = cli([...args]);+ expect(r.status).toBe(2);+ expect(r.stderr).toContain(message);+ expect(r.stdout).toBe('');+ }+ expect(readdirSync(brainDir).sort()).toEqual(before);+ expect(cli(['auth', 'list']).status).toBe(0);+ });+test('--help still answers when an = token would refuse', () => {const r = cli(['serve', '--source-guard=true', '--help']);expect(r.status).toBe(0);