Skip to content

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

TypeScript

test(e2e): guard sdk writes and restore preferences

Alfredo Lopezeee49763d92a
diff --git a/Makefile b/Makefile
index 664e38ecc..720b8e7f2 100644
--- a/Makefile
+++ b/Makefile
@@ -773,9 +773,9 @@ test-e2e-wrc-internal-dependency-networkpolicy: ## Run issue #485 WRC internal-d
KUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-wrc-internal-dependency-networkpolicy.sh
.PHONY: test-e2e-plugin-workload-sdk
-test-e2e-plugin-workload-sdk: ## Run Plugin Workload SDK E2E gate (minikube only; set E2E_ADMIN_TOKEN for the full happy path)
+test-e2e-plugin-workload-sdk: ## Run Plugin Workload SDK E2E gate (minikube only; requires E2E_PLUGIN_SDK_WRITE_CONFIRM=1)
@echo "Running Plugin Workload SDK E2E gate..."
- KUBECONTEXT=$(E2E_KUBECONTEXT) bash scripts/e2e/e2e-plugin-workload-sdk.sh
+ KUBECONTEXT="$${KUBECONTEXT:-$${E2E_KUBECONTEXT:-}}" bash scripts/e2e/e2e-plugin-workload-sdk.sh
.PHONY: test-e2e-cron-tab-validation
test-e2e-cron-tab-validation: ## Run recipe cron tab E2E (set E2E_CRON_TAB_FIX_REQUIRED=1 when the fix must be present)
@@ -941,4 +941,3 @@ run-platform-security-gates: ## Execute the revised platform security gate runne
help: ## Show this help
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-24s\033[0m %s\n", $$1, $$2}'
-
diff --git a/scripts/e2e/e2e-plugin-workload-sdk.sh b/scripts/e2e/e2e-plugin-workload-sdk.sh
index c4be4f682..2f61d8ff4 100755
--- a/scripts/e2e/e2e-plugin-workload-sdk.sh
+++ b/scripts/e2e/e2e-plugin-workload-sdk.sh
@@ -16,8 +16,9 @@
# session from the seeded admin on an explicitly selected local minikube profile.
#
# Usage:
-# KUBECONTEXT=clerum-test bash scripts/e2e/e2e-plugin-workload-sdk.sh
-# bash scripts/e2e/e2e-plugin-workload-sdk.sh --cleanup-only
+# E2E_PLUGIN_SDK_WRITE_CONFIRM=1 KUBECONTEXT=clerum-test \
+# bash scripts/e2e/e2e-plugin-workload-sdk.sh
+# E2E_PLUGIN_SDK_WRITE_CONFIRM=1 bash scripts/e2e/e2e-plugin-workload-sdk.sh --cleanup-only
set -euo pipefail
@@ -189,6 +190,11 @@ FIXTURE="${SCRIPT_DIR}/../../tests/e2e/fixtures/plugin-workload-sdk-recipe.yaml"
E2E_CREATED_RECIPE=0
ADMIN_CURL_HTTP_STATUS=""
ADMIN_CURL_BODY=""
+NOTIFICATION_PREF_SNAPSHOT_READY=0
+NOTIFICATION_PREF_SNAPSHOT_EXISTS=0
+NOTIFICATION_PREF_SNAPSHOT_MEDIUM=""
+NOTIFICATION_PREF_SNAPSHOT_FALLBACK=""
+NOTIFICATION_PREF_SNAPSHOT_ACCOUNT=""
# Hard ceiling for the entire gate (default 15m). Override with E2E_GATE_MAX_SECONDS.
E2E_GATE_MAX_SECONDS="${E2E_GATE_MAX_SECONDS:-900}"
E2E_GATE_STARTED_AT=$SECONDS
@@ -198,6 +204,15 @@ E2E_WAIT_CALLER_MARKER="${E2E_WAIT_CALLER_MARKER:-180}"
E2E_WAIT_CALLER_DONE="${E2E_WAIT_CALLER_DONE:-180}"
E2E_WAIT_NOTIFICATION_ROW="${E2E_WAIT_NOTIFICATION_ROW:-60}"
+require_write_confirmation() {
+ if [ "${E2E_PLUGIN_SDK_WRITE_CONFIRM:-}" != "1" ]; then
+ printf '%s\n' \
+ 'Refusing Plugin Workload SDK E2E: this gate creates grants, calls providers, sends a notification, and changes test-user preferences.' \
+ 'Set E2E_PLUGIN_SDK_WRITE_CONFIRM=1 explicitly for the branch-owned local Minikube profile.' >&2
+ return 1
+ fi
+}
+
for provider in "$E2E_WORKFLOW_MODEL_PROVIDER" "$E2E_PROMPT_FALLBACK_PROVIDER"; do
case "$provider" in
openai|claude) ;;
@@ -352,6 +367,10 @@ cleanup_on_exit() {
if [ "${e2e_total:-0}" -gt 0 ] && [ "${E2E_SUPPRESS_RESULTS:-0}" != "1" ]; then
print_results || true
fi
+ if ! restore_notification_preferences && [ "$status" -eq 0 ]; then
+ fail "notification preference cleanup could not restore the seeded user state"
+ status=1
+ fi
if [ "${E2E_KEEP_RESOURCES:-0}" = "1" ]; then exit "$status"; fi
if [ "$E2E_CREATED_RECIPE" != "1" ]; then exit "$status"; fi
if ! cleanup_sdk_recipe && [ "$status" -eq 0 ]; then
@@ -362,10 +381,13 @@ cleanup_on_exit() {
}
if [ "${1:-}" = "--cleanup-only" ]; then
+ require_write_confirmation || exit 2
cleanup_sdk_recipe
exit $?
fi
+require_write_confirmation || exit 2
+
trap cleanup_on_exit EXIT
# ─── control-api admin helpers (exec curl inside the control-api pod) ─────
@@ -522,6 +544,46 @@ psql_query() {
-c "$sql" 2>/dev/null
}
+snapshot_notification_preferences() {
+ local row
+ if ! row="$(psql_query "SELECT CASE WHEN preferred_medium IS NULL THEN '<NULL>' ELSE preferred_medium END || '|' || channel_fallback_enabled::text || '|' || CASE WHEN preferred_account_id IS NULL THEN '<NULL>' ELSE preferred_account_id::text END FROM user_notification_preferences WHERE user_id='${USER_REF}'::uuid;")"; then
+ return 1
+ fi
+ if [ -z "$row" ]; then
+ NOTIFICATION_PREF_SNAPSHOT_EXISTS=0
+ NOTIFICATION_PREF_SNAPSHOT_READY=1
+ return 0
+ fi
+ IFS='|' read -r NOTIFICATION_PREF_SNAPSHOT_MEDIUM \
+ NOTIFICATION_PREF_SNAPSHOT_FALLBACK \
+ NOTIFICATION_PREF_SNAPSHOT_ACCOUNT <<< "$row"
+ NOTIFICATION_PREF_SNAPSHOT_EXISTS=1
+ NOTIFICATION_PREF_SNAPSHOT_READY=1
+}
+
+restore_notification_preferences() {
+ if [ "${NOTIFICATION_PREF_SNAPSHOT_READY:-0}" != "1" ]; then
+ return 0
+ fi
+ if [ "${NOTIFICATION_PREF_SNAPSHOT_EXISTS:-0}" != "1" ]; then
+ psql_query "DELETE FROM user_notification_preferences WHERE user_id='${USER_REF}'::uuid;" >/dev/null 2>&1
+ return $?
+ fi
+
+ local medium_sql account_sql
+ if [ "$NOTIFICATION_PREF_SNAPSHOT_MEDIUM" = '<NULL>' ]; then
+ medium_sql='NULL'
+ else
+ medium_sql="'${NOTIFICATION_PREF_SNAPSHOT_MEDIUM}'"
+ fi
+ if [ "$NOTIFICATION_PREF_SNAPSHOT_ACCOUNT" = '<NULL>' ]; then
+ account_sql='NULL'
+ else
+ account_sql="'${NOTIFICATION_PREF_SNAPSHOT_ACCOUNT}'::uuid"
+ fi
+ psql_query "INSERT INTO user_notification_preferences (user_id,preferred_medium,channel_fallback_enabled,preferred_account_id) VALUES ('${USER_REF}'::uuid,${medium_sql},${NOTIFICATION_PREF_SNAPSHOT_FALLBACK},${account_sql}) ON CONFLICT (user_id) DO UPDATE SET preferred_medium=EXCLUDED.preferred_medium,channel_fallback_enabled=EXCLUDED.channel_fallback_enabled,preferred_account_id=EXCLUDED.preferred_account_id,updated_at=NOW();" >/dev/null 2>&1
+}
+
is_psql_true() {
case "$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" in
t | true) return 0 ;;
@@ -1084,6 +1146,12 @@ if [ -z "$desktop_session_token" ]; then
fi
ok "obtained desktop session token for notification-preferences checks"
+if ! snapshot_notification_preferences; then
+ fail "could not snapshot notification preferences for ${USER_REF}"
+ exit 1
+fi
+ok "snapshotted notification preferences before the contract PUT checks"
+
session_curl PUT "/external/me/notification-preferences" "$desktop_session_token" '{"preferredMedium":"telegram"}' >/dev/null || true
if [ "$ADMIN_CURL_HTTP_STATUS" = "400" ] &&
printf '%s' "$ADMIN_CURL_BODY" | grep -q 'invalid_channel_fallback_enabled'; then