fix(api): expose kb_ready and gate E2E/nightly on shared KB

Health reports kb_ready; PI E2E uses layered Load + require-online;
nightly preflights SELECT 1 before product suite.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
weichen
2026-09-17 02:03:07 +00:00
co-authored by Cursor
parent f3ed57c41f
commit e782400736
6 changed files with 66 additions and 30 deletions
+38
View File
@@ -126,6 +126,44 @@ export PI_AGENT_RUNNER_AUTH_TOKEN="${TOKEN}"
export RUNNER_AUTH_TOKEN="${TOKEN}"
export PI_AGENT_MODEL="${MODEL_ID}"
export RUN_PI_E2E=1
export KB_REQUIRE_ONLINE="${KB_REQUIRE_ONLINE:-1}"
# Shared KB preflight (host :5432). Fail closed unless KB_ALLOW_OFFLINE=1.
preflight_shared_kb() {
if [[ "${KB_ALLOW_OFFLINE:-0}" == "1" ]]; then
echo "NOTE: KB offline degradation test (KB_ALLOW_OFFLINE=1)" | tee "${EVIDENCE_DIR}/kb-allow-offline.txt"
return 0
fi
local kb_host="${KB_DB_HOST:-127.0.0.1}"
local kb_port="${KB_DB_PORT:-5432}"
local kb_user="${KB_DB_USER:-regkb}"
local kb_name="${KB_DB_NAME:-regulations}"
local kb_pass="${KB_DB_PASSWORD:-}"
if [[ -z "${kb_pass}" && -f "${ROOT}/.env" ]]; then
kb_pass="$(grep -E '^KB_DB_PASSWORD=' "${ROOT}/.env" | head -1 | cut -d= -f2- | tr -d '"' | tr -d "'")"
fi
if [[ -z "${kb_pass}" ]]; then
echo "KB_DB_PASSWORD missing (root .env or env); cannot preflight shared KB" | tee "${EVIDENCE_DIR}/infra-kb-missing-password.txt"
write_receipt infra_fail infra "${EVIDENCE_DIR}/infra-kb-missing-password.txt"
echo "infrastructure failure: shared KB password missing" >&2
exit 1
fi
if ! command -v psql >/dev/null 2>&1; then
echo "psql not found; skip SQL preflight, rely on go test KB_REQUIRE_ONLINE" | tee "${EVIDENCE_DIR}/kb-preflight-skipped-no-psql.txt"
return 0
fi
if ! PGPASSWORD="${kb_pass}" psql -h "${kb_host}" -p "${kb_port}" -U "${kb_user}" -d "${kb_name}" -c 'SELECT 1' >/dev/null 2>"${EVIDENCE_DIR}/kb-preflight.err"; then
{
echo "shared KB preflight failed host=${kb_host} port=${kb_port} db=${kb_name} user=${kb_user}"
cat "${EVIDENCE_DIR}/kb-preflight.err" 2>/dev/null || true
} | tee "${EVIDENCE_DIR}/infra-kb-down.txt"
write_receipt infra_fail infra "${EVIDENCE_DIR}/infra-kb-down.txt"
echo "infrastructure failure: shared KB unreachable" >&2
exit 1
fi
echo "shared KB preflight OK ${kb_host}:${kb_port}/${kb_name}" | tee "${EVIDENCE_DIR}/kb-preflight-ok.txt"
}
preflight_shared_kb
# Clear env pollution that flakes short/config tests elsewhere.
unset AGENT_TIMEOUT KB_DATABASE_URL KB_EMBEDDING_DIM 2>/dev/null || true