Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
/**
* F4b (spec 5.3 test 10, O-CEO-9): the planner-stats objects exist on PGLite
* only. The committed catalog goldens (regenerated by
* test/schema-catalog-golden.test.ts and its Postgres twin
* test/e2e/schema-catalog-golden.test.ts) carry the two tables, the function
* and the 18 statement triggers for every PGLite config, and none of them for
* any Postgres config. Postgres write paths gain no trigger.
*/
import { describe, test, expect } from 'bun:test';
import { readdirSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { PLANNER_STATS_TABLES } from '../src/core/planner-stats-schema.ts';
const DIR = join(import.meta.dir, 'fixtures', 'goldens', 'catalog');
const goldens = readdirSync(DIR).filter(f => f.endsWith('.json'));
const text = (file: string) => readFileSync(join(DIR, file), 'utf8');
describe('planner-stats catalog goldens', () => {
test('every PGLite engine-init golden has the accounting tables, function and triggers', () => {
const pglite = goldens.filter(f => f.startsWith('pglite-engine-init-'));
expect(pglite.length).toBe(3);
for (const file of pglite) {
const golden = text(file);
expect(golden).toContain('"planner_stats_deltas": {');
expect(golden).toContain('"planner_stats_state": {');
expect(golden).toContain('"gbrain_count_modifications()"');
for (const table of PLANNER_STATS_TABLES) {
for (const [trigger, event, rows] of [['planner_stats_ins', 'INSERT', 'NEW'], ['planner_stats_upd', 'UPDATE', 'NEW'], ['planner_stats_del', 'DELETE', 'OLD']]) {
expect(golden).toContain(`"${table}.${trigger}": "CREATE TRIGGER ${trigger} AFTER ${event} ON public.${table} REFERENCING ${rows} TABLE AS ${rows.toLowerCase()}_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()"`);
}
}
}
});
test('no Postgres golden has any planner-stats object', () => {
const postgres = goldens.filter(f => f.startsWith('postgres-'));
expect(postgres.length).toBeGreaterThan(0);
for (const file of postgres) {
expect(text(file)).not.toContain('planner_stats');
expect(text(file)).not.toContain('gbrain_count_modifications');
}
});
});