High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(e2e): close scenario-opened tabs after each scenario so tab churn stops evicting live tabs mid-suite (PIN-381)
Luigi Agosti1a28aecfbad1
diff --git a/tests/e2e/helpers/api-http.sh b/tests/e2e/helpers/api-http.shindex 91fd0623..c7526ddb 100644--- a/tests/e2e/helpers/api-http.sh+++ b/tests/e2e/helpers/api-http.sh@@ -294,6 +294,22 @@ get_tab_count() {e2e_curl -s "${E2E_SERVER}/tabs" | jq '.tabs | length'}+_e2e_snapshot_tab_ids() {+ e2e_curl -s --max-time 5 "${E2E_SERVER}/tabs" 2>/dev/null | jq -r '.tabs[].id // empty' 2>/dev/null || true+}++_e2e_close_leaked_tabs() {+ local keep id+ keep=$(e2e_curl -s --max-time 5 "${E2E_SERVER}/tabs" 2>/dev/null | jq -r '.tabs[0].id // empty' 2>/dev/null || true)+ while read -r id; do+ [ -n "$id" ] || continue+ [ "$id" = "$keep" ] && continue+ e2e_curl -s --max-time 5 -X POST "${E2E_SERVER}/close" \+ -H "Content-Type: application/json" \+ -d "{\"tabId\":\"$id\"}" >/dev/null 2>&1 || true+ done < <(_e2e_snapshot_tab_ids)+}+get_tab_id() {echo "$RESULT" | jq -r '.tabId'}diff --git a/tests/e2e/helpers/base.sh b/tests/e2e/helpers/base.shindex 8fe72f16..af4573f1 100644--- a/tests/e2e/helpers/base.sh+++ b/tests/e2e/helpers/base.sh@@ -262,10 +262,21 @@ assert_ref_json_jq() {assert_json_jq "$(_e2e_default_ref_json)" "$expr" "$success_desc" "$fail_desc" "$@"}+SCENARIO_TAB_BASELINE="${SCENARIO_TAB_BASELINE:-}"++record_scenario_tab_baseline() {+ if declare -F _e2e_snapshot_tab_ids >/dev/null 2>&1; then+ SCENARIO_TAB_BASELINE="$(_e2e_snapshot_tab_ids | tr '\n' ' ')"+ fi+}+run_scenario_cleanup() {if declare -F scenario_cleanup >/dev/null 2>&1; thenscenario_cleanupfi+ if declare -F _e2e_close_leaked_tabs >/dev/null 2>&1; then+ _e2e_close_leaked_tabs+ fireturn 0}diff --git a/tests/e2e/run.sh b/tests/e2e/run.shindex 1d573bcd..0edb40ed 100644--- a/tests/e2e/run.sh+++ b/tests/e2e/run.sh@@ -213,9 +213,21 @@ source_filtered_scenario() {# non-zero exit intact.finish_scenario() {run_scenario_cleanup+ assert_scenario_tabs_settled[ "${TESTS_FAILED:-0}" -eq 0 ] || exit 1}+assert_scenario_tabs_settled() {+ declare -F _e2e_snapshot_tab_ids >/dev/null 2>&1 || return 0+ local baseline_count after_count+ baseline_count=$(printf '%s' "${SCENARIO_TAB_BASELINE}" | tr ' ' '\n' | grep -c .)+ after_count=$(_e2e_snapshot_tab_ids | grep -c .)+ if [ "${after_count}" -ne "${baseline_count}" ]; then+ echo -e "${RED} ✗ ${CURRENT_SCENARIO_FILE}: tab count did not return to baseline (start ${baseline_count}, end ${after_count})${NC}"+ fi+ return 0+}+# Each scenario file runs in its own subshell: file-scope variables, functions# and traps die with the file, so no scenario can be reached by state another# one left behind. The subshell cannot write TESTS_FAILED back, so it reports@@ -225,6 +237,7 @@ run_scenario_file() {(CURRENT_SCENARIO_FILE="${script_name%.sh}"TESTS_FAILED=0+ record_scenario_tab_baselinetrap finish_scenario EXITif [ -n "${TEST_FILTER}" ]; thenif ! source_filtered_scenario "${script_path}" "${TEST_FILTER}"; then