Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(sync): count the pass's read-only round snapshots apart in the waiver-run bound, at most one per round (4b Postgres sweep)

garrytanf5374618b82e
diff --git a/test/sync-waiver-run-imports.test.ts b/test/sync-waiver-run-imports.test.ts
index 57121847ac..b942f89775 100644
--- a/test/sync-waiver-run-imports.test.ts
+++ b/test/sync-waiver-run-imports.test.ts
@@ -56,10 +56,18 @@ async function syncedSource(engine: BrainEngine, n: number) {
}
const importRequests = (engine: BrainEngine, id: string) => engine.executeRaw<{ slug: string; state: string }>(
"SELECT slug,state FROM persistence_requests WHERE source_id=$1 AND intent->>'kind'='managed_sync_import' ORDER BY sequence", [id]);
-function countTransactions(engine: BrainEngine): { engine: BrainEngine; count: () => number } {
- let count = 0;
- return { count: () => count, engine: new Proxy(engine, { get(target, key) {
- if (key === 'transaction') return (fn: (tx: BrainEngine) => Promise<unknown>) => { count++; return target.transaction(fn); };
+/**
+ * The engine's transactions, with the pass's round snapshots counted apart: on Postgres each pass round reads its level in
+ * one `REPEATABLE READ, READ ONLY` transaction (`withRoundSnapshot`, sync-pass.ts); PGLite (one connection) runs those
+ * reads without a transaction. They are bounded by rounds, not files, so they are asserted per round instead.
+ */
+function countTransactions(engine: BrainEngine): { engine: BrainEngine; count: () => number; snapshots: () => number } {
+ let count = 0, snapshots = 0;
+ return { count: () => count, snapshots: () => snapshots, engine: new Proxy(engine, { get(target, key) {
+ if (key === 'transaction') return (fn: (tx: BrainEngine) => Promise<unknown>) => {
+ if (new Error().stack?.includes('withRoundSnapshot')) snapshots++; else count++;
+ return target.transaction(fn);
+ };
const value = Reflect.get(target, key);
return typeof value === 'function' ? value.bind(target) : value;
} }) };
@@ -79,6 +87,7 @@ test('a full re-sync of unchanged files waives them in one waiver-run transactio
expect((await importRequests(engine, f.id)).length).toBe(before);
// The per-entry path takes two transactions per file (24 here); the run takes one for all twelve.
expect(counted.count()).toBeLessThan(8);
+ expect(counted.snapshots()).toBeLessThanOrEqual(engine.kind === 'postgres' ? result.pass!.round : 0);
} finally { await disposePersistenceConsumer(counted.engine); }
}
}), 120_000);