Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(gfs): isolate real-pg cleanup from minikube runtime

Alfredo Lopez9c072c782f1e
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 55d9289fc..6126190d2 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.454",
+ "version": "0.1.455",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.454",
+ "version": "0.1.455",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/control-api/package.json b/control-api/package.json
index b93ab5c7c..1bb4bec0a 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.454",
+ "version": "0.1.455",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/deploy.gfsProvisioning.test.ts b/control-api/test/deploy.gfsProvisioning.test.ts
index ee310442d..a88935255 100644
--- a/control-api/test/deploy.gfsProvisioning.test.ts
+++ b/control-api/test/deploy.gfsProvisioning.test.ts
@@ -136,7 +136,9 @@ describe('deploy/scripts/provision-gfs-db.sh', () => {
'reconcile_credential gfs_controller_reader reader "$READER_SECRET" gfsc-reader false'
)
expect(script).toContain('gfs_dsn_authenticates_as "$1" "$2"')
- expect(probe).toContain('kc -n "$PG_NS" exec -i "$PG_PROBE_DEPLOY" -- node -e')
+ expect(probe).toContain(
+ 'kc -n "$PG_NS" exec -i "$PG_PROBE_DEPLOY" -c "$probe_container" -- node -e'
+ )
expect(probe).toContain('await client.query("SELECT current_user")')
expect(probe).toContain('[ "$actual" = "$expected_role" ]')
expect(probe).toContain('error.code === "28P01" || error.code === "28000"')
diff --git a/deploy/scripts/lib/gfs-dsn-probe.sh b/deploy/scripts/lib/gfs-dsn-probe.sh
index fb0f950b0..cc3238c8a 100755
--- a/deploy/scripts/lib/gfs-dsn-probe.sh
+++ b/deploy/scripts/lib/gfs-dsn-probe.sh
@@ -50,13 +50,18 @@ print(value, end="")
gfs_dsn_authenticates_as() {
local dsn="$1" expected_role="$2" actual rc
+ # Explicitly select the application container. `kubectl exec` can otherwise
+ # resolve a deployment's default container inconsistently while a rollout is
+ # replacing its pod, turning an authentication rejection into an
+ # "unavailable" probe and preventing safe NOLOGIN recovery.
+ local probe_container="${PG_PROBE_CONTAINER:-control-api}"
printf '%s' "$dsn" | gfs_dsn_validate \
"$expected_role" "$PG_HOST" "$PG_PORT" "$PG_DB" || return 1
# Authenticate through the same Service DNS and SCRAM path used by GFSC.
# The connection string stays on stdin; the fixed program emits only the
# authenticated role and intentionally suppresses connection error details.
- actual="$(printf '%s' "$dsn" | kc -n "$PG_NS" exec -i "$PG_PROBE_DEPLOY" -- node -e '
+ actual="$(printf '%s' "$dsn" | kc -n "$PG_NS" exec -i "$PG_PROBE_DEPLOY" -c "$probe_container" -- node -e '
const { Client } = require("pg");
let raw = "";
process.stdin.on("data", chunk => { raw += chunk });
diff --git a/scripts/e2e/gfs-real-pg-minikube-gate.sh b/scripts/e2e/gfs-real-pg-minikube-gate.sh
index 5ca1c7258..0654f525c 100755
--- a/scripts/e2e/gfs-real-pg-minikube-gate.sh
+++ b/scripts/e2e/gfs-real-pg-minikube-gate.sh
@@ -234,6 +234,20 @@ PG_DATABASE="$(secret_value POSTGRES_DB)"
TMP_DIR="$(mktemp -d)"
PORT_FORWARD_PID=''
LOCAL_PORT=''
+restore_gfs_runtime_credentials() {
+ # The reader-role real-Postgres suite exercises the production role names,
+ # which are cluster-global even though its fixture database is temporary.
+ # Restore the branch profile before this gate exits so a failed or interrupted
+ # T1 run cannot leave GFSC in NOLOGIN and poison the following T2 journey.
+ if ! kc -n gfs get secret gfs-controller-db >/dev/null 2>&1; then
+ return 0
+ fi
+ if ! GFS_RESTORE_ACTIVE_NOLOGIN=true CONTEXT="${CONTEXT}" \
+ bash "${PROJECT_DIR}/deploy/scripts/reconcile-gfs-deploy-credentials.sh"; then
+ printf '[gfs-real-pg-minikube] ERROR: failed to restore branch-profile GFS credentials\n' >&2
+ return 1
+ fi
+}
stop_port_forward() {
if [[ -z "${PORT_FORWARD_PID}" ]] || ! kill -0 "${PORT_FORWARD_PID}" >/dev/null 2>&1; then
PORT_FORWARD_PID=''
@@ -252,6 +266,9 @@ stop_port_forward() {
cleanup() {
local status=$?
stop_port_forward
+ if ! restore_gfs_runtime_credentials; then
+ status=1
+ fi
rm -rf "${TMP_DIR}"
exit "${status}"
}
diff --git a/scripts/tests/test-gfs-dsn-probe.sh b/scripts/tests/test-gfs-dsn-probe.sh
index 67c5c989f..8afa60244 100755
--- a/scripts/tests/test-gfs-dsn-probe.sh
+++ b/scripts/tests/test-gfs-dsn-probe.sh
@@ -24,6 +24,9 @@ source "$ROOT/deploy/scripts/lib/gfs-dsn-probe.sh"
grep -q 'error.code === "28P01".*error.code === "28000"' \
"$ROOT/deploy/scripts/lib/gfs-dsn-probe.sh" \
|| { printf 'FAIL: probe does not limit rejection to PostgreSQL authentication SQLSTATEs\n' >&2; exit 1; }
+grep -q 'exec -i "\$PG_PROBE_DEPLOY" -c "\$probe_container" -- node -e' \
+ "$ROOT/deploy/scripts/lib/gfs-dsn-probe.sh" \
+ || { printf 'FAIL: probe does not select the control-api container explicitly\n' >&2; exit 1; }
gfs_dsn_authenticates_as "$DSN" gfs_controller \
|| { printf 'FAIL: authenticated DSN was rejected\n' >&2; exit 1; }
diff --git a/scripts/tests/test-gfs-real-pg-minikube-gate.sh b/scripts/tests/test-gfs-real-pg-minikube-gate.sh
index aa4b0a233..3a1e47640 100755
--- a/scripts/tests/test-gfs-real-pg-minikube-gate.sh
+++ b/scripts/tests/test-gfs-real-pg-minikube-gate.sh
@@ -15,6 +15,9 @@ grep -Fq -- '--reporter=json' "${SCRIPT}"
grep -Fq "gfs*.realPostgres.integration.test.ts" "${SCRIPT}"
grep -Fq "services.rateLimiter.realPostgres.integration.test.ts" "${SCRIPT}"
grep -Fq 'isolated processes' "${SCRIPT}"
+grep -Fq 'restore_gfs_runtime_credentials' "${SCRIPT}"
+grep -Fq 'GFS_RESTORE_ACTIVE_NOLOGIN=true' "${SCRIPT}"
+grep -Fq 'failed to restore branch-profile GFS credentials' "${SCRIPT}"
grep -Fq 'gke_*)' "${SCRIPT}"
grep -Fq '*prod*)' "${SCRIPT}"
grep -Fq 'test-gfs-real-postgres-minikube' "${ROOT_DIR}/Makefile"