Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(tests-heavy): shared database name floor for the heavy shell lane (#3485)
Garry Tan9f598e4b2072
diff --git a/scripts/run-heavy.sh b/scripts/run-heavy.shindex 28c1b26a60..d9ff1adce6 100755--- a/scripts/run-heavy.sh+++ b/scripts/run-heavy.sh@@ -16,6 +16,10 @@set -euo pipefailcd "$(dirname "$0")/.."+# #3485: the heavy lane runs destructive shell scripts against DATABASE_URL —+# apply the shared name floor once here for every script it dispatches.+source tests/heavy/_db_floor.sh+PATTERN="${1:-}"heavy_files=()diff --git a/tests/heavy/_build_legacy_fixtures.sh b/tests/heavy/_build_legacy_fixtures.shindex 95b98b8476..68904493de 100755--- a/tests/heavy/_build_legacy_fixtures.sh+++ b/tests/heavy/_build_legacy_fixtures.sh@@ -40,6 +40,10 @@ if [ -z "${DATABASE_URL:-}" ]; thenexit 2fi+# #3485 name floor (shared): this script DROPs the public schema of whatever+# DATABASE_URL names — refuse non-test-shaped names without an explicit opt-in.+source "$(dirname "$0")/_db_floor.sh"+SQL_FILE="tests/heavy/fixtures/down-mutate-${SHAPE}.sql"if [ ! -f "$SQL_FILE" ]; thenecho "[build_legacy_fixtures] no fixture for shape '$SHAPE' at $SQL_FILE" >&2diff --git a/tests/heavy/_db_floor.sh b/tests/heavy/_db_floor.shnew file mode 100644index 0000000000..d637d462d0--- /dev/null+++ b/tests/heavy/_db_floor.sh@@ -0,0 +1,49 @@+#!/usr/bin/env bash+# #3485 shared shell name floor, mirrored from test/helpers/db-guard.ts.+#+# Heavy-lane scripts run destructive operations (DROP SCHEMA, source-registry+# UPSERTs, initSchema migration replay, parallel syncs) against whatever+# database URL the resolved config names. The bunfig preload guard is+# bun-test-only — shell lanes need their own floor. Source this file AFTER+# confirming DATABASE_URL is set:+#+# source "$(dirname "$0")/_db_floor.sh" # exits 2 unless every set db-url+# # var is test-shaped or allowed+#+# BOTH variables are floored: heavy scripts shell out to the real CLI+# (gbrain doctor / gbrain sync), and src/core/config.ts resolves+# GBRAIN_DATABASE_URL ABOVE DATABASE_URL — flooring only one would let the+# other reach a real brain. Query strings are stripped BEFORE the name is+# extracted: `?host=/tmp/test-sockets` must not smuggle a test-shaped segment+# past the floor (the last path segment of the pre-query URL is the db name).+#+# Refuses unless the database name carries "test" as a word segment+# (gbrain_test) or the operator opts the exact name in via GBRAIN_E2E_ALLOW_DB+# (prefer one-shot inline usage — GBRAIN_E2E_ALLOW_DB=name ./script — over a+# shell-profile export, which would permanently disarm the floor).++_db_floor_check() {+ _db_floor_url="$1"+ _db_floor_var="$2"+ [ -z "$_db_floor_url" ] && return 0+ _db_floor_prequery="${_db_floor_url%%\?*}"+ _db_floor_name="${_db_floor_prequery##*/}"+ if [ -z "$_db_floor_name" ]; then+ echo "[db-floor] REFUSING: $_db_floor_var has no database name" >&2+ exit 2+ fi+ if ! printf '%s' "$_db_floor_name" | grep -qiE '(^|[_-])test([_-]|$)'; then+ if [ "${GBRAIN_E2E_ALLOW_DB:-}" != "$_db_floor_name" ]; then+ echo "[db-floor] REFUSING: $_db_floor_var database \"$_db_floor_name\" does not look like a test database" >&2+ echo " (expected \"test\" as a name segment, e.g. gbrain_test). Heavy-lane scripts run" >&2+ echo " destructive operations against it. If intentional, opt in one-shot:" >&2+ echo " GBRAIN_E2E_ALLOW_DB=$_db_floor_name <command>" >&2+ exit 2+ fi+ fi+}++_db_floor_check "${DATABASE_URL:-}" DATABASE_URL+_db_floor_check "${GBRAIN_DATABASE_URL:-}" GBRAIN_DATABASE_URL+unset -f _db_floor_check 2>/dev/null || true+unset _db_floor_url _db_floor_var _db_floor_prequery _db_floor_name 2>/dev/null || truediff --git a/tests/heavy/frontmatter_scan_wallclock.sh b/tests/heavy/frontmatter_scan_wallclock.shindex 0c42d963cb..ecbdfa539f 100755--- a/tests/heavy/frontmatter_scan_wallclock.sh+++ b/tests/heavy/frontmatter_scan_wallclock.sh@@ -30,6 +30,10 @@set -euo pipefail+# #3485: shared name floor — these scripts mutate whatever DATABASE_URL names+# and are documented for direct invocation, so each sources the floor itself.+source "$(dirname "$0")/_db_floor.sh"+cd "$(dirname "$0")/../.."WALLCLOCK_BUDGET_S="${WALLCLOCK_BUDGET_S:-15}"diff --git a/tests/heavy/pg_upgrade_matrix.sh b/tests/heavy/pg_upgrade_matrix.shindex 837a55dfcd..ccbfa3059c 100755--- a/tests/heavy/pg_upgrade_matrix.sh+++ b/tests/heavy/pg_upgrade_matrix.sh@@ -33,6 +33,10 @@set -euo pipefail+# #3485: shared name floor — these scripts mutate whatever DATABASE_URL names+# and are documented for direct invocation, so each sources the floor itself.+source "$(dirname "$0")/_db_floor.sh"+cd "$(dirname "$0")/../.."if [ -z "${DATABASE_URL:-}" ]; thendiff --git a/tests/heavy/sync_lock_regression.sh b/tests/heavy/sync_lock_regression.shindex f54d767898..ccb3af75b3 100755--- a/tests/heavy/sync_lock_regression.sh+++ b/tests/heavy/sync_lock_regression.sh@@ -17,6 +17,10 @@set -euo pipefail+# #3485: shared name floor — these scripts mutate whatever DATABASE_URL names+# and are documented for direct invocation, so each sources the floor itself.+source "$(dirname "$0")/_db_floor.sh"+cd "$(dirname "$0")/../.."if [ -z "${DATABASE_URL:-}" ]; then