Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test: setupDB resets managed-persistence state; sync-lock E2E runs on a set-up classic brain; verify watchdog TERM race
time-attackc4e18c32fa22
diff --git a/docs/TESTING.md b/docs/TESTING.mdindex 0000168379..5e8b63b04e 100644--- a/docs/TESTING.md+++ b/docs/TESTING.md@@ -107,9 +107,11 @@ captured at registration so hooks retain it after the import environment restoreEvery backend's assertions remain in the shared suites; engine-specific cases runin their owning lane.-Ordinary PostgreSQL `setupDB()` clears fixture data, operator configuration and-source sync identity while retaining `config.version` and the stored embedding-identity, avoiding historical migration+Ordinary PostgreSQL `setupDB()` clears fixture data, operator configuration,+source sync identity and managed-persistence state (requests, and the+`persistence_brain` row back to disabled, protocol floor 1, shared skill bundles+off, as a fresh-database CLI `gbrain init` leaves them raised) while retaining+`config.version` and the stored embedding identity, avoiding historical migrationreplay against an already-current schema. Migration-focused fixtures use`setupDB({ replayMigrations: true })`; an absent ledger also runs the cold chain.`test/e2e/fixture-reset-postgres.test.ts` checks both paths, cleanup and vector-shapediff --git a/scripts/run-verify-parallel.sh b/scripts/run-verify-parallel.shindex c06ca0af21..c6232e05a0 100755--- a/scripts/run-verify-parallel.sh+++ b/scripts/run-verify-parallel.sh@@ -295,9 +295,12 @@ spawn_check() {# The watchdog owns no caller pipes (an orphaned sleep holding stdout# stalled spawnSync callers for the whole $TIMEOUT) and its TERM trap# takes its sleep down with it, closing the window where pkill -P runs- # before the sleep is forked.- ( trap 'kill "$nap" 2>/dev/null; exit 0' TERM+ # before the sleep is forked. A TERM that lands between the fork and+ # `nap=$!` only records itself; the sleep is killed once its pid is known.+ ( trap 'term=1' TERMsleep "$TIMEOUT" & nap=$!+ trap 'kill "$nap" 2>/dev/null; exit 0' TERM+ [ -z "${term:-}" ] || { kill "$nap" 2>/dev/null; exit 0; }wait "$nap" && kill -TERM "$pid" 2>/dev/null && \sleep 5 && kill -KILL "$pid" 2>/dev/null ) </dev/null >/dev/null 2>&1 &cap_pid=$!diff --git a/test/e2e/helpers.ts b/test/e2e/helpers.tsindex c1e1006a70..d8cc2fd820 100644--- a/test/e2e/helpers.ts+++ b/test/e2e/helpers.ts@@ -62,6 +62,10 @@ const ALL_TABLES = ['minion_attachments','minion_inbox','minion_jobs',+ // A fresh-database `gbrain init` commits a protocol-2 shared-skill request;+ // the request guard refuses to delete it (cascading from a source delete)+ // in any later protocol-1 session. TRUNCATE fires no row guard.+ 'persistence_requests',];/**@@ -132,9 +136,15 @@ export async function setupDB(options: { replayMigrations?: boolean } = {}): Protry {// A file that activated managed persistence and exited without// deactivating leaves the writer guard armed, and its sources trigger- // rejects the reset below (writer_coordinator_required). Restore the- // schema default (disabled) first.- await conn.unsafe(`UPDATE persistence_brain SET enabled = false, activated_at = NULL WHERE singleton = 1`);+ // rejects the reset below (writer_coordinator_required). A fresh-database+ // `gbrain init` also raises the writer protocol floor to 2 with shared+ // skill bundles on, after which every protocol-1 request is refused+ // (writer_upgrade_required). Restore the schema defaults (disabled, floor+ // 1, bundles off) first. The floor trigger forbids lowering it by UPDATE,+ // so the singleton row is replaced with its other columns kept.+ await conn.unsafe(`WITH old AS (DELETE FROM persistence_brain WHERE singleton = 1 RETURNING *)+ INSERT INTO persistence_brain SELECT (jsonb_populate_record(NULL::persistence_brain, to_jsonb(old)+ || '{"enabled": false, "activated_at": null, "writer_protocol_floor": 1, "skill_bundles_enabled": false}'::jsonb)).* FROM old`);await conn.unsafe(`DELETE FROM sources WHERE id <> 'default'`);// Only the sync-identity columns: local_path feeds writeSyncAnchor's// ownership guard (#3735) and last_commit/last_sync_at feed first_syncdiff --git a/test/e2e/sync-lock-overlap-postgres.test.ts b/test/e2e/sync-lock-overlap-postgres.test.tsindex a8deb18fc3..d477c01293 100644--- a/test/e2e/sync-lock-overlap-postgres.test.ts+++ b/test/e2e/sync-lock-overlap-postgres.test.ts@@ -1,15 +1,21 @@-import { describe, expect, test } from 'bun:test';+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';import { hostname, tmpdir } from 'node:os';import { join, resolve } from 'node:path';import postgres from '#postgres'import { assertSafeE2eDatabaseUrl } from '../helpers/db-guard.ts';import { makeGitFixture } from '../helpers/git-fixture.ts';+import { setupDB, teardownDB } from './helpers.ts';const databaseUrl = process.env.DATABASE_URL;const cli = resolve(import.meta.dir, '../../src/cli.ts');describe.skipIf(!databaseUrl)('sync lock overlap on Postgres', () => {+ // The CLI `init` below must meet an existing, classic (unmanaged) brain:+ // on a fresh database it activates managed persistence, whose sync refuses+ // a Git pull and publishes through the coordinator instead of this lock.+ beforeAll(async () => { await setupDB(); });+ afterAll(async () => { await teardownDB(); });test('held owner excludes every contender, releases, and permits a later sync', async () => {assertSafeE2eDatabaseUrl(databaseUrl!);const count = Number(process.env.NUM_PARALLEL ?? 4);