Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(w13): seeded local_path pages carry their files (#6398 DB-only route, P1.17 fixture flips)
time-attack866f36a91979
diff --git a/test/checkpoint-harvest.serial.test.ts b/test/checkpoint-harvest.serial.test.tsindex bf1e3e8019..c4eeb406a2 100644--- a/test/checkpoint-harvest.serial.test.ts+++ b/test/checkpoint-harvest.serial.test.ts@@ -11,6 +11,7 @@import { describe, test, expect, beforeAll, afterAll, beforeEach, afterEach, spyOn } from 'bun:test';import { randomUUID } from 'node:crypto';import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { serializePageToMarkdown } from '../src/core/markdown.ts';import { join } from 'node:path';import { tmpdir } from 'node:os';import { PGLiteEngine } from '../src/core/pglite-engine.ts';@@ -123,9 +124,12 @@ async function enableFenceWrites(): Promise<string> {describe('post-compaction recall (the done criterion)', () => {test('segment → harvest → truthful manifest → link re-pull via trusted get_page', async () => {const brainDir = await enableFenceWrites();- await engine.putPage('people/alice-example', {+ const alice = await engine.putPage('people/alice-example', {type: 'person', title: 'Alice Example', compiled_truth: 'Alice Example is a synthetic fixture person.',}, { sourceId: 'default' });+ // The page has its file, as a local_path brain's pages do (#6398: a DB-only page takes the DB-only fact route).+ mkdirSync(join(brainDir, 'people'), { recursive: true });+ writeFileSync(join(brainDir, 'people/alice-example.md'), serializePageToMarkdown(alice, []));chatStub([{ fact: 'decided to move the auth check into the middleware', entity: 'people/alice-example' },{ fact: 'unparented aside that produces no link', entity: null },diff --git a/test/facts-backstop-entity-inference.test.ts b/test/facts-backstop-entity-inference.test.tsindex 5be7a97a68..2c76744e7b 100644--- a/test/facts-backstop-entity-inference.test.ts+++ b/test/facts-backstop-entity-inference.test.ts@@ -8,7 +8,9 @@* PGLite, unmanaged (persistence off), chat stubbed. Synthetic names only.*/import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';-import { mkdtempSync, readFileSync, rmSync } from 'node:fs';+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { serializePageToMarkdown } from '../src/core/markdown.ts';+import type { Page } from '../src/core/types.ts';import { tmpdir } from 'node:os';import { join } from 'node:path';import { PGLiteEngine } from '../src/core/pglite-engine.ts';@@ -48,10 +50,11 @@ async function backstopPage(slug: string, type: 'note' | 'meeting') {return r;}+const pages: Page[] = [];beforeAll(async () => {engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema();- const page = (slug: string, title: string, type: string, frontmatter: Record<string, unknown> = {}) =>- engine.putPage(slug, { type: type as never, title, compiled_truth: `# ${title}\n\n${BODY}`, frontmatter }, { sourceId: 'default' });+ const page = async (slug: string, title: string, type: string, frontmatter: Record<string, unknown> = {}) =>+ pages.push(await engine.putPage(slug, { type: type as never, title, compiled_truth: `# ${title}\n\n${BODY}`, frontmatter }, { sourceId: 'default' }));await page('companies/acme-example', 'Acme Example', 'note');await page('companies/widget-example', 'Widget Example', 'company');await page('people/dana-private-example', 'Dana Private-Example', 'person', { visibility: 'private' });@@ -59,6 +62,11 @@ beforeAll(async () => {}, 60_000);beforeEach(async () => {dir = mkdtempSync(join(tmpdir(), 'backstop-infer-'));+ // The pages have their files, as a local_path brain's pages do (#6398: a DB-only page takes the DB-only fact route).+ for (const p of pages) {+ mkdirSync(join(dir, p.slug, '..'), { recursive: true });+ writeFileSync(join(dir, `${p.slug}.md`), serializePageToMarkdown(p, []));+ }await engine.executeRaw(`UPDATE sources SET local_path=$1 WHERE id='default'`, [dir]);_resetWriteThroughCacheForTest();});diff --git a/test/loops-close-fact.serial.test.ts b/test/loops-close-fact.serial.test.tsindex 1658e1278e..2f30c2ed1d 100644--- a/test/loops-close-fact.serial.test.ts+++ b/test/loops-close-fact.serial.test.ts@@ -15,6 +15,9 @@*/import { afterAll, beforeAll, describe, expect, test } from 'bun:test';import { randomUUID } from 'node:crypto';+import { mkdirSync, writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { serializePageToMarkdown } from '../src/core/markdown.ts';import type { BrainEngine } from '../src/core/engine.ts';import type { OperationContext } from '../src/core/ops/contract.ts';import { configureGateway, resetGateway, __setChatTransportForTests, type ChatResult } from '../src/core/ai/gateway.ts';@@ -59,9 +62,15 @@ async function seedCommitment(engine: BrainEngine, managed: boolean) {} else {await disposePersistenceConsumer(engine);await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');- await engine.putPage('people/alice-example', { title: 'Alice Example', type: 'person', compiled_truth: '# Alice Example' }, { sourceId: f.id });- await engine.putPage('emails/example', { title: 'Synthetic exchange', type: 'email', compiled_truth: 'I will send the deck by Friday.',- frontmatter: { thread_id: 'example', from: '[email protected]' } }, { sourceId: f.id });+ const written = [await engine.putPage('people/alice-example', { title: 'Alice Example', type: 'person', compiled_truth: '# Alice Example' }, { sourceId: f.id }),+ await engine.putPage('emails/example', { title: 'Synthetic exchange', type: 'email', compiled_truth: 'I will send the deck by Friday.',+ frontmatter: { thread_id: 'example', from: '[email protected]' } }, { sourceId: f.id })];+ // The pages have their files, as a local_path source's pages do (#6398: a DB-only page takes the DB-only fact route).+ const [{ local_path: root }] = await engine.executeRaw<{ local_path: string | null }>('SELECT local_path FROM sources WHERE id=$1', [f.id]);+ for (const page of written) if (root) {+ mkdirSync(join(root, page.slug, '..'), { recursive: true });+ writeFileSync(join(root, `${page.slug}.md`), serializePageToMarkdown(page, []));+ }}const extracted = await runLoopsExtract(engine, { slug: 'emails/example', sourceId: f.id });expect(extracted).toMatchObject({ status: 'extracted', commitments: 1 });