Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
/**
* trust_release_unpreviewed_fields doctor check (#7656) on a brain with no trust releases: ok, read-only, categorized.
* The listing itself runs on real releases in test/trust-release-preview-binding.test.ts (PGLite and Postgres).
*
* PGLite in-memory ($0).
*/
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import type { Check } from '../src/commands/doctor.ts';
import type { DoctorContext } from '../src/commands/doctor/context.ts';
import { trustReleaseUnpreviewedEntry } from '../src/commands/doctor/checks/trust-release-unpreviewed.ts';
import { categorizeCheck } from '../src/core/doctor-categories.ts';
let engine: PGLiteEngine;
beforeAll(async () => {
engine = new PGLiteEngine();
await engine.connect({});
await engine.initSchema();
}, 60_000);
afterAll(async () => { if (engine) await engine.disconnect(); }, 60_000);
describe('trust_release_unpreviewed_fields doctor check', () => {
test('a brain with no trust release is ok and the check is categorized', async () => {
const [check] = await trustReleaseUnpreviewedEntry.run({ engine } as unknown as DoctorContext) as Check[];
expect(check).toMatchObject({ name: 'trust_release_unpreviewed_fields', status: 'ok', details: { total: 0, items: [] } });
expect(categorizeCheck('trust_release_unpreviewed_fields')).toBe('brain');
}, 60_000);
// Generated by gstack /ship Step 7 coverage audit (#7794).
// Value: protects=the check lists at most five facts in its message, reports the full total, and names its first row as the read-only fix target;
// fails_when=the five-row message cap or the "and N more" count is dropped, or total reads the page of rows instead of the window count;
// seam=none; no_claim=the SQL itself (a stub engine returns the rows; the listing is exercised against real releases in trust-release-preview-binding.test.ts)
test('a listing past five rows names five, counts the rest, and points the fix at the first row', async () => {
const rows = Array.from({ length: 7 }, (_, i) => ({ id: i + 1, source_id: 'default', slug: 'people/alice-example', row_num: i + 1, hold_id: 10 + i, total: 52 }));
const [check] = await trustReleaseUnpreviewedEntry.run({ engine: { executeRaw: async () => rows } } as unknown as DoctorContext) as Check[];
expect(check).toMatchObject({ name: 'trust_release_unpreviewed_fields', status: 'warn', details: { total: 52 } });
expect(check!.message).toContain('f5 (default/people/alice-example row 5, released h14)');
expect(check!.message).not.toContain('f6 ');
expect(check!.message).toContain('; and 47 more.');
expect(check!.fix).toMatchObject({ argv: ['gbrain', 'trust', 'explain', 'f1'] });
});
// Value: protects=a schema that predates trust releases reports ok, while any other read failure surfaces as a warn with its error instead of a silent ok;
// fails_when=the missing-schema classification swallows every error, or a pre-trust schema reports a failure; why_new=only the empty-brain path was covered;
// seam=none; no_claim=real pre-trust schemas (the errors are the exact Postgres wording, thrown by a stub engine)
test('a missing trust table is ok (pre_trust); any other error is reported, never swallowed', async () => {
const run = (error: unknown) => trustReleaseUnpreviewedEntry.run({ engine: { executeRaw: async () => { throw error; } } } as unknown as DoctorContext) as Promise<Check[]>;
const [preTrust] = await run(Object.assign(new Error('relation "write_gate_holds" does not exist'), { code: '42P01' }));
expect(preTrust).toMatchObject({ status: 'ok', details: { schema: 'pre_trust' } });
const [failed] = await run(new Error('connection reset by peer'));
expect(failed).toMatchObject({ name: 'trust_release_unpreviewed_fields', status: 'warn' });
expect(failed!.message).toContain('connection reset by peer');
});
});