Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(doctor): --only sync_failures connects the brain (#7143)
garrytan756da1294f8a
diff --git a/src/commands/doctor/checks/local-audits.ts b/src/commands/doctor/checks/local-audits.tsindex 53ca4348d5..d80c51fbf1 100644--- a/src/commands/doctor/checks/local-audits.ts+++ b/src/commands/doctor/checks/local-audits.ts@@ -124,6 +124,7 @@ async function runStubGuard(ctx: DoctorContext): Promise<Check[]> {export const stubGuardEntry: DoctorEntry = {name: 'stub_guard_24h',emits: ['stub_guard_24h', 'sync_failures', 'managed_sync_backlog', 'slug_fallback_audit'],+ engineChecks: ['sync_failures', 'managed_sync_backlog'],run: runStubGuard,};diff --git a/test/doctor-only-engine-checks.test.ts b/test/doctor-only-engine-checks.test.tsindex bec4b2cd5b..ba17b1a6dd 100644--- a/test/doctor-only-engine-checks.test.ts+++ b/test/doctor-only-engine-checks.test.ts@@ -37,7 +37,7 @@ const postGate = new Set(DOCTOR_CHECK_REGISTRY.slice(gate + 1).flatMap((e) => e.describe('doctor --only engine need (#6303)', () => {test('engine-reading pre-gate checks need the engine', () => {- for (const name of ['dream_paid_loop', 'connectors', 'extract_atoms_backlog', 'default_source_local_path', 'volunteer_channels']) {+ for (const name of ['dream_paid_loop', 'connectors', 'extract_atoms_backlog', 'default_source_local_path', 'volunteer_channels', 'sync_failures', 'managed_sync_backlog']) {expect(`${name}:${onlyNeedsEngine(new Set([name]))}`).toBe(`${name}:true`);}expect(onlyNeedsEngine(new Set(['pglite_data_dir', 'supervisor', 'harness_wiring']))).toBe(false);diff --git a/test/doctor-only-sync-failures-7143.serial.test.ts b/test/doctor-only-sync-failures-7143.serial.test.tsnew file mode 100644index 0000000000..b4a59e1ea7--- /dev/null+++ b/test/doctor-only-sync-failures-7143.serial.test.ts@@ -0,0 +1,54 @@+/**+ * #7143: `gbrain doctor --only sync_failures` run on its own must connect the+ * brain. The check is emitted by a pre-gate entry (stub_guard_24h), and+ * `onlyNeedsEngine` only connects for names past the DB-checks gate or names+ * declared in `engineChecks`, so the standalone run read the local ledger with+ * no engine and said "Durable sync state is unavailable without a database+ * connection" against a reachable brain.+ *+ * Serial: spawns the CLI against a tmpdir PGLite brain.+ */+import { describe, expect, test } from 'bun:test';+import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { fileURLToPath } from 'node:url';++const REPO = fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/, '');+const SKIP = process.env.GBRAIN_TEST_SKIP_SUBPROCESS === '1';++async function runCli(args: string[], env: Record<string, string>): Promise<{ exitCode: number; stdout: string; stderr: string }> {+ const proc = Bun.spawn(['bun', 'run', `${REPO}/src/cli.ts`, ...args], { cwd: REPO, env: { ...process.env, ...env }, stdout: 'pipe', stderr: 'pipe' });+ const killer = setTimeout(() => { try { proc.kill('SIGKILL'); } catch { /* exited */ } }, 120_000);+ try {+ const [stdout, stderr, exitCode] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited]);+ return { exitCode, stdout, stderr };+ } finally {+ clearTimeout(killer);+ }+}++describe('doctor --only sync_failures connects the brain (#7143)', () => {+ test.skipIf(SKIP)('a standalone run reads the durable state instead of reporting no database connection', async () => {+ const home = mkdtempSync(join(tmpdir(), 'gbrain-only-syncfail-'));+ try {+ mkdirSync(join(home, '.gbrain'), { recursive: true });+ writeFileSync(join(home, '.gbrain', 'config.json'), JSON.stringify({ engine: 'pglite', database_path: join(home, '.gbrain', 'brain.pglite'), embedding_dimensions: 1536 }) + '\n');+ const ledgerDir = join(home, 'sync-failures');+ mkdirSync(ledgerDir, { recursive: true });+ const now = new Date().toISOString();+ writeFileSync(join(ledgerDir, 'sync-failures.jsonl'), JSON.stringify({ source_id: 'default', path: 'notes/alice-example.md', error: 'frontmatter slug does not match the path', code: 'SLUG_MISMATCH', commit: 'abc1234', first_seen: now, ts: now, attempts: 1, state: 'open' }) + '\n');+ const env = { HOME: home, GBRAIN_HOME: home, GBRAIN_AUDIT_DIR: join(home, 'audit'), GBRAIN_SYNC_FAILURES_DIR: ledgerDir };+ expect((await runCli(['init', '--migrate-only'], env)).exitCode).toBe(0);++ const run = await runCli(['doctor', '--only', 'sync_failures', '--json'], env);+ const report = JSON.parse(run.stdout) as { checks: Array<{ name: string; status: string; message: string }> };+ const check = report.checks.find((c) => c.name === 'sync_failures')!;+ expect(check.message).not.toContain('without a database connection');+ expect(check.message).toContain('1 unresolved sync failure');+ expect(report.checks.some((c) => c.name === 'connection' && c.status !== 'ok')).toBe(false);+ } finally {+ rmSync(home, { recursive: true, force: true });+ }+ }, 300_000);+});