High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
test(e2e): pin the tab-baseline recorder's success flag and id parsing, and state the true reason a failed snapshot skips cleanup
Luigi Agosti483b55b814b7
diff --git a/tests/e2e/helpers/api-http.sh b/tests/e2e/helpers/api-http.shindex 97984009..f1b68f1b 100644--- a/tests/e2e/helpers/api-http.sh+++ b/tests/e2e/helpers/api-http.sh@@ -315,10 +315,9 @@ _e2e_record_tab_baseline() {_e2e_close_leaked_tabs() {local id- # Skip only when the start-of-scenario snapshot FAILED: "close everything not in- # an unknown set" could close the only tab and tear the browser down. A- # successful empty baseline means the scenario began with no tabs, so every tab- # present now is one it opened and must be closed.+ # Skip only when the start-of-scenario snapshot FAILED: an unknown baseline cannot+ # say which tabs the scenario opened. A successful empty baseline means the+ # scenario began with no tabs, so every tab present now is one it opened.[ "${SCENARIO_TAB_BASELINE_OK:-0}" = "1" ] || return 0while read -r id; do[ -n "$id" ] || continuediff --git a/tests/e2e/tab_cleanup_test.go b/tests/e2e/tab_cleanup_test.goindex 29f4441e..fb6b3993 100644--- a/tests/e2e/tab_cleanup_test.go+++ b/tests/e2e/tab_cleanup_test.go@@ -86,10 +86,52 @@ func TestCloseLeakedTabsClosesOnlyNonBaselineTabs(t *testing.T) {}})- t.Run("a failed start snapshot skips cleanup so it cannot close the only tab", func(t *testing.T) {+ t.Run("a failed start snapshot skips cleanup because an unknown baseline cannot say which tabs the scenario opened", func(t *testing.T) {got := runTabCleanup(t, "", "0", "T1")if len(got) != 0 {t.Fatalf("closed %v, want none (a failed baseline snapshot must skip cleanup)", got)}})}++const tabBaselineHarness = `+set -uo pipefail+source helpers/base.sh >/dev/null 2>&1+source helpers/api-http.sh >/dev/null 2>&1+e2e_curl() {+ [ "${STUB_CURL_FAILS:-0}" = "1" ] && return 7+ printf '%s\n%s' "${STUB_BODY:-}" "${STUB_STATUS:-}"+}+_e2e_record_tab_baseline+printf 'OK=%s BASELINE=[%s]' "${SCENARIO_TAB_BASELINE_OK}" "${SCENARIO_TAB_BASELINE% }"+`++func TestRecordTabBaselineSeparatesAnEmptySnapshotFromAFailedOne(t *testing.T) {+ if runtime.GOOS == "windows" {+ t.Skip("the helper under test is a bash function")+ }+ if _, err := exec.LookPath("jq"); err != nil {+ t.Skip("the helper parses tab ids with jq")+ }+ for _, tc := range []struct {+ name, body, status, fails, want string+ }{+ {"a 200 with tabs records them and marks the snapshot good", `{"tabs":[{"id":"T0"},{"id":"T1"}]}`, "200", "0", "OK=1 BASELINE=[T0 T1]"},+ {"a 200 with no tabs is a good, empty baseline", `{"tabs":[]}`, "200", "0", "OK=1 BASELINE=[]"},+ {"a non-200 answer is a failed snapshot", `{"error":"no instance"}`, "503", "0", "OK=0 BASELINE=[]"},+ {"a curl failure is a failed snapshot", "", "", "1", "OK=0 BASELINE=[]"},+ } {+ t.Run(tc.name, func(t *testing.T) {+ cmd := exec.Command("bash", "-c", tabBaselineHarness)+ cmd.Dir = "."+ cmd.Env = append(os.Environ(), "STUB_BODY="+tc.body, "STUB_STATUS="+tc.status, "STUB_CURL_FAILS="+tc.fails)+ raw, err := cmd.CombinedOutput()+ if err != nil {+ t.Fatalf("harness failed: %v\n%s", err, raw)+ }+ if got := strings.TrimSpace(string(raw)); got != tc.want {+ t.Fatalf("got %q, want %q", got, tc.want)+ }+ })+ }+}