Skip to content

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

TypeScript

fix(branch-profile): stop every verified port-forward when one record is invalid

Alfredo Lopezf68591995e7b
diff --git a/scripts/minikube-profiles/branch-profile.sh b/scripts/minikube-profiles/branch-profile.sh
index 51205f1fa..b502df10d 100755
--- a/scripts/minikube-profiles/branch-profile.sh
+++ b/scripts/minikube-profiles/branch-profile.sh
@@ -1158,14 +1158,10 @@ cmd_stop_pf() {
return 0
fi
local pidfile name
- # Validate the complete filename set before stopping anything. An unknown
- # record must not cause a partially applied cleanup.
- for pidfile in "${pidfiles[@]}"; do
- name="$(basename "${pidfile}" .pid)"
- resolve_stop_pf_binding "${name}" "${pidfile}" || return 1
- done
- # Attempt every record, so one record that cannot be verified does not leave
- # the verified ones running; the kept records are listed and fail the call.
+ # Attempt every record, so one record that cannot be verified (an unknown
+ # name, an unreadable MCP binding, or a record stop_own_pf cannot prove is
+ # this worktree's) does not leave the verified ones running; the kept
+ # records are listed and fail the call.
local -a kept=()
for pidfile in "${pidfiles[@]}"; do
name="$(basename "${pidfile}" .pid)"
diff --git a/scripts/tests/test-branch-profile-lifecycle.sh b/scripts/tests/test-branch-profile-lifecycle.sh
index 3c7c6dc94..d885e243e 100755
--- a/scripts/tests/test-branch-profile-lifecycle.sh
+++ b/scripts/tests/test-branch-profile-lifecycle.sh
@@ -533,6 +533,62 @@ bp delete-clean delete "CONFIRM_DELETE=${profile}"
assert_rc 0 'delete with verified records'
assert_log_has "minikube -p ${profile} delete pidfiles=0" 'delete clears every record before minikube delete'
+# === stop-pf attempts every record ============================================
+# record_pf_pids <name...>: PF_PIDS gets the recorded PID of each named forward.
+record_pf_pids() {
+ local name
+ PF_PIDS=()
+ for name in "$@"; do
+ pf_owner_read_record "${pids_dir}/${name}.pid" || fail "${name} record is unreadable"
+ PF_PIDS+=("${PF_OWNER_RECORD_PID}")
+ done
+ ok
+}
+
+# An unknown pidfile name is kept and reported, and does not stop the verified
+# records from being stopped before minikube stop runs.
+reset_state
+bp stop-stray-pf pf
+assert_rc 0 'pf before a stop with a stray record'
+record_pf_pids control-ui control-api external-rest-api rpc-proxy
+printf '12345\n' >"${pids_dir}/stray.pid"
+bp stop-stray stop
+assert_rc_nonzero 'stop with a stray record among verified ones'
+# pidfiles=1: only the stray record was left when minikube stop ran.
+assert_log_has "minikube -p ${profile} stop pidfiles=1" 'stop cleared the verified records before minikube stop'
+assert_output_has 'stopped or cleared verified rpc-proxy record' 'stop reached the verified records'
+for name in control-ui control-api external-rest-api rpc-proxy; do
+ assert_no_file "${pids_dir}/${name}.pid" "stop removes the verified ${name} record next to a stray one"
+done
+for pid in "${PF_PIDS[@]}"; do
+ assert_dead "${pid}" 'stop terminates every verified forward next to a stray record'
+done
+assert_file "${pids_dir}/stray.pid" 'stop keeps the stray record'
+assert_output_has " ${pids_dir}/stray.pid" 'stop lists the kept stray record'
+rm -f "${pids_dir}/stray.pid"
+
+# The first record in glob order cannot be verified; every later verified
+# record is still stopped and removed.
+reset_state
+bp stop-pf-first-unverified-pf pf
+assert_rc 0 'pf before a stop-pf whose first record is unverifiable'
+record_pf_pids control-api
+orphaned_control_api_pid="${PF_PIDS[0]}"
+record_pf_pids control-ui external-rest-api rpc-proxy
+printf '12345\n' >"${pids_dir}/control-api.pid"
+bp stop-pf-first-unverified stop-pf
+assert_rc 1 'stop-pf whose first record is unverifiable'
+for name in control-ui external-rest-api rpc-proxy; do
+ assert_no_file "${pids_dir}/${name}.pid" "stop-pf removes ${name} after an unverifiable first record"
+done
+for pid in "${PF_PIDS[@]}"; do
+ assert_dead "${pid}" 'stop-pf terminates the verified forwards after an unverifiable first record'
+done
+assert_file "${pids_dir}/control-api.pid" 'stop-pf keeps the unverifiable first record'
+assert_output_has " ${pids_dir}/control-api.pid" 'stop-pf lists the kept first record'
+kill -KILL "${orphaned_control_api_pid}" 2>/dev/null || true
+rm -f "${pids_dir}/control-api.pid"
+
# === stop-pf keeps records it cannot prove are stale ==========================
reset_state
write_control_ui_record "$(dead_pid)" 'Mon Jan 1 00:00:00 2024' "${other_worktree}"