Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: pre-landing review fixes (accept-all reports a pending release as pending, not 'not applied')
garrytane24695d43191
diff --git a/src/commands/trust.ts b/src/commands/trust.tsindex 6125217101..cfe932f92c 100644--- a/src/commands/trust.ts+++ b/src/commands/trust.ts@@ -28,6 +28,8 @@ import {type TrustExplanation, type TrustReview, type TrustReviewFilter,} from '../core/trust/review.ts';import { trustLabel } from '../core/trust/tier.ts';+import { PENDING_WRITE_EXIT_CODE } from '../core/exit-codes.ts';+import { pendingReceiptOf, pollCommand } from '../core/persistence/write-wait.ts';import { reportPersistenceCliError } from './persistence-delegate.ts';import { writeCliError } from '../cli/cli-error.ts';@@ -159,17 +161,24 @@ async function acceptAll(backend: TrustBackend, args: string[], json: boolean):const summary = [`Accept ${previews.length} item(s):`, ...previews.map(p => ` ${p.ref.padEnd(6)} ${p.summary}`)].join('\n');await requireOwnerConfirmation(LOCAL_CTX, { ref: `${previews.length} items`, token, summary, command });const accepted: OwnerActionResult[] = [];+ const pending: Array<{ ref: string; request_id: string; poll: string }> = [];const failed: Array<{ ref: string; error: unknown }> = [];for (let i = 0; i < inputs.length; i++) {try { accepted.push(await backend.apply(inputs[i]!, previews[i]!.binding, previews[i]!.raises)); }- catch (error) { failed.push({ ref: previews[i]!.ref, error: error instanceof OperationError ? error.toJSON() : String(error) }); }+ catch (error) {+ const receipt = pendingReceiptOf(error);+ if (receipt) pending.push({ ref: previews[i]!.ref, request_id: receipt.request_id, poll: pollCommand(receipt.request_id) });+ else failed.push({ ref: previews[i]!.ref, error: error instanceof OperationError ? error.toJSON() : String(error) });+ }}- if (json) await writeStdoutFinal(`${JSON.stringify({ accepted, failed }, null, 2)}\n`);+ if (json) await writeStdoutFinal(`${JSON.stringify({ accepted, pending, failed }, null, 2)}\n`);else {for (const r of accepted) console.log(resultLine(r));+ for (const p of pending) console.log(`${p.ref}: accepted, still pending (request ${p.request_id}; check with ${p.poll})`);for (const f of failed) console.log(`${f.ref}: not applied (${(f.error as { message?: string }).message ?? String(f.error)})`);}if (failed.length) setCliExitVerdict(1);+ else if (pending.length) setCliExitVerdict(PENDING_WRITE_EXIT_CODE);}/** Renders a refusal through the shared CLI envelope with its contract exit code (3 for consent refusals). */diff --git a/test/trust-owner-actions.test.ts b/test/trust-owner-actions.test.tsindex 02ddb4d146..e85f3160ee 100644--- a/test/trust-owner-actions.test.ts+++ b/test/trust-owner-actions.test.ts@@ -16,7 +16,7 @@* insufficient_scope, a stale approval applies, or the listing drifts.* Runs on PGLite, and on Postgres when DATABASE_URL is set.*/-import { _resetCliExitVerdictForTests } from '../src/core/cli-force-exit.ts';+import { _resetCliExitVerdictForTests, currentExitCode } from '../src/core/cli-force-exit.ts';import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';import { randomUUID } from 'node:crypto';import { mkdtempSync, readFileSync, rmSync, writeFileSync, mkdirSync } from 'node:fs';@@ -478,6 +478,32 @@ describe('review, explain and accept-all (CEO-2, DX-10, DX-15, DX-16)', () => {for (const slug of ['notes/bulk-a-example', 'notes/bulk-b-example']) expect((await pageRow(b, slug)).trust_tier).toBe('user_confirmed');}), 90_000);+ test('accept-all reports a release still pending in the door as pending (exit 10 with its poll command), never as not applied', async () => withEnv({ GBRAIN_HOME: home }, async () => {+ const requestId = randomUUID();+ const pending = Object.assign(new OperationError('write_pending', 'The write is accepted and is still pending.'),+ { writeRequest: { request_id: requestId, state: 'queued', retry_after_ms: 1000 } });+ const backend = {+ review: async () => ({ items: [{ kind: 'hold', ref: 'h7', source_id: 'default' }, { kind: 'hold', ref: 'h8', source_id: 'default' }] }),+ explain: async () => [],+ preview: async (input: OwnerActionInput) => ({ action: 'release', ref: input.ref, token: input.ref, command: `gbrain trust release ${input.ref}`, raises: true, binding: `b-${input.ref}`, summary: `Release held fact ${input.ref}` }),+ apply: async (input: OwnerActionInput) => {+ if (input.ref === 'h7') throw pending;+ return { action: 'release', ref: 'h8', status: 'released', tier: 'user_confirmed' };+ },+ } as unknown as Parameters<typeof runTrustOwnerCommand>[0];+ typesToken();+ const lines: string[] = [];+ const original = console.log;+ console.log = (...args: unknown[]) => { lines.push(args.join(' ')); };+ let exit: number | undefined;+ try { await runTrustOwnerCommand(backend, 'review', ['--accept-all', '--from', 'default']); exit = currentExitCode(); }+ finally { console.log = original; process.exitCode = 0; _resetCliExitVerdictForTests(); }+ expect(lines.join('\n')).not.toContain('h7: not applied');+ expect(lines.find(l => l.startsWith('h7:'))).toContain(requestId);+ expect(lines.find(l => l.startsWith('h8:'))).toContain('released');+ expect(exit).toBe(10);+ }), 60_000);+test('the review listing is pinned (DX-16) and explain names tier, origin, receipts and activation', async () => withEnv({ GBRAIN_HOME: home }, async () => {const engine = engines[0]!;const b = await brain(engine);