Skip to content

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

TypeScript

test(gfs): run real postgres lane on validated minikube

Alfredo Lopez781116b4c365
diff --git a/.github/workflows/ci-public.yml b/.github/workflows/ci-public.yml
index 0d9088665..bbeaf50db 100644
--- a/.github/workflows/ci-public.yml
+++ b/.github/workflows/ci-public.yml
@@ -178,12 +178,13 @@ jobs:
working-directory: control-api
env:
CONTROL_API_REAL_PG_ADMIN_URL: postgresql://[email protected]:15433/postgres
+ CONTROL_API_REAL_PG_REQUIRED: '1'
FORCE_COLOR: '0'
NO_COLOR: '1'
- # The `realPostgres` filter matches all 8 *.realPostgres.integration
- # suites: the DB migration plus the 7 GFS suites (reader role, blob
- # migration, blob reconciler, audit evidence, copy, readiness, structural
- # integrity). The matrix `npm test` skips them for lack of the admin URL.
+ # The `realPostgres` filter matches every control-api
+ # *.realPostgres.integration suite. The ordinary matrix may omit these
+ # suites when no admin DSN is supplied; this job requires the DSN and
+ # therefore fails before test collection if the lane is misconfigured.
run: |
set -euo pipefail
log_file="$(mktemp)"
@@ -200,6 +201,10 @@ jobs:
echo 'real-Postgres control-api lane executed zero passing tests' >&2
exit 1
}
+ if grep -Eq '(Test Files|Tests).*([1-9][0-9]*) skipped' "$normalized_log"; then
+ echo 'real-Postgres control-api lane reported skipped tests' >&2
+ exit 1
+ fi
- name: Install gfs-controller dependencies
working-directory: gfs-controller
@@ -209,6 +214,7 @@ jobs:
working-directory: gfs-controller
env:
CONTROL_API_REAL_PG_ADMIN_URL: postgresql://[email protected]:15433/postgres
+ CONTROL_API_REAL_PG_REQUIRED: '1'
FORCE_COLOR: '0'
NO_COLOR: '1'
# rename-publication concurrency suite — also admin-URL-gated, so the
@@ -229,6 +235,10 @@ jobs:
echo 'real-Postgres gfs-controller lane executed zero passing tests' >&2
exit 1
}
+ if grep -Eq '(Test Files|Tests).*([1-9][0-9]*) skipped' "$normalized_log"; then
+ echo 'real-Postgres gfs-controller lane reported skipped tests' >&2
+ exit 1
+ fi
# ─── control-ui build + test check ───────────────────────────────────────
# control-ui stays out of the SHARED build/test matrix because its tsconfig
@@ -431,6 +441,9 @@ jobs:
- name: Test GFS Upload v2 cross-client geometry contract
run: bash scripts/tests/test-gfs-upload-v2-geometry-contract.sh
+ - name: Test GFS real-Postgres Minikube runner contract
+ run: bash scripts/tests/test-gfs-real-pg-minikube-gate.sh
+
# The NetworkPolicy probe runs on an E2E-only fixture that the default
# (pulled) setup never acquires. This proves the target says so up front
# instead of timing out on ErrImageNeverPull, and that it still builds
diff --git a/Makefile b/Makefile
index 2b4b0e5e5..27003759b 100644
--- a/Makefile
+++ b/Makefile
@@ -420,6 +420,10 @@ minikube-pf-all-bg: ## Refresh background port-forwards for gate automation
minikube-pre-gate-sync: ## Enforce minikube sync before a gate (use GATE=<name>)
@scripts/minikube/pre-gate-sync.sh --gate "$${GATE:-manual}" $(ARGS)
+.PHONY: test-gfs-real-postgres-minikube
+test-gfs-real-postgres-minikube: ## Run GFS T1 real-Postgres suites against a validated branch-owned Minikube profile
+ @CONTEXT="$(MINIKUBE_PROFILE)" bash scripts/e2e/gfs-real-pg-minikube-gate.sh
+
.PHONY: minikube-verify-network-policy
minikube-verify-network-policy: ## Prove NetworkPolicy enforcement in clerum-test/minikube before custom-image gates
@CONTEXT="$(MINIKUBE_PROFILE)" scripts/minikube/verify-network-policy-enforcement.sh
diff --git a/control-api/test/realPostgres.requirement.ts b/control-api/test/realPostgres.requirement.ts
new file mode 100644
index 000000000..ec96dcc66
--- /dev/null
+++ b/control-api/test/realPostgres.requirement.ts
@@ -0,0 +1,11 @@
+/**
+ * Real-Postgres suites are intentionally opt-in for the ordinary unit matrix.
+ * A gate that explicitly requests them must never turn a missing DSN into a
+ * green run with skipped files.
+ */
+if (
+ process.env.CONTROL_API_REAL_PG_REQUIRED === '1' &&
+ !process.env.CONTROL_API_REAL_PG_ADMIN_URL
+) {
+ throw new Error('CONTROL_API_REAL_PG_ADMIN_URL is required when CONTROL_API_REAL_PG_REQUIRED=1')
+}
diff --git a/control-api/vitest.config.ts b/control-api/vitest.config.ts
index e316fcd76..501489f2e 100644
--- a/control-api/vitest.config.ts
+++ b/control-api/vitest.config.ts
@@ -3,6 +3,7 @@ import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
environment: 'node',
+ setupFiles: ['test/realPostgres.requirement.ts'],
// Control API route suites mock shared modules, env-backed config, and
// Supertest apps. Running files in parallel can leak those process-level
// fixtures across workers and produce nondeterministic HTTP parse failures.
diff --git a/gfs-controller/test/realPostgres.requirement.ts b/gfs-controller/test/realPostgres.requirement.ts
new file mode 100644
index 000000000..3f51cd62b
--- /dev/null
+++ b/gfs-controller/test/realPostgres.requirement.ts
@@ -0,0 +1,12 @@
+/**
+ * Real-Postgres suites remain opt-in for the normal unit matrix, but an
+ * explicit T1 gate must fail rather than silently report a skipped suite.
+ */
+if (
+ process.env.CONTROL_API_REAL_PG_REQUIRED === '1' &&
+ !process.env.CONTROL_API_REAL_PG_ADMIN_URL
+) {
+ throw new Error(
+ 'CONTROL_API_REAL_PG_ADMIN_URL is required when CONTROL_API_REAL_PG_REQUIRED=1'
+ )
+}
diff --git a/gfs-controller/vitest.config.ts b/gfs-controller/vitest.config.ts
index 37b473f54..56b64f4a1 100644
--- a/gfs-controller/vitest.config.ts
+++ b/gfs-controller/vitest.config.ts
@@ -2,6 +2,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
+ setupFiles: ["test/realPostgres.requirement.ts"],
include: ["src/**/*.test.ts", "src/**/__tests__/**/*.ts", "test/**/*.test.ts"],
exclude: ["dist/**", "node_modules/**"],
},
diff --git a/scripts/e2e/gfs-real-pg-minikube-gate.sh b/scripts/e2e/gfs-real-pg-minikube-gate.sh
new file mode 100755
index 000000000..91d82ad8b
--- /dev/null
+++ b/scripts/e2e/gfs-real-pg-minikube-gate.sh
@@ -0,0 +1,238 @@
+#!/usr/bin/env bash
+# Run the real-Postgres T1 suites against the control-postgres instance in an
+# explicitly validated, branch-owned Minikube profile.
+#
+# This runner is deliberately separate from CI: CI supplies its own ephemeral
+# Postgres DSN, while this gate obtains a short-lived localhost port-forward to
+# the selected Minikube service. It never discovers or accepts a GKE context.
+set -euo pipefail
+set +x
+
+SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
+PROJECT_DIR="$(cd -- "${SCRIPT_DIR}/../.." && pwd -P)"
+CONTEXT="${CONTEXT:-${MINIKUBE_PROFILE:-}}"
+SYNC_CONFIGMAP="${CLERUM_PRE_GATE_SYNC_CONFIGMAP:-clerum-pre-gate-sync-state}"
+CONTROL_NS="${CONTROL_NS:-control-plane}"
+PG_SERVICE="${PG_SERVICE:-control-postgres}"
+PG_SECRET="${PG_SECRET:-control-postgres}"
+TIMEOUT="${TIMEOUT:-120}"
+PORTS_ENV="${CLERUM_PROFILE_PORTS_ENV:-${HOME}/.cache/clerum/minikube-profiles/${CONTEXT}/ports.env}"
+
+die() {
+ printf '[gfs-real-pg-minikube] ERROR: %s\n' "$*" >&2
+ exit 1
+}
+
+kc() {
+ kubectl --context="${CONTEXT}" "$@"
+}
+
+require_command() {
+ local command_name
+ for command_name in "$@"; do
+ command -v "${command_name}" >/dev/null 2>&1 || die "required command is missing: ${command_name}"
+ done
+}
+
+is_branch_profile() {
+ [[ "${1}" =~ ^clerum-[a-z0-9][a-z0-9-]*-[0-9a-f]{8}$ ]]
+}
+
+reject_unsafe_context() {
+ [[ -n "${CONTEXT}" ]] || die 'CONTEXT or MINIKUBE_PROFILE is required'
+ case "${CONTEXT}" in
+ gke_*) die "refusing non-Minikube or production context: ${CONTEXT}" ;;
+ *prod*) die "refusing non-Minikube or production context: ${CONTEXT}" ;;
+ esac
+ if [[ "${CONTEXT}" != "clerum-test" ]] && ! is_branch_profile "${CONTEXT}"; then
+ die "context is not an allowed local/branch profile: ${CONTEXT}"
+ fi
+}
+
+verify_profile_ownership() {
+ if ! is_branch_profile "${CONTEXT}"; then
+ return 0
+ fi
+ [[ -f "${PORTS_ENV}" ]] || die "branch profile ports.env is missing: ${PORTS_ENV}"
+
+ local profile_name profile_repo profile_dir
+ profile_dir="${PORTS_ENV%/ports.env}"
+ profile_name="$(awk -F= '$1 == "PROFILE" { print substr($0, index($0, "=") + 1); exit }' "${profile_dir}/profile.env" 2>/dev/null || true)"
+ profile_repo="$(awk -F= '$1 == "REPO_DIR" { print substr($0, index($0, "=") + 1); exit }' "${profile_dir}/profile.env" 2>/dev/null || true)"
+ [[ "${profile_name}" == "${CONTEXT}" ]] || die "ports.env/profile marker belongs to '${profile_name:-unknown}', not ${CONTEXT}"
+ [[ -n "${profile_repo}" ]] || die 'profile marker has no REPO_DIR'
+ [[ "$(cd -- "${profile_repo}" 2>/dev/null && pwd -P)" == "${PROJECT_DIR}" ]] || \
+ die "profile marker is owned by another worktree: ${profile_repo}"
+}
+
+verify_clean_and_sync_marker() {
+ local head worktree_id marker_json
+ [[ -z "$(git -C "${PROJECT_DIR}" status --porcelain)" ]] || \
+ die 'worktree is dirty; run pre-gate-sync after committing or cleanly restoring changes'
+ head="$(git -C "${PROJECT_DIR}" rev-parse --verify HEAD)"
+ worktree_id="$(printf '%s' "${PROJECT_DIR}" | shasum | awk '{print $1}')"
+ marker_json="$(kc -n "${CONTROL_NS}" get configmap "${SYNC_CONFIGMAP}" -o json 2>/dev/null)" || \
+ die "validated pre-gate marker is missing: ${CONTROL_NS}/${SYNC_CONFIGMAP}"
+
+ python3 - "${worktree_id}" "${head}" "${marker_json}" <<'PY'
+import json
+import sys
+
+expected_worktree, expected_head, marker_json = sys.argv[1:]
+payload = json.loads(marker_json)
+data = payload.get("data") or {}
+if not data.get("clusterFingerprint"):
+ raise SystemExit("pre-gate marker has no cluster fingerprint")
+if data.get("worktreeId") != expected_worktree:
+ raise SystemExit("pre-gate marker belongs to another worktree")
+if data.get("gitHead") != expected_head:
+ raise SystemExit("pre-gate marker does not match the current HEAD")
+PY
+}
+
+secret_value() {
+ local key="$1" encoded
+ encoded="$(kc -n "${CONTROL_NS}" get secret "${PG_SECRET}" -o "jsonpath={.data.${key}}" 2>/dev/null)" || \
+ die "cannot read ${CONTROL_NS}/${PG_SECRET}.${key}"
+ [[ -n "${encoded}" ]] || die "${CONTROL_NS}/${PG_SECRET}.${key} is empty"
+ printf '%s' "${encoded}" | python3 -c 'import base64,sys; print(base64.b64decode(sys.stdin.read(), validate=True).decode(), end="")'
+}
+
+wait_for_tcp() {
+ local port="$1" deadline=$((SECONDS + TIMEOUT))
+ while (( SECONDS < deadline )); do
+ if python3 - "${port}" <<'PY' >/dev/null 2>&1
+import socket
+import sys
+
+with socket.create_connection(("127.0.0.1", int(sys.argv[1])), timeout=1):
+ pass
+PY
+ then
+ return 0
+ fi
+ sleep 1
+ done
+ return 1
+}
+
+sanitize_file() {
+ local file="$1"
+ [[ -f "${file}" ]] || return 0
+ python3 - "${file}" <<'PY'
+from pathlib import Path
+import re
+import sys
+
+path = Path(sys.argv[1])
+text = path.read_text(errors="replace")
+text = re.sub(r"postgres(?:ql)?://[^\s\"'<>]+", "<minikube-postgres-dsn-redacted>", text)
+path.write_text(text)
+PY
+}
+
+run_suite() {
+ local package="$1" expected_files log_file json_file
+ local passed_files passed_tests pending_files pending_tests success
+ expected_files="$(find "${PROJECT_DIR}/${package}" -name '*realPostgres*.test.ts' ! -name 'realPostgres.requirement.ts' -print | wc -l | tr -d ' ')"
+ [[ "${expected_files}" =~ ^[1-9][0-9]*$ ]] || die "no real-Postgres suites found under ${package}"
+ log_file="${TMP_DIR}/${package//\//_}.log"
+ json_file="${TMP_DIR}/${package//\//_}.json"
+
+ printf '[gfs-real-pg-minikube] running %s real-Postgres suites\n' "${package}"
+ if ! (
+ cd "${PROJECT_DIR}/${package}"
+ CONTROL_API_REAL_PG_ADMIN_URL="${ADMIN_DSN}" \
+ CONTROL_API_REAL_PG_REQUIRED=1 \
+ FORCE_COLOR=0 NO_COLOR=1 \
+ npm test -- --run realPostgres --reporter=json --outputFile="${json_file}"
+ ) >"${log_file}" 2>&1; then
+ sanitize_file "${log_file}"
+ sanitize_file "${json_file}"
+ cat "${log_file}" >&2 || true
+ cat "${json_file}" >&2 || true
+ die "${package} real-Postgres gate failed"
+ fi
+
+ sanitize_file "${log_file}"
+ sanitize_file "${json_file}"
+ [[ -s "${json_file}" ]] || die "${package} real-Postgres reporter produced no JSON result"
+ read -r passed_files passed_tests pending_files pending_tests success < <(python3 - "${json_file}" <<'PY'
+import json
+import sys
+from pathlib import Path
+
+result = json.loads(Path(sys.argv[1]).read_text())
+
+print(
+ result.get("numPassedTestSuites", 0),
+ result.get("numPassedTests", 0),
+ result.get("numPendingTestSuites", 0),
+ result.get("numPendingTests", 0),
+ str(bool(result.get("success"))).lower(),
+)
+PY
+ )
+ [[ "${success}" == 'true' && "${passed_files}" -eq "${expected_files}" ]] || die "${package} real-Postgres reporter did not pass every suite"
+ [[ "${passed_tests}" -gt 0 && "${pending_files}" -eq 0 && "${pending_tests}" -eq 0 ]] || die "${package} real-Postgres lane reported zero tests or skips"
+ printf '[gfs-real-pg-minikube] PASS %s (%s files, %s tests, 0 skipped)\n' \
+ "${package}" "${passed_files}" "${passed_tests}"
+}
+
+require_command git kubectl npm python3 shasum
+reject_unsafe_context
+verify_profile_ownership
+verify_clean_and_sync_marker
+kc -n "${CONTROL_NS}" get service "${PG_SERVICE}" >/dev/null || die "${CONTROL_NS}/${PG_SERVICE} service is missing"
+kc -n "${CONTROL_NS}" rollout status deployment/control-postgres --timeout="${TIMEOUT}s" >/dev/null || \
+ die 'control-postgres is not Ready in the validated profile'
+
+PG_USER="$(secret_value POSTGRES_USER)"
+PG_PASSWORD="$(secret_value POSTGRES_PASSWORD)"
+PG_DATABASE="$(secret_value POSTGRES_DB)"
+[[ -n "${PG_USER}" && -n "${PG_PASSWORD}" && -n "${PG_DATABASE}" ]] || die 'control-postgres secret is incomplete'
+
+TMP_DIR="$(mktemp -d)"
+PORT_FORWARD_PID=''
+cleanup() {
+ local status=$?
+ if [[ -n "${PORT_FORWARD_PID}" ]]; then
+ kill "${PORT_FORWARD_PID}" >/dev/null 2>&1 || true
+ wait "${PORT_FORWARD_PID}" >/dev/null 2>&1 || true
+ fi
+ rm -rf "${TMP_DIR}"
+ exit "${status}"
+}
+trap cleanup EXIT
+
+LOCAL_PORT="$(python3 - <<'PY'
+import socket
+
+sock = socket.socket()
+sock.bind(("127.0.0.1", 0))
+print(sock.getsockname()[1])
+sock.close()
+PY
+)"
+kubectl --context="${CONTEXT}" -n "${CONTROL_NS}" port-forward \
+ --address=127.0.0.1 "svc/${PG_SERVICE}" "${LOCAL_PORT}:5432" \
+ >"${TMP_DIR}/port-forward.log" 2>&1 &
+PORT_FORWARD_PID=$!
+wait_for_tcp "${LOCAL_PORT}" || {
+ cat "${TMP_DIR}/port-forward.log" >&2 || true
+ die 'Minikube PostgreSQL port-forward did not become reachable'
+}
+
+ADMIN_DSN="$(python3 - "${PG_USER}" "${PG_PASSWORD}" "${LOCAL_PORT}" <<'PY'
+from urllib.parse import quote
+import sys
+
+user, password, port = sys.argv[1:]
+print(f"postgresql://{quote(user, safe='')}:{quote(password, safe='')}@127.0.0.1:{port}/postgres", end="")
+PY
+)"
+unset PG_USER PG_PASSWORD PG_DATABASE
+
+run_suite control-api
+run_suite gfs-controller
+printf '[gfs-real-pg-minikube] T1 PASS: real PostgreSQL executed against validated Minikube profile %s\n' "${CONTEXT}"
diff --git a/scripts/tests/test-gfs-real-pg-minikube-gate.sh b/scripts/tests/test-gfs-real-pg-minikube-gate.sh
new file mode 100755
index 000000000..95c42b817
--- /dev/null
+++ b/scripts/tests/test-gfs-real-pg-minikube-gate.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd -P)"
+SCRIPT="${ROOT_DIR}/scripts/e2e/gfs-real-pg-minikube-gate.sh"
+
+bash -n "${SCRIPT}"
+grep -Fq 'CONTROL_API_REAL_PG_REQUIRED=1' "${SCRIPT}"
+grep -Fq 'CONTROL_API_REAL_PG_ADMIN_URL=' "${SCRIPT}"
+grep -Fq 'gitHead' "${SCRIPT}"
+grep -Fq 'worktreeId' "${SCRIPT}"
+grep -Fq 'port-forward' "${SCRIPT}"
+grep -Fq 'pending_files' "${SCRIPT}"
+grep -Fq -- '--reporter=json' "${SCRIPT}"
+grep -Fq 'gke_*)' "${SCRIPT}"
+grep -Fq '*prod*)' "${SCRIPT}"
+grep -Fq 'test-gfs-real-postgres-minikube' "${ROOT_DIR}/Makefile"
+grep -Fq "setupFiles: ['test/realPostgres.requirement.ts']" "${ROOT_DIR}/control-api/vitest.config.ts"
+grep -Fq 'setupFiles: ["test/realPostgres.requirement.ts"]' "${ROOT_DIR}/gfs-controller/vitest.config.ts"
+
+printf 'PASS: Minikube real-Postgres runner is explicit, owned, and fail-loud\n'