Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(post-upgrade): banner names captured_facts_active and loop_facts_drift with their explicit previews (D14)
garrytan99e3916acd36
diff --git a/test/post-upgrade-banner.test.ts b/test/post-upgrade-banner.test.tsindex a6b728940a..cbfb228cfc 100644--- a/test/post-upgrade-banner.test.ts+++ b/test/post-upgrade-banner.test.ts@@ -5,12 +5,25 @@* command. The banner runs the full wave checks, not doctor --fast.*/import { describe, expect, test } from 'bun:test';-import { readFileSync } from 'node:fs';+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';import { join } from 'node:path';import { postUpgradeRecoveryBanner } from '../src/commands/doctor/upgrade-banner.ts';+import { writeSingleFact } from '../src/core/facts/write-single.ts';+import { upsertOpenLoop } from '../src/core/loops/loops-store.ts';import { managedBrain } from './helpers/managed-brain.ts';+import { withEnv } from './helpers/with-env.ts';import { put, waveBrain } from './helpers/wave-fixture.ts';+/** A CLAUDE_CONFIG_DIR holding one gbrain claude-cli scratch-project transcript (session `sess-self`). */+function selfCaptureHost(): string {+ const claude = mkdtempSync(join(tmpdir(), 'gbrain-banner-claude-'));+ const scratch = join(claude, 'projects', '-tmp-gbrain-claude-cli-cwd-4242');+ mkdirSync(scratch, { recursive: true });+ writeFileSync(join(scratch, 'sess-self.jsonl'), '{}\n');+ return claude;+}+describe('post-upgrade recovery banner', () => {test('a brain with wave findings gets one preview-only [AGENT] banner', async () => {await waveBrain(async ({ engine }) => {@@ -36,6 +49,35 @@ describe('post-upgrade recovery banner', () => {});}, 180_000);+ test('captured facts from gbrain\'s own sessions name the captured-facts preview (D14)', async () => {+ const claude = selfCaptureHost();+ try {+ await withEnv({ CLAUDE_CONFIG_DIR: claude }, () => managedBrain(async ({ engine }) => {+ for (const fact of ['Alice Example prefers Rust for systems work', 'Alice Example ships on Fridays']) {+ await writeSingleFact(engine, 'default', { fact, entity: 'people/alice-example', provenance: 'hook:writeback', sessionId: 'sess-self' });+ }+ const text = (await postUpgradeRecoveryBanner(engine, 'host')).join('\n');+ expect(text).toContain('[AGENT] captured_facts_active: 2 (explicit_kind_required; preview with: gbrain repair captured-facts)');+ expect(text).not.toContain('loop_facts_drift');+ expect(text).not.toContain('--apply');+ }));+ } finally { rmSync(claude, { recursive: true, force: true }); }+ }, 180_000);++ test('closed loops with an active commitment fact name the loop-facts preview (D14)', async () => {+ await managedBrain(async ({ engine }) => {+ const { id: factId } = await writeSingleFact(engine, 'default', { fact: 'Send the deck by Friday', entity: 'people/alice-example', provenance: 'cli:remember' });+ const { id: loopId } = await upsertOpenLoop(engine, { sourceId: 'default', dedupKey: 'commit:deck', loopType: 'commitment_owed_by_me',+ summary: 'Send the deck by Friday', evidence: [], threadId: 'example', pageSlug: 'emails/example', detector: 'llm_extract', factId });+ // What loops_close left before #5869: the loop closed, its fact still active.+ await engine.executeRaw("UPDATE open_loops SET status='done', closed_at=now(), closed_by='manual' WHERE id=$1", [loopId]);+ const text = (await postUpgradeRecoveryBanner(engine, 'host')).join('\n');+ expect(text).toContain('[AGENT] loop_facts_drift: 1 (explicit_kind_required; preview with: gbrain repair loop-facts)');+ expect(text).not.toContain('captured_facts_active');+ expect(text).not.toContain('--apply');+ });+ }, 180_000);+test('post-upgrade prints the banner and no longer prints an applying safe-chunk advisory', () => {// test-reads-source-ok[structural]: runPostUpgrade needs a configured brain plus a full migration run; this pins that it calls the banner and no longer prints the applying advisory.const source = readFileSync(join(import.meta.dir, '..', 'src', 'commands', 'upgrade.ts'), 'utf8');