Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(test-infra): a snapshot-restored PGLite brain is created now, not at snapshot build time
garrytanb4ca55ebc55d
diff --git a/src/core/pglite-engine.ts b/src/core/pglite-engine.tsindex 3813652404..502de50992 100644--- a/src/core/pglite-engine.ts+++ b/src/core/pglite-engine.ts@@ -912,17 +912,17 @@ export class PGLiteEngine implements BrainEngine {...embedded,}),));- // Snapshot-timezone parity: dumpDataDir bakes the BUILD process's- // TimeZone into the restored cluster's defaults, so a snapshot-loaded- // engine would run sessions in the build machine's zone while a- // cold-init engine follows this process (bun test pins TZ=UTC; bun run- // follows the host). That divergence shifted every naive-timestamp- // day-boundary comparison by the offset — date-dependent tests failed- // only in the evening, only under the snapshot. Pin the session to the- // RUNTIME zone so restored engines behave exactly like cold ones.+ // Snapshot parity: dumpDataDir bakes the BUILD process's TimeZone into+ // the cluster defaults (date-dependent tests failed only in the evening,+ // only under the snapshot) and the BUILD time into the seeded sources'+ // created_at (a CI-cached snapshot over an hour old made every fresh+ // test brain fail the behavior_changes fresh-install grace, which reads+ // MIN(sources.created_at)). Pin the RUNTIME zone and stamp now(), so+ // restored engines behave like cold ones (bun test pins TZ=UTC).if (this._snapshotLoaded && this._db) {const runtimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';await this._db.query(`SELECT set_config('TimeZone', $1, false)`, [runtimeZone]);+ await this._db.query(`UPDATE sources SET created_at = now()`);}// Healthy open: close any repair episode left open by a prior failed// attempt (red-team: episodes otherwise stayed open forever — doctordiff --git a/test/pglite-snapshot-timezone.serial.test.ts b/test/pglite-snapshot-timezone.serial.test.tsindex 21cb54b81f..62f48e5b86 100644--- a/test/pglite-snapshot-timezone.serial.test.ts+++ b/test/pglite-snapshot-timezone.serial.test.ts@@ -63,3 +63,23 @@ describe('PGLite snapshot timezone parity', () => {expect(snap).toBe(cold);}, 120_000);});++describe('PGLite snapshot creation-time parity', () => {+ test('a snapshot-restored brain is created now, like a cold init (not when the snapshot was built)', async () => {+ const prev = process.env.GBRAIN_PGLITE_SNAPSHOT;+ process.env.GBRAIN_PGLITE_SNAPSHOT = SNAPSHOT;+ const engine = new PGLiteEngine();+ try {+ await Bun.sleep(1500);+ const t0 = Date.now();+ await engine.connect({} as never);+ await engine.initSchema();+ const rows = await engine.executeRaw<{ at: string | Date }>(`SELECT MIN(created_at) AS at FROM sources`);+ expect(new Date(rows[0].at).getTime()).toBeGreaterThanOrEqual(t0 - 500);+ } finally {+ await engine.disconnect?.();+ if (prev === undefined) delete process.env.GBRAIN_PGLITE_SNAPSHOT;+ else process.env.GBRAIN_PGLITE_SNAPSHOT = prev;+ }+ }, 120_000);+});