Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix(e2e): close only non-baseline tabs on scenario cleanup and settle by tab ids (PIN-381)

Luigi Agosti83060cdcc115
diff --git a/tests/e2e/helpers/api-http.sh b/tests/e2e/helpers/api-http.sh
index c7526ddb..3f7b97cb 100644
--- a/tests/e2e/helpers/api-http.sh
+++ b/tests/e2e/helpers/api-http.sh
@@ -299,11 +299,16 @@ _e2e_snapshot_tab_ids() {
}
_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)
+ local id
+ # An empty baseline means the start-of-scenario GET /tabs failed or the instance
+ # was gone; "close everything not in an empty set" would close the only tab and
+ # tear down the browser, so skip and let the count check report the drift.
+ [ -n "${SCENARIO_TAB_BASELINE// /}" ] || return 0
while read -r id; do
[ -n "$id" ] || continue
- [ "$id" = "$keep" ] && continue
+ case " ${SCENARIO_TAB_BASELINE} " in
+ *" ${id} "*) continue ;;
+ esac
e2e_curl -s --max-time 5 -X POST "${E2E_SERVER}/close" \
-H "Content-Type: application/json" \
-d "{\"tabId\":\"$id\"}" >/dev/null 2>&1 || true
diff --git a/tests/e2e/run.sh b/tests/e2e/run.sh
index 0edb40ed..99521886 100644
--- a/tests/e2e/run.sh
+++ b/tests/e2e/run.sh
@@ -219,11 +219,14 @@ finish_scenario() {
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}"
+ local baseline_ids after_ids
+ baseline_ids=$(printf '%s' "${SCENARIO_TAB_BASELINE}" | tr ' ' '\n' | sed '/^$/d' | sort)
+ after_ids=$(_e2e_snapshot_tab_ids | sed '/^$/d' | sort)
+ if [ "${baseline_ids}" != "${after_ids}" ]; then
+ local baseline_count after_count
+ baseline_count=$(printf '%s\n' "${baseline_ids}" | grep -c .)
+ after_count=$(printf '%s\n' "${after_ids}" | grep -c .)
+ echo -e "${YELLOW} ⚠ ${CURRENT_SCENARIO_FILE}: tabs did not return to baseline (start ${baseline_count}, end ${after_count})${NC}"
fi
return 0
}