Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(e2e): the backend-matrix passes select the Postgres arm of testBackends

garrytan1dba77b07614
diff --git a/test/helpers/test-backends.ts b/test/helpers/test-backends.ts
index e9ceb35ff6..56b9253592 100644
--- a/test/helpers/test-backends.ts
+++ b/test/helpers/test-backends.ts
@@ -9,12 +9,15 @@ export function requirePostgresTestDatabase(env: Record<string, string | undefin
return env.DATABASE_URL;
}
+/** `postgres` (registerPostgresTests) and the E2E backend matrix passes (scripts/run-e2e.sh: direct and PgBouncer) select the Postgres arm only. */
+const POSTGRES_ONLY_BACKENDS = new Set(['postgres', 'postgres-direct', 'pgbouncer']);
+
export function testBackends(env: Record<string, string | undefined> = process.env): TestBackend[] {
- if (env.GBRAIN_TEST_BACKEND === 'postgres') {
+ if (env.GBRAIN_TEST_BACKEND !== undefined && POSTGRES_ONLY_BACKENDS.has(env.GBRAIN_TEST_BACKEND)) {
requirePostgresTestDatabase(env);
return ['postgres'];
}
- if (env.GBRAIN_TEST_BACKEND !== undefined) throw new Error('Unknown GBRAIN_TEST_BACKEND; expected postgres or unset');
+ if (env.GBRAIN_TEST_BACKEND !== undefined) throw new Error('Unknown GBRAIN_TEST_BACKEND; expected postgres, postgres-direct, pgbouncer or unset');
return env.DATABASE_URL ? ['pglite', 'postgres'] : ['pglite'];
}
diff --git a/test/test-backends.test.ts b/test/test-backends.test.ts
index 6fec79a41e..8c4de39648 100644
--- a/test/test-backends.test.ts
+++ b/test/test-backends.test.ts
@@ -11,6 +11,9 @@ test('direct invocation keeps local-only and opt-in dual-engine execution', () =
test('explicit PostgreSQL selection cannot silently fall back, skip, or use an unsafe database', () => {
expect(testBackends({ GBRAIN_TEST_BACKEND: 'postgres', DATABASE_URL: databaseUrl })).toEqual(['postgres']);
+ // The E2E backend matrix passes (scripts/run-e2e.sh) select the Postgres arm only.
+ expect(testBackends({ GBRAIN_TEST_BACKEND: 'postgres-direct', DATABASE_URL: databaseUrl })).toEqual(['postgres']);
+ expect(testBackends({ GBRAIN_TEST_BACKEND: 'pgbouncer', DATABASE_URL: databaseUrl })).toEqual(['postgres']);
expect(() => testBackends({ GBRAIN_TEST_BACKEND: 'postgres' })).toThrow('requires DATABASE_URL');
expect(() => testBackends({ GBRAIN_TEST_BACKEND: 'postgres', DATABASE_URL: 'postgresql://localhost/operator' })).toThrow('does not look like a test database');
expect(() => testBackends({ GBRAIN_TEST_BACKEND: 'unknown' })).toThrow('Unknown GBRAIN_TEST_BACKEND');