Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(doctor): stamp the soak counter day in the Postgres hot-check golden
garrytan2448c83ac97f
diff --git a/test/doctor-hot-checks-sync-day.test.ts b/test/doctor-hot-checks-sync-day.test.tsindex 11fca77f39..26a7cfdbff 100644--- a/test/doctor-hot-checks-sync-day.test.ts+++ b/test/doctor-hot-checks-sync-day.test.ts@@ -4,11 +4,12 @@* that pins the capture day (2026-10-10) fails on any other day; `stampSyncDay`* accepts the run only when every trend day is the day the sync stamped and* that day is one of the days read around the sync, and it touches no other field.+ * The soak counters' day gets the same treatment from `stampSoakDays`.*/import { describe, expect, test } from 'bun:test';import { readFileSync } from 'node:fs';import { join } from 'node:path';-import { stampSyncDay, SYNC_DAY } from './helpers/doctor-hot-checks-fixture.ts';+import { SOAK_DAY, stampSoakDays, stampSyncDay, SYNC_DAY } from './helpers/doctor-hot-checks-fixture.ts';type Check = { name: string; message?: string; details?: { trend?: Array<{ by_day?: Array<{ day: string }> }> } };type Report = { checks: Check[] };@@ -16,6 +17,9 @@ const golden = (JSON.parse(readFileSync(join(import.meta.dir, 'fixtures/goldens//** The recorded report with its fence trend day set to `day` (a run on that day). */const runOn = (day: string): Report => JSON.parse(JSON.stringify(golden).replaceAll(`"day":"${SYNC_DAY}"`, `"day":"${day}"`)) as Report;+/** The recorded report with its soak counter day set to `day`. */+const soakOn = (day: string): Report => JSON.parse(JSON.stringify(golden).replaceAll(`"day":"${SOAK_DAY}"`, `"day":"${day}"`)) as Report;+const soakDays = (report: Report) => report.checks.filter(c => c.name === 'sync_soak_counters').flatMap(c => (c.details as { by_day?: Array<{ day: string }> } | undefined)?.by_day ?? []).map(d => d.day);const trendDays = (report: Report) => report.checks.filter(c => c.name === 'fence_integrity').flatMap(c => c.details?.trend ?? []).flatMap(t => t.by_day ?? []).map(d => d.day);describe('Postgres hot-check golden: the fence trend day', () => {@@ -47,3 +51,22 @@ describe('Postgres hot-check golden: the fence trend day', () => {expect(stampSyncDay(drifted, '2026-11-20', ['2026-11-20', '2026-11-20'])).not.toEqual(golden);});});++describe('Postgres hot-check golden: the soak counter day', () => {+ test('the recorded run carries a soak day to check', () => {+ expect(soakDays(golden)).toEqual([SOAK_DAY]);+ });++ test('a run on any day passes when that day was recorded; an unrecorded day fails', () => {+ expect(soakOn('2026-10-16')).not.toEqual(soakOn('2026-10-17'));+ expect(stampSoakDays(soakOn('2026-10-17'), ['2026-10-17'])).toEqual(golden);+ expect(stampSoakDays(soakOn('2026-10-16'), ['2026-10-16', '2026-10-17'])).toEqual(golden);+ expect(() => stampSoakDays(soakOn('2026-10-17'), ['2026-10-16'])).toThrow('not a day the fixture recorded soak counters');+ });++ test('only the soak day is replaced: the fence trend day is left to its own check', () => {+ const both = JSON.parse(JSON.stringify(runOn('2026-11-20')).replaceAll(`"day":"${SOAK_DAY}"`, '"day":"2026-10-17"')) as Report;+ expect(stampSoakDays(both, ['2026-10-17'])).not.toEqual(golden);+ expect(stampSyncDay(stampSoakDays(both, ['2026-10-17']), '2026-11-20', ['2026-11-20', '2026-11-20'])).toEqual(golden);+ });+});diff --git a/test/e2e/doctor-hot-checks-golden.test.ts b/test/e2e/doctor-hot-checks-golden.test.tsindex 9986bd84e3..82f0e472d2 100644--- a/test/e2e/doctor-hot-checks-golden.test.ts+++ b/test/e2e/doctor-hot-checks-golden.test.ts@@ -16,7 +16,8 @@ import { assertSafeE2eDatabaseUrl } from '../helpers/db-guard.ts';import { defineNormalizer, expectGolden, expectNormalizerStable } from '../helpers/golden.ts';import { doctorJsonNormalizer, makeDoctorHome, networkAttempts, runGbrain, type DoctorHome, type GbrainRun } from '../helpers/doctor-json-golden.ts';import { FENCE_TREND_OP } from '../../src/core/fence-repair/census-store.ts';-import { buildHotCheckFixture, editHotCheckFixture, stampSyncDay, type Sql } from '../helpers/doctor-hot-checks-fixture.ts';+import { buildHotCheckFixture, editHotCheckFixture, stampSoakDays, stampSyncDay, type Sql } from '../helpers/doctor-hot-checks-fixture.ts';+import { SOAK_COUNTERS_OP } from '../../src/core/persistence/soak-counters.ts';const DATABASE_URL = process.env.DATABASE_URL;const describeE2E = DATABASE_URL ? describe : describe.skip;@@ -77,10 +78,13 @@ async function capture(adminUrl: string): Promise<PgCaptures> {expect(networkAttempts(h)).toEqual([]);// Real clock here (the server's now() stamps last_sync_at): the fence trend day is checked against the day the sync stamped, then stored as <sync-day>.const db = postgres(url, { max: 1, prepare: false });- const stamped = await db.unsafe(`SELECT DISTINCT completed_keys->0->>'day' AS day FROM op_checkpoints WHERE op = $1`, [FENCE_TREND_OP]).finally(() => db.end());+ const [stamped, soak] = await Promise.all([+ db.unsafe(`SELECT DISTINCT completed_keys->0->>'day' AS day FROM op_checkpoints WHERE op = $1`, [FENCE_TREND_OP]),+ db.unsafe(`SELECT fingerprint FROM op_checkpoints WHERE op = $1`, [SOAK_COUNTERS_OP]),+ ]).finally(() => db.end());expect(stamped.length).toBe(1);const day = stamped[0]!.day as string;- for (const run of [first, second]) run.json = stampSyncDay(run.json, day, syncDays);+ for (const run of [first, second]) run.json = stampSoakDays(stampSyncDay(run.json, day, syncDays), soak.map(r => String(r.fingerprint)));return { first, second, url, name };}diff --git a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json b/test/fixtures/goldens/doctor/hot-checks-postgres-json.jsonindex 8565982aaf..47f001e1dd 100644--- a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json+++ b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json@@ -677,7 +677,7 @@"by_day": [{"content_decisions": 0,- "day": "2026-10-16",+ "day": "<soak-day>","interventions": 1}],@@ -4602,7 +4602,7 @@"by_day": [{"content_decisions": 0,- "day": "2026-10-16",+ "day": "<soak-day>","interventions": 1}],diff --git a/test/helpers/doctor-hot-checks-fixture.ts b/test/helpers/doctor-hot-checks-fixture.tsindex 3aab6be94d..737b7ca7c0 100644--- a/test/helpers/doctor-hot-checks-fixture.ts+++ b/test/helpers/doctor-hot-checks-fixture.ts@@ -189,6 +189,25 @@ export function stampSyncDay(report: unknown, stamped: string, syncDays: readonlreturn copy;}+export const SOAK_DAY = '<soak-day>';++/**+ * The soak counters are stamped on the real clock too (one `op_checkpoints` row per UTC day the fixture recorded an+ * intervention), so doctor `sync_soak_counters.details.by_day[].day` is that day. This replaces exactly that field, and+ * only after checking each entry is a day a soak row was recorded for (`recorded`, read back from the database).+ */+export function stampSoakDays(report: unknown, recorded: readonly string[]): unknown {+ const copy = structuredClone(report) as { checks?: Array<{ name: string; details?: { by_day?: Array<{ day: string }> } }> };+ for (const check of copy.checks ?? []) {+ if (check.name !== 'sync_soak_counters') continue;+ for (const entry of check.details?.by_day ?? []) {+ if (!recorded.includes(entry.day)) throw new Error(`sync_soak_counters day ${entry.day} is not a day the fixture recorded soak counters (${recorded.join(', ') || 'none'})`);+ entry.day = SOAK_DAY;+ }+ }+ return copy;+}+/*** Edits between the first and second doctor run, so the second run takes the* incremental paths (changed-file census pass, resumed timeline state): one