Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(ci-local): give PgBouncer admin sessions their own database so shard 1's cleanup cannot kill them (#6674)
time-attack4cefe55a73d5
diff --git a/scripts/ci-local.sh b/scripts/ci-local.shindex 9d82329c8e..504f38858a 100755--- a/scripts/ci-local.sh+++ b/scripts/ci-local.sh@@ -165,10 +165,13 @@ echo "[runner] slow tests (DATABASE_URL unset)"env -u DATABASE_URL -u GBRAIN_DATABASE_URL bun run test:slowecho "[runner] unit (unsharded, DATABASE_URL unset)"env -u DATABASE_URL bash scripts/run-unit-shard.sh+echo "[runner] PgBouncer admin database (gbrain_ci_admin_test on postgres-1)"+bun scripts/lib/ensure-e2e-database.ts postgresql://postgres:postgres@postgres-1:5432/gbrain_test gbrain_ci_admin_test \+ || { echo "[runner] ERROR: could not create gbrain_ci_admin_test; E2E not started" >&2; exit 1; }echo "[runner] e2e (unsharded)"DATABASE_URL=postgresql://postgres:postgres@postgres-1:5432/gbrain_test \GBRAIN_PGBOUNCER_URL=postgresql://postgres:postgres@pgbouncer:5432/gbrain_pgbouncer_test \-GBRAIN_PGBOUNCER_DIRECT_URL=postgresql://postgres:postgres@postgres-1:5432/gbrain_test \+GBRAIN_PGBOUNCER_DIRECT_URL=postgresql://postgres:postgres@postgres-1:5432/gbrain_ci_admin_test \GBRAIN_PGBOUNCER_E2E_DB=gbrain_test \GBRAIN_CI_REQUIRE_PGBOUNCER=1 \GBRAIN_TEST_DB=1 \@@ -194,6 +197,14 @@ export GBRAIN_PGLITE_SNAPSHOT=test/fixtures/pglite-snapshot.tar# file in the container than natively — timeout-class failures that pass on# the host. Scale the per-test ceiling for the container lane (overridable).export GBRAIN_TEST_TIMEOUT_MULTIPLIER=\${GBRAIN_TEST_TIMEOUT_MULTIPLIER:-6}+# #6674: E2E files hold administrative sessions on GBRAIN_PGBOUNCER_DIRECT_URL+# across a file, while run-e2e.sh terminates every other session on its own+# DATABASE_URL between files. The admin database is therefore no shard's+# database (shard 1 uses postgres-1/gbrain_test), created once before any+# shard starts.+echo \"[runner] PgBouncer admin database (gbrain_ci_admin_test on postgres-1)\"+bun scripts/lib/ensure-e2e-database.ts postgresql://postgres:postgres@postgres-1:5432/gbrain_test gbrain_ci_admin_test \\+ || { echo \"[runner] ERROR: could not create gbrain_ci_admin_test; shards not started\" >&2; exit 1; }mkdir -p /tmp/shard-logsecho \"[runner] Tier 1: 4-shard parallel unit + E2E (xargs -P4)\"set +e@@ -214,7 +225,7 @@ printf '%s\\n' 1 2 3 4 | xargs -P4 -I{} sh -c 'SHARD=\${shard}/4 \\DATABASE_URL=postgresql://postgres:postgres@postgres-\${shard}:5432/gbrain_test \\GBRAIN_PGBOUNCER_URL=postgresql://postgres:postgres@pgbouncer:5432/gbrain_pgbouncer_test \\- GBRAIN_PGBOUNCER_DIRECT_URL=postgresql://postgres:postgres@postgres-1:5432/gbrain_test \\+ GBRAIN_PGBOUNCER_DIRECT_URL=postgresql://postgres:postgres@postgres-1:5432/gbrain_ci_admin_test \\GBRAIN_PGBOUNCER_E2E_DB=gbrain_pooled_\${shard}_test \\GBRAIN_CI_REQUIRE_PGBOUNCER=1 \\GBRAIN_TEST_DB=1 \\diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsvindex 0751e6fa1f..7d509286ff 100644--- a/scripts/structural-suites.tsv+++ b/scripts/structural-suites.tsv@@ -286,7 +286,7 @@ test/scripts/ci-executed-counts.test.ts CLI 2 readFileSynctest/scripts/ci-gates.test.ts CI execution evidence 6 readFileSynctest/scripts/ci-gates.test.ts test:full exit status 0 readFileSynctest/scripts/ci-local-rendering.test.ts ci-local command rendering 1 readFileSync-test/scripts/ci-local-rendering.test.ts ci-local execution coverage 5 readFileSync+test/scripts/ci-local-rendering.test.ts ci-local execution coverage 7 readFileSynctest/scripts/ci-local-rendering.test.ts local test configuration through run-e2e 2 readFileSynctest/scripts/ci-local-rendering.test.ts required PgBouncer execution through run-e2e 1 readFileSynctest/scripts/ci-manifest-diff.test.ts test.yml dependency-audit scope 2 readFileSyncdiff --git a/test/scripts/ci-local-rendering.test.ts b/test/scripts/ci-local-rendering.test.tsindex 715bf05eb0..4fdd54e43a 100644--- a/test/scripts/ci-local-rendering.test.ts+++ b/test/scripts/ci-local-rendering.test.ts@@ -108,6 +108,10 @@ function runPhases(noShard: boolean, diff: boolean, failStage = '') {for (const name of ['git', 'python3', 'ps', 'psql', 'apt-get']) put(`bin/${name}`, 'exit 0');put('bin/bun', `case "$*" in+ "scripts/lib/ensure-e2e-database.ts "*)+ printf 'admin_db:%s:%s\\n' "$2" "$3" >> "$TRACE"+ [ "$FAIL_STAGE" != admin_db ] || exit 7+ exit 0 ;;"run verify") stage=verify ;;"run test:serial") stage=serial ;;"run test:slow") stage=slow ;;@@ -131,7 +135,7 @@ for line in {1..35}; do printf 'fixture progress %s\\n' "$line"; doneset -eucase "$DATABASE_URL" in postgresql://postgres:postgres@postgres-*:5432/gbrain_test) ;; *) exit 42 ;; esac[ "$GBRAIN_PGBOUNCER_URL" = postgresql://postgres:postgres@pgbouncer:5432/gbrain_pgbouncer_test ] || exit 43-[ "$GBRAIN_PGBOUNCER_DIRECT_URL" = postgresql://postgres:postgres@postgres-1:5432/gbrain_test ] || exit 44+[ "$GBRAIN_PGBOUNCER_DIRECT_URL" = postgresql://postgres:postgres@postgres-1:5432/gbrain_ci_admin_test ] || exit 44[ "$GBRAIN_CI_REQUIRE_PGBOUNCER" = 1 ] || exit 45[ "$GBRAIN_TEST_DB" = 1 ] || exit 46printf 'target:%s\\n' "$DATABASE_URL" "$GBRAIN_PGBOUNCER_URL" "$GBRAIN_PGBOUNCER_DIRECT_URL" >> "$TRACE"@@ -190,6 +194,28 @@ describe('ci-local execution coverage', () => {}}+ for (const noShard of [false, true]) {+ test(`the PgBouncer admin database is created first and is no shard's database (#6674, no-shard=${noShard})`, () => {+ const result = runPhases(noShard, false);+ expect(result.status, result.stdout + result.stderr).toBe(0);+ const targets = result.trace.filter(line => line.startsWith('target:')).map(line => new URL(line.slice(7)));+ const shards = targets.filter((_, i) => i % 3 === 0);+ const admins = new Set(targets.filter((_, i) => i % 3 === 2).map(url => `${url.host}${url.pathname}`));+ expect([...admins]).toEqual(['postgres-1:5432/gbrain_ci_admin_test']);+ for (const shard of shards) expect(shard.pathname).not.toBe('/gbrain_ci_admin_test');+ const created = result.trace.indexOf('admin_db:postgresql://postgres:postgres@postgres-1:5432/gbrain_test:gbrain_ci_admin_test');+ expect(created).toBeGreaterThanOrEqual(0);+ expect(created).toBeLessThan(result.trace.findIndex(line => line.startsWith('e2e:')));+ });+ }++ test('a failed admin database bootstrap starts no shard', () => {+ const result = runPhases(false, false, 'admin_db');+ expect(result.status).toBe(1);+ expect(result.stderr).toContain('could not create gbrain_ci_admin_test; shards not started');+ expect(result.trace.some(line => line.startsWith('unit:') || line.startsWith('e2e:'))).toBe(false);+ });+for (const failStage of ['timeout_guard', 'verify', 'serial', 'slow', 'unit', 'e2e']) {test(`a failed ${failStage} stage cannot produce a green local CI result`, () => {const result = runPhases(false, false, failStage);