Skip to content

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

TypeScript

test(branch-profile): replace the start_pf text grep with a pf behavior scenario

Alfredo Lopez7853b878aa50
diff --git a/scripts/tests/test-branch-profile-lifecycle.sh b/scripts/tests/test-branch-profile-lifecycle.sh
index df56b7340..bae71a86b 100755
--- a/scripts/tests/test-branch-profile-lifecycle.sh
+++ b/scripts/tests/test-branch-profile-lifecycle.sh
@@ -634,6 +634,28 @@ assert_file "${pids_dir}/control-ui.pid" 'stop-pf keeps a live other-worktree re
assert_alive "${FOREIGN_PID}" 'stop-pf never signals the process behind another worktree record'
rm -f "${pids_dir}/control-ui.pid"
+# pf must not start a forward over a record it could not stop: start_pf runs
+# under `|| failed++`, where errexit is suspended, so a failed stop_own_pf has
+# to return explicitly or the control-ui forward is launched anyway.
+reset_state
+write_control_ui_record "$(dead_pid)" 'Mon Jan 1 00:00:00 2024' "${other_worktree}"
+bp pf-over-foreign-record pf
+assert_rc 1 'pf with another worktree control-ui record'
+assert_output_has 'belongs to a different profile, context, worktree, service, or port binding' \
+ 'pf ran the ownership check on the other-worktree control-ui record'
+assert_output_has '1 port-forward(s) failed to start' 'pf counts the control-ui forward it refused to start'
+# Witness: the other required forwards were launched in the same run.
+assert_log_count 'port-forward --address=127.0.0.1' 3 'pf starts every other present service'
+assert_log_count 'port-forward --address=127.0.0.1 svc/control-ui' 0 \
+ 'pf must not launch a control-ui forward over a record it could not stop'
+pf_owner_read_record "${pids_dir}/control-ui.pid" || fail 'the other-worktree control-ui record is unreadable'
+[[ "${PF_OWNER_RECORD_WORKTREE}" == "${other_worktree}" ]] ||
+ fail "pf replaced the other-worktree control-ui record (worktree=${PF_OWNER_RECORD_WORKTREE})"
+ok
+rm -f "${pids_dir}/control-ui.pid"
+bp pf-over-foreign-record-cleanup stop-pf
+assert_rc 0 'stop-pf clears the forwards pf started next to the foreign record'
+
reset_state
start_foreign_process
write_control_ui_record "${FOREIGN_PID}" "$(pf_owner_process_start "${FOREIGN_PID}")" "${repo}"
diff --git a/scripts/tests/test-minikube-t2-scenarios.sh b/scripts/tests/test-minikube-t2-scenarios.sh
index 10cbc7353..82181bda4 100755
--- a/scripts/tests/test-minikube-t2-scenarios.sh
+++ b/scripts/tests/test-minikube-t2-scenarios.sh
@@ -549,14 +549,8 @@ grep -Fq 'CONTROL_DB_RESET_PVC_UID' "$ROOT/scripts/minikube/t2.sh"
# branch-profile.sh lifecycle (preflight, start, status, pf, health, pf-health,
# stop-pf, stop, delete, prepare-shims) is exercised end to end against a
# fixture repository with PATH stubs for kubectl, minikube, helm, docker and
-# curl; it asserts exit codes, the stub call log and pidfile state.
+# curl; it asserts exit codes, the stub call log and pidfile state, including
+# that pf never launches a forward over a record start_pf could not stop.
bash "$ROOT/scripts/tests/test-branch-profile-lifecycle.sh"
-# The one path the stubs do not reach: a failed stop of an existing record
-# inside start_pf. start_pf runs under `|| failed++`, where errexit is
-# suspended, so it must return explicitly.
-BRANCH_PROFILE="$ROOT/scripts/minikube-profiles/branch-profile.sh"
-start_pf_body="$(awk '$0 == "start_pf() {" { on = 1; next } on && $0 == "}" { exit } on { print }' "$BRANCH_PROFILE")"
-[[ -n "$start_pf_body" ]] || fail 'branch-profile.sh function start_pf not found or empty'
-[[ "$start_pf_body" == *'stop_own_pf'*'|| return 1'* ]] || fail 'start_pf must return explicitly on a failed stop because errexit is suspended under || failed++'
printf 'PASS: local Minikube T0/T1/T2 scenario checks\n'