Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(graduation): harness targets get their own Postgres database; older-release scenarios pick tags below the first graduation release

garrytane48a081d41ca
diff --git a/test/helpers/graduation-e2e.ts b/test/helpers/graduation-e2e.ts
index f5ef8798b7..3fe238189b 100644
--- a/test/helpers/graduation-e2e.ts
+++ b/test/helpers/graduation-e2e.ts
@@ -259,7 +259,14 @@ export function manifestPath(home: string): string {
// ── Older released binaries ───────────────────────────────────────────────────
-/** The last `count` release tags at or below this checkout's VERSION, newest first (from origin). */
+/**
+ * The first release that ships engine graduation. "Older release" scenarios
+ * model clients that predate graduation (they ignore its markers), so their
+ * tags must stay below it even after later releases are tagged.
+ */
+const FIRST_GRADUATION_RELEASE = '0.60.52.0';
+
+/** The last `count` release tags below both this checkout's VERSION and the first graduation release, newest first (from origin). */
export function previousReleaseTags(count = 2): string[] {
const version = readFileSync(join(REPO, 'VERSION'), 'utf8').trim();
const out = Bun.spawnSync(['git', '-C', REPO, 'ls-remote', '--tags', '--refs', 'origin', 'v*'], { stdout: 'pipe', stderr: 'pipe' });
@@ -267,8 +274,9 @@ export function previousReleaseTags(count = 2): string[] {
const parse = (tag: string) => tag.slice(1).split('.').map(Number);
const cmp = (a: number[], b: number[]) => { for (let i = 0; i < Math.max(a.length, b.length); i++) { const d = (a[i] ?? 0) - (b[i] ?? 0); if (d) return d; } return 0; };
const current = version.split('.').map(Number);
+ const graduation = FIRST_GRADUATION_RELEASE.split('.').map(Number);
return out.stdout.toString().split('\n').map(line => line.split('refs/tags/')[1]).filter((t): t is string => !!t && /^v\d+(\.\d+){3}$/.test(t))
- .filter(t => cmp(parse(t), current) <= 0).sort((a, b) => cmp(parse(b), parse(a))).slice(0, count);
+ .filter(t => cmp(parse(t), current) <= 0 && cmp(parse(t), graduation) < 0).sort((a, b) => cmp(parse(b), parse(a))).slice(0, count);
}
/**
diff --git a/test/helpers/graduation-harness.ts b/test/helpers/graduation-harness.ts
index 3e99d0f269..35c908acd0 100644
--- a/test/helpers/graduation-harness.ts
+++ b/test/helpers/graduation-harness.ts
@@ -9,13 +9,15 @@
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
-import { createHash } from 'node:crypto';
+import { createHash, randomUUID } from 'node:crypto';
+import postgres from '#postgres';
import { PGLiteEngine } from '../../src/core/pglite-engine.ts';
import type { BrainEngine } from '../../src/core/engine.ts';
import type { GraduationDeps } from '../../src/core/persistence/engine-graduation.ts';
import type { InventoryEntry, TableReceipt, VerifyResult } from '../../src/core/persistence/engine-graduation.types.ts';
import { withGraduationRun } from '../../src/core/persistence/graduation-schema.ts';
import { withEnv } from './with-env.ts';
+import { assertSafeE2eDatabaseUrl } from './db-guard.ts';
export const PROBE: InventoryEntry = {
relation: 'grad_probe', kind: 'table', class: 'carry', engines: { pglite: true, postgres: true },
@@ -91,18 +93,34 @@ export interface Harness {
export interface HarnessOptions { postgresUrl?: string }
-async function freshTarget(opts: HarnessOptions): Promise<BrainEngine> {
+/**
+ * An empty target brain. On Postgres it is a database of its own, dropped on
+ * close: a graduation leaves its target fenced (rollback abandons it that way
+ * on purpose), and the shared test database must stay writable for every
+ * later file in the same lane.
+ */
+async function freshTarget(opts: HarnessOptions): Promise<{ engine: BrainEngine; drop: () => Promise<void> }> {
if (!opts.postgresUrl) {
const engine = new PGLiteEngine();
await engine.connect({ engine: 'pglite' });
- return engine;
+ return { engine, drop: async () => {} };
}
+ assertSafeE2eDatabaseUrl(opts.postgresUrl);
const { PostgresEngine } = await import('../../src/core/postgres-engine.ts');
+ const database = `gbrain_test_graduation_${randomUUID().replace(/-/g, '')}`;
+ const admin = postgres(opts.postgresUrl, { max: 1, prepare: false });
+ await admin.unsafe(`CREATE DATABASE ${database}`);
+ const url = new URL(opts.postgresUrl);
+ url.pathname = `/${database}`;
const engine = new PostgresEngine();
- await engine.connect({ engine: 'postgres', database_url: opts.postgresUrl });
- await engine.executeRaw('DROP SCHEMA IF EXISTS public CASCADE');
- await engine.executeRaw('CREATE SCHEMA public');
- return engine;
+ const drop = async () => { await admin.unsafe(`DROP DATABASE IF EXISTS ${database} WITH (FORCE)`); await admin.end(); };
+ try {
+ await engine.connect({ engine: 'postgres', database_url: url.toString() });
+ } catch (error) {
+ await drop();
+ throw error;
+ }
+ return { engine, drop };
}
/** A source brain with history-shaped rows: three probe rows and one access token. */
@@ -124,7 +142,7 @@ export async function makeHarness(opts: HarnessOptions = {}): Promise<Harness> {
await source.executeRaw(`INSERT INTO access_tokens (id, name, token_hash) VALUES ($1::uuid, 'agent-example', 'hash-a1')`, [SOURCE_TOKEN_ID]);
} finally { await source.disconnect(); }
});
- const target = await freshTarget(opts);
+ const { engine: target, drop: dropTarget } = await freshTarget(opts);
const calls: Record<string, number> = {};
const count = (name: string) => { calls[name] = (calls[name] ?? 0) + 1; };
const deps: Partial<GraduationDeps> = {
@@ -186,7 +204,7 @@ export async function makeHarness(opts: HarnessOptions = {}): Promise<Harness> {
return {
root, home, gbrainDir, dataDir, mountsPath, target, deps, calls,
inHome: fn => withEnv({ GBRAIN_HOME: home }, fn),
- close: async () => { await target.disconnect(); },
+ close: async () => { await target.disconnect(); await dropTarget(); },
};
}