Skip to content

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

TypeScript

fix: restore T2 port-forward conflict detection

Alfredo Lopezf3e704e82888
diff --git a/scripts/minikube/t2-common.sh b/scripts/minikube/t2-common.sh
index 1b766d737..543ab8a41 100755
--- a/scripts/minikube/t2-common.sh
+++ b/scripts/minikube/t2-common.sh
@@ -513,7 +513,8 @@ t2_process_check() {
safe_profile="$(printf '%s' "$T2_PROFILE" | tr -c 'A-Za-z0-9_.-' '_')"
# Only real kubectl port-forward processes. A wrapper whose argv merely
# mentions those words is not a port-forward.
- while IFS= read -r uid pid ppid rest; do
+ # Default IFS so UID/PID/PPID split. `IFS=` left pid empty and skipped every line.
+ while read -r uid pid ppid rest; do
[ -n "$pid" ] || continue
command_line="$uid $pid $ppid $rest"
[[ "$command_line" == *"$T2_PROFILE"* || "$command_line" == *"$T2_CONTEXT"* ]] || continue
@@ -542,7 +543,7 @@ t2_process_check() {
T2_NEXT_COMMAND='stop the unrelated profile port-forward or select the owner worktree; do not share it'
t2_fail PORT_FORWARD_CONFLICT 'a port-forward for this profile is owned by another process'
fi
- done < <(ps -ef 2>/dev/null | awk '/(^|\/)kubectl([[:space:]]|$)/ && /[[:space:]]port-forward([[:space:]]|$)/ {print}' || true)
+ done < <(ps -ef 2>/dev/null | awk '/[[:space:]][0-9]+:[0-9]+(\.[0-9]+)?[[:space:]]+([^[:space:]]*\/)?kubectl[[:space:]]+port-forward([[:space:]]|$)/ {print}' || true)
}
t2_classify_transition() {
diff --git a/scripts/tests/test-minikube-t2-contract.sh b/scripts/tests/test-minikube-t2-contract.sh
index 9eac0ae2d..4a89f4ac8 100755
--- a/scripts/tests/test-minikube-t2-contract.sh
+++ b/scripts/tests/test-minikube-t2-contract.sh
@@ -27,6 +27,11 @@ for code in $required_codes; do
done
grep -Fq 'kubectl --context=' "$COMMON"
+if grep -Eq 'while IFS= read -r uid pid ppid rest' "$COMMON"; then
+ echo 'FAIL: t2_process_check IFS= prevents UID/PID split' >&2
+ exit 1
+fi
+grep -Fq 'while read -r uid pid ppid rest' "$COMMON"
grep -Fq 'CONTROL_API_REAL_PG_CONTEXT' "$T1"
grep -Fq 'CONTROL_API_REAL_PG_ADMIN_URL=' "$T1"
grep -Fq 'CONTROL_API_REAL_PG_REQUIRED=1' "$T1"
diff --git a/scripts/tests/test-minikube-t2-scenarios.sh b/scripts/tests/test-minikube-t2-scenarios.sh
index 22eb3ae98..3c223ccf2 100755
--- a/scripts/tests/test-minikube-t2-scenarios.sh
+++ b/scripts/tests/test-minikube-t2-scenarios.sh
@@ -254,6 +254,19 @@ grep -Fq 'ISOLATED_DSN' "$ROOT/scripts/e2e/minikube-real-postgres.sh"
grep -Fq 'T2_LOCK_ROOT' "$COMMON"
grep -Fq 'trap t2_lock_release EXIT INT TERM' "$COMMON"
grep -Fq 'PORT_FORWARD_CONFLICT' "$COMMON"
+grep -Fq 'while read -r uid pid ppid rest' "$COMMON" || fail 't2_process_check must split ps -ef fields'
+grep -Fq 'IFS= read -r uid pid ppid rest' "$COMMON" && fail 'IFS= read disables PID split and silences PORT_FORWARD_CONFLICT'
+grep -Fq '([^[:space:]]*\/)?kubectl[[:space:]]+port-forward' "$COMMON" || fail 't2_process_check awk must match argv0 kubectl, not a wrapper mention'
+bare_pf='user 12345 1 0 10:00 ttys000 0:00 kubectl port-forward --context=clerum-feat-scenario svc/x 8080:80'
+path_pf='user 124 1 0 10:00 ttys000 0:00 /usr/local/bin/kubectl port-forward --context=clerum-feat-scenario svc/y 9090:80'
+wrapper_pf='user 125 1 0 10:00 ttys000 0:00 bash -c echo kubectl port-forward'
+awk_pf='/[[:space:]][0-9]+:[0-9]+(\.[0-9]+)?[[:space:]]+([^[:space:]]*\/)?kubectl[[:space:]]+port-forward([[:space:]]|$)/ {print}'
+printf '%s\n' "$bare_pf" "$path_pf" "$wrapper_pf" | awk "$awk_pf" >"$tmp/pf-awk.out"
+grep -Fq 'kubectl port-forward --context=clerum-feat-scenario svc/x' "$tmp/pf-awk.out" || fail 'awk missed a bare kubectl port-forward'
+grep -Fq '/usr/local/bin/kubectl port-forward' "$tmp/pf-awk.out" || fail 'awk missed a path kubectl port-forward'
+grep -Fq 'bash -c echo kubectl port-forward' "$tmp/pf-awk.out" && fail 'awk matched a wrapper that only mentions kubectl'
+read -r uid pid ppid rest <<<"$bare_pf"
+[ "$pid" = 12345 ] || fail "ps field split left pid='$pid' instead of 12345"
grep -Fq 'REUSE_DB=true' "$ROOT/scripts/minikube/t2.sh"
grep -Fq 'CONTROL_DB_RESET_PVC_UID' "$ROOT/scripts/minikube/t2.sh"