High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat(e2e): run each scenario file in its own subshell so no scenario inherits another's state
Luigi Agostid8bf0e2280d4
diff --git a/TESTING.md b/TESTING.mdindex dfceeb26..049341b4 100644--- a/TESTING.md+++ b/TESTING.md@@ -214,6 +214,32 @@ start_test "tab focus"end_test```+### Scenario Files Are Isolated++Each scenario file is sourced into its own subshell, so its variables, functions+and traps die with the file. A scenario must not rely on state another scenario+left behind — not a variable, not a helper function, not an open tab, and not+the value of `E2E_SERVER`. Anything two scenarios both need belongs in+`tests/e2e/helpers/`, and anything a scenario sets up it must be able to set up+itself.++Failure accounting crosses the subshell boundary through exit status: a scenario+that ends with any failed test exits non-zero and the executor fails the suite.+The `E2E_RESULT` lines the Go runner parses are unaffected — they are printed,+not accumulated in a variable.++To clean up after a scenario, define `scenario_cleanup`; the executor calls it+when the file finishes, including when the file exits early:++```bash+scenario_cleanup() {+ rm -f "$AUTH_COOKIE_FILE"+}+```++Do not install `trap ... EXIT` in a scenario — bash keeps exactly one EXIT trap,+so a second `trap` silently replaces the first.+### Assertions Must Be Able to FailEvery branch of a scenario ends in `pass_assert`, `fail_assert`, or a named skip@@ -244,9 +270,21 @@ firunning, so it reports a readiness failure to its caller instead of failing atest that has not started.-To drive a second server in the stack (a provider instance, the bridge), wrap-the call in `pt_on <base_url> <token> <pt_command...>`; it retargets `E2E_SERVER`-and the token together and restores both afterwards.+### Targeting Another Server++Never assign `E2E_SERVER` directly. `with_server <base_url> <command...>` points+it at another server in the stack for the duration of one command and restores+the previous value whatever the command returns, passing the command's exit+status back:++```bash+with_server "$E2E_SECURE_SERVER" secure_only_checks+with_server "http://127.0.0.1:1" pt health+```++`pt_on <base_url> <token> <command...>` is the same thing when the second server+also has its own token — it retargets `E2E_SERVER` and `E2E_SERVER_TOKEN`+together and restores both.## Coveragediff --git a/tests/e2e/helpers/base.sh b/tests/e2e/helpers/base.shindex d46fa487..8fe72f16 100644--- a/tests/e2e/helpers/base.sh+++ b/tests/e2e/helpers/base.sh@@ -122,10 +122,7 @@ wait_until() {done}-# pt_on runs a pt_* call against another PinchTab in the stack — a second-# provider instance, the bridge — and restores the caller's target afterwards.-# The base URL and token move together: a second server usually has its own.-pt_on() {+_e2e_against() {local base_url="$1" token="$2"shift 2local prev_url="$E2E_SERVER" prev_token="${E2E_SERVER_TOKEN:-}"@@ -138,6 +135,18 @@ pt_on() {return $rc}+with_server() {+ local base_url="$1"+ shift+ _e2e_against "$base_url" "${E2E_SERVER_TOKEN:-}" "$@"+}++pt_on() {+ local base_url="$1" token="$2"+ shift 2+ _e2e_against "$base_url" "$token" "$@"+}+start_test() {ASSERTIONS_PASSED=0ASSERTIONS_FAILED=0@@ -253,8 +262,15 @@ assert_ref_json_jq() {assert_json_jq "$(_e2e_default_ref_json)" "$expr" "$success_desc" "$fail_desc" "$@"}+run_scenario_cleanup() {+ if declare -F scenario_cleanup >/dev/null 2>&1; then+ scenario_cleanup+ fi+ return 0+}+finish_suite() {- if [ "$TESTS_FAILED" -gt 0 ]; then+ if [ "${1:-$TESTS_FAILED}" -gt 0 ]; thenexit 1fi}diff --git a/tests/e2e/helpers/cli.sh b/tests/e2e/helpers/cli.shindex 6582c01c..e22e6867 100644--- a/tests/e2e/helpers/cli.sh+++ b/tests/e2e/helpers/cli.sh@@ -138,6 +138,19 @@ assert_file_exists() {fi}+config_setup() {+ TMPDIR=$(mktemp -d)+ CFG="$TMPDIR/config.json"+}++config_cleanup() {+ rm -rf "$TMPDIR"+}++config_init() {+ PINCHTAB_CONFIG="$CFG" HOME="$TMPDIR" pt_ok config init+}+config_version_of() {local path="$1"safe_jq -r '.configVersion // "none"' "$path"diff --git a/tests/e2e/run.sh b/tests/e2e/run.shindex a99f2b23..21bb5c90 100644--- a/tests/e2e/run.sh+++ b/tests/e2e/run.sh@@ -152,9 +152,6 @@ echo "Waiting for configured targets..."wait_for_ready_targetsecho ""-# When E2E_TEST_FILTER is set, source only scenario preamble + matching-# start_test...end_test blocks. Lets a single test run end-to-end with the-# scenario's setup intact, no per-helper guards needed.TEST_FILTER="${E2E_TEST_FILTER:-}"source_filtered_scenario() {@@ -208,7 +205,30 @@ source_filtered_scenario() {return 0}-# Run scenarios+# 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+# failure through its exit status instead.+run_scenario_file() {+ local script_path="$1" script_name="$2"+ (+ CURRENT_SCENARIO_FILE="${script_name%.sh}"+ TESTS_FAILED=0+ trap run_scenario_cleanup EXIT+ if [ -n "${TEST_FILTER}" ]; then+ if ! source_filtered_scenario "${script_path}" "${TEST_FILTER}"; then+ echo -e "${MUTED} no matching test in ${script_name}${NC}"+ fi+ else+ # shellcheck disable=SC1090+ source "${script_path}"+ fi+ [ "${TESTS_FAILED}" -eq 0 ]+ )+}++SUITE_FAILED=0+for script_name in "${SCENARIO_GROUPS[@]}"; doscript_path="${GROUP_DIR}/${script_name}"if [ ! -f "${script_path}" ]; then@@ -218,16 +238,9 @@ for script_name in "${SCENARIO_GROUPS[@]}"; doecho -e "${YELLOW}Running: ${script_name}${NC}"echo ""- CURRENT_SCENARIO_FILE="${script_name%.sh}"- if [ -n "${TEST_FILTER}" ]; then- if ! source_filtered_scenario "${script_path}" "${TEST_FILTER}"; then- echo -e "${MUTED} no matching test in ${script_name}${NC}"- fi- else- source "${script_path}"- fi+ run_scenario_file "${script_path}" "${script_name}" || SUITE_FAILED=1echo ""done-finish_suite+finish_suite "${SUITE_FAILED}"diff --git a/tests/e2e/scenarios/api/actions-extended.sh b/tests/e2e/scenarios/api/actions-extended.shindex 26aab0de..c8231f82 100644--- a/tests/e2e/scenarios/api/actions-extended.sh+++ b/tests/e2e/scenarios/api/actions-extended.sh@@ -509,12 +509,6 @@ assert_not_ok "unscoped selector cannot type into cross-origin iframe"end_test-# Regression test for GitHub issue #236: press action was typing key names-# as literal text instead of dispatching keyboard events.--# Use permissive instance (needs evaluate enabled)-E2E_SERVER="http://pinchtab:9999"-# ─────────────────────────────────────────────────────────────────start_test "press Enter: does not type 'Enter' as text"diff --git a/tests/e2e/scenarios/api/network-retain-body.sh b/tests/e2e/scenarios/api/network-retain-body.shindex 51a31309..e4308884 100644--- a/tests/e2e/scenarios/api/network-retain-body.sh+++ b/tests/e2e/scenarios/api/network-retain-body.sh@@ -7,72 +7,69 @@ source "${GROUP_DIR}/../../helpers/api.sh"start_test "network detail: retained response body"if [ -z "${E2E_RETAIN_SERVER:-}" ]; then- echo " E2E_RETAIN_SERVER not set, skipping retained-body smoke"+ skip_test "E2E_RETAIN_SERVER not set"end_test- exit 0+ return 0 2>/dev/null || exit 0fi-NETWORK_RETAIN_OLD_SERVER="$E2E_SERVER"-E2E_SERVER="$E2E_RETAIN_SERVER"+retained_body_checks() {+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/network-retain-body.html\"}"+ assert_ok "navigate to retention fixture"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/network-retain-body.html\"}"-assert_ok "navigate to retention fixture"+ # The fixture uses fetch(), which CDP classifies as Fetch rather than XHR.+ NETWORK_JSON=$(e2e_curl -s "${E2E_SERVER}/network?type=Fetch&limit=20")+ REQ_ID=$(echo "$NETWORK_JSON" | jq -r '.entries[] | select(.url | contains("network-retain-body.json")) | .requestId' | head -n1)+ if [ -z "$REQ_ID" ] || [ "$REQ_ID" = "null" ]; then+ fail_assert "could not find retained-body request in network buffer"+ return 1+ fi-# The fixture uses fetch(), which CDP classifies as Fetch rather than XHR.-NETWORK_JSON=$(e2e_curl -s "${E2E_SERVER}/network?type=Fetch&limit=20")-REQ_ID=$(echo "$NETWORK_JSON" | jq -r '.entries[] | select(.url | contains("network-retain-body.json")) | .requestId' | head -n1)-if [ -z "$REQ_ID" ] || [ "$REQ_ID" = "null" ]; then- echo -e " ${RED}✗${NC} could not find retained-body request in network buffer"- ((ASSERTIONS_FAILED++)) || true- end_test- E2E_SERVER="$NETWORK_RETAIN_OLD_SERVER"- exit 0-fi+ echo -e " ${GREEN}✓${NC} found request id: $REQ_ID"+ ((ASSERTIONS_PASSED++)) || true-echo -e " ${GREEN}✓${NC} found request id: $REQ_ID"-((ASSERTIONS_PASSED++)) || true+ DETAIL=$(e2e_curl -s "${E2E_SERVER}/network/${REQ_ID}?body=true&bodyMode=retained-preferred&timeoutMs=2000")-DETAIL=$(e2e_curl -s "${E2E_SERVER}/network/${REQ_ID}?body=true&bodyMode=retained-preferred&timeoutMs=2000")+ echo "$DETAIL" | jq -e '.bodyRetained == true' >/dev/null 2>&1+ if [ $? -eq 0 ]; then+ echo -e " ${GREEN}✓${NC} bodyRetained=true"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} expected bodyRetained=true"+ echo "$DETAIL" | jq .+ ((ASSERTIONS_FAILED++)) || true+ fi-echo "$DETAIL" | jq -e '.bodyRetained == true' >/dev/null 2>&1-if [ $? -eq 0 ]; then- echo -e " ${GREEN}✓${NC} bodyRetained=true"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${RED}✗${NC} expected bodyRetained=true"- echo "$DETAIL" | jq .- ((ASSERTIONS_FAILED++)) || true-fi+ echo "$DETAIL" | jq -e '.bodySource == "retained"' >/dev/null 2>&1+ if [ $? -eq 0 ]; then+ echo -e " ${GREEN}✓${NC} bodySource=retained"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} expected bodySource=retained"+ echo "$DETAIL" | jq .+ ((ASSERTIONS_FAILED++)) || true+ fi-echo "$DETAIL" | jq -e '.bodySource == "retained"' >/dev/null 2>&1-if [ $? -eq 0 ]; then- echo -e " ${GREEN}✓${NC} bodySource=retained"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${RED}✗${NC} expected bodySource=retained"- echo "$DETAIL" | jq .- ((ASSERTIONS_FAILED++)) || true-fi+ echo "$DETAIL" | jq -e '.responseBody | contains("retained-body-ok")' >/dev/null 2>&1+ if [ $? -eq 0 ]; then+ echo -e " ${GREEN}✓${NC} retained response body contains expected payload"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} retained response body missing expected payload"+ echo "$DETAIL" | jq .+ ((ASSERTIONS_FAILED++)) || true+ fi-echo "$DETAIL" | jq -e '.responseBody | contains("retained-body-ok")' >/dev/null 2>&1-if [ $? -eq 0 ]; then- echo -e " ${GREEN}✓${NC} retained response body contains expected payload"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${RED}✗${NC} retained response body missing expected payload"- echo "$DETAIL" | jq .- ((ASSERTIONS_FAILED++)) || true-fi+ echo "$DETAIL" | jq -e '(.bodyPending // false) == false' >/dev/null 2>&1+ if [ $? -eq 0 ]; then+ echo -e " ${GREEN}✓${NC} bounded wait completed without leaving bodyPending=true"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} expected bodyPending=false after bounded wait"+ echo "$DETAIL" | jq .+ ((ASSERTIONS_FAILED++)) || true+ fi+}-echo "$DETAIL" | jq -e '(.bodyPending // false) == false' >/dev/null 2>&1-if [ $? -eq 0 ]; then- echo -e " ${GREEN}✓${NC} bounded wait completed without leaving bodyPending=true"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${RED}✗${NC} expected bodyPending=false after bounded wait"- echo "$DETAIL" | jq .- ((ASSERTIONS_FAILED++)) || true-fi+with_server "$E2E_RETAIN_SERVER" retained_body_checksend_test-E2E_SERVER="$NETWORK_RETAIN_OLD_SERVER"diff --git a/tests/e2e/scenarios/api/network-route-extended.sh b/tests/e2e/scenarios/api/network-route-extended.shindex ac2a21ec..8588727e 100755--- a/tests/e2e/scenarios/api/network-route-extended.sh+++ b/tests/e2e/scenarios/api/network-route-extended.sh@@ -13,20 +13,6 @@ if [ -z "${E2E_FULL_SERVER:-}" ]; thenreturn 0 2>/dev/null || exit 0fi-NETROUTE_OLD_SERVER=""--netroute_use_full_server() {- NETROUTE_OLD_SERVER="$E2E_SERVER"- E2E_SERVER="$E2E_FULL_SERVER"-}--netroute_restore_server() {- if [ -n "${NETROUTE_OLD_SERVER}" ]; then- E2E_SERVER="${NETROUTE_OLD_SERVER}"- NETROUTE_OLD_SERVER=""- fi-}-# ─────────────────────────────────────────────────────────────────# Capability disabled on the default server → 403.# ─────────────────────────────────────────────────────────────────@@ -44,165 +30,163 @@ assert_json_contains "$RESULT" '.details.setting' 'security.allowNetworkIntercepend_test# ─────────────────────────────────────────────────────────────────-# Switch to full-permissive server for the happy paths.+# Happy paths run against the full-permissive server.# ─────────────────────────────────────────────────────────────────-netroute_use_full_server-trap netroute_restore_server EXIT+netroute_full_server_tests() {+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"+ assert_ok "navigate (full-permissive)"+ TAB_ID=$(echo "$RESULT" | jq -r '.tabId')-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"-assert_ok "navigate (full-permissive)"-TAB_ID=$(echo "$RESULT" | jq -r '.tabId')+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /tabs/{id}/network/route installs an abort rule"-# ─────────────────────────────────────────────────────────────────-start_test "POST /tabs/{id}/network/route installs an abort rule"+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"*.png","action":"abort"}'+ assert_ok "install abort rule"+ assert_json_eq "$RESULT" '.ok' 'true'+ assert_json_eq "$RESULT" '.rules | length' '1' "one rule stored"+ assert_json_eq "$RESULT" '.rules[0].action' 'abort'+ assert_json_eq "$RESULT" '.rules[0].pattern' '*.png'-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"*.png","action":"abort"}'-assert_ok "install abort rule"-assert_json_eq "$RESULT" '.ok' 'true'-assert_json_eq "$RESULT" '.rules | length' '1' "one rule stored"-assert_json_eq "$RESULT" '.rules[0].action' 'abort'-assert_json_eq "$RESULT" '.rules[0].pattern' '*.png'+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "GET /tabs/{id}/network/route lists current rules"-# ─────────────────────────────────────────────────────────────────-start_test "GET /tabs/{id}/network/route lists current rules"+ pt_get "/tabs/${TAB_ID}/network/route"+ assert_ok "list rules"+ assert_json_eq "$RESULT" '.rules | length' '1'-pt_get "/tabs/${TAB_ID}/network/route"-assert_ok "list rules"-assert_json_eq "$RESULT" '.rules | length' '1'+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /tabs/{id}/network/route same pattern replaces (no growth)"-# ─────────────────────────────────────────────────────────────────-start_test "POST /tabs/{id}/network/route same pattern replaces (no growth)"+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"*.png","action":"continue"}'+ assert_ok "replace by same pattern"+ assert_json_eq "$RESULT" '.rules | length' '1' "still one rule"+ assert_json_eq "$RESULT" '.rules[0].action' 'continue' "action updated"-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"*.png","action":"continue"}'-assert_ok "replace by same pattern"-assert_json_eq "$RESULT" '.rules | length' '1' "still one rule"-assert_json_eq "$RESULT" '.rules[0].action' 'continue' "action updated"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /tabs/{id}/network/route adds fulfill rule with json body"-# ─────────────────────────────────────────────────────────────────-start_test "POST /tabs/{id}/network/route adds fulfill rule with json body"+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"api/users","action":"fulfill","body":"{\"k\":1}","status":201}'+ assert_ok "install fulfill rule"+ assert_json_eq "$RESULT" '.rules | length' '2' "two rules"-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"api/users","action":"fulfill","body":"{\"k\":1}","status":201}'-assert_ok "install fulfill rule"-assert_json_eq "$RESULT" '.rules | length' '2' "two rules"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /tabs/{id}/network/route rejects oversize body"-# ─────────────────────────────────────────────────────────────────-start_test "POST /tabs/{id}/network/route rejects oversize body"+ # Build a string slightly over 1 MiB.+ HUGE=$(head -c $((1024 * 1024 + 16)) /dev/zero | tr '\0' 'x')+ PAYLOAD=$(jq -n --arg b "$HUGE" '{pattern:"big",action:"fulfill",body:$b}')+ pt_post "/tabs/${TAB_ID}/network/route" -d "$PAYLOAD"+ assert_not_ok "rejects body over 1 MiB cap"-# Build a string slightly over 1 MiB.-HUGE=$(head -c $((1024 * 1024 + 16)) /dev/zero | tr '\0' 'x')-PAYLOAD=$(jq -n --arg b "$HUGE" '{pattern:"big",action:"fulfill",body:$b}')-pt_post "/tabs/${TAB_ID}/network/route" -d "$PAYLOAD"-assert_not_ok "rejects body over 1 MiB cap"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /tabs/{id}/network/route rejects out-of-range status"-# ─────────────────────────────────────────────────────────────────-start_test "POST /tabs/{id}/network/route rejects out-of-range status"+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"fulfill","body":"{}","status":999}'+ assert_not_ok "rejects status=999"-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"fulfill","body":"{}","status":999}'-assert_not_ok "rejects status=999"+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"fulfill","body":"{}","status":50}'+ assert_not_ok "rejects status=50"-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"fulfill","body":"{}","status":50}'-assert_not_ok "rejects status=50"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /tabs/{id}/network/route rejects forbidden Content-Type"-# ─────────────────────────────────────────────────────────────────-start_test "POST /tabs/{id}/network/route rejects forbidden Content-Type"+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"fulfill","body":"<script>1</script>","contentType":"text/html"}'+ assert_not_ok "rejects text/html"-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"fulfill","body":"<script>1</script>","contentType":"text/html"}'-assert_not_ok "rejects text/html"+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"fulfill","body":"alert(1)","contentType":"application/javascript"}'+ assert_not_ok "rejects application/javascript"-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"fulfill","body":"alert(1)","contentType":"application/javascript"}'-assert_not_ok "rejects application/javascript"+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"fulfill","body":"<svg/>","contentType":"image/svg+xml"}'+ assert_not_ok "rejects image/svg+xml"-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"fulfill","body":"<svg/>","contentType":"image/svg+xml"}'-assert_not_ok "rejects image/svg+xml"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /tabs/{id}/network/route rejects CRLF in Content-Type"-# ─────────────────────────────────────────────────────────────────-start_test "POST /tabs/{id}/network/route rejects CRLF in Content-Type"+ pt_post "/tabs/${TAB_ID}/network/route" -d "$(jq -n '{pattern:"x",action:"fulfill",body:"{}",contentType:"application/json\r\nX-Evil: 1"}')"+ assert_not_ok "rejects header injection via CRLF"-pt_post "/tabs/${TAB_ID}/network/route" -d "$(jq -n '{pattern:"x",action:"fulfill",body:"{}",contentType:"application/json\r\nX-Evil: 1"}')"-assert_not_ok "rejects header injection via CRLF"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /tabs/{id}/network/route rejects unknown HTTP method"-# ─────────────────────────────────────────────────────────────────-start_test "POST /tabs/{id}/network/route rejects unknown HTTP method"+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"abort","method":"FOOBAR"}'+ assert_not_ok "rejects bogus method"-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"abort","method":"FOOBAR"}'-assert_not_ok "rejects bogus method"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /tabs/{id}/network/route rejects unknown resourceType"-# ─────────────────────────────────────────────────────────────────-start_test "POST /tabs/{id}/network/route rejects unknown resourceType"+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"abort","resourceType":"java"}'+ assert_not_ok "rejects bogus resourceType"-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"x","action":"abort","resourceType":"java"}'-assert_not_ok "rejects bogus resourceType"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /tabs/{id}/network/route rejects forbidden URL scheme"-# ─────────────────────────────────────────────────────────────────-start_test "POST /tabs/{id}/network/route rejects forbidden URL scheme"--# Schemes like javascript: / data: / file: / chrome: must never be fulfilled-# regardless of the host allowlist. Validation is at the bridge boundary so-# the rule itself is rejected on installation.-# Note: AddRule's scheme reject fires only when the request URL matches at-# match time, so the install itself succeeds for an arbitrary pattern. But a-# fulfill rule whose pattern only matches a forbidden-scheme URL has no-# user-visible path — covered by unit tests. Here we sanity-check missing-# pattern still 400s.-pt_post "/tabs/${TAB_ID}/network/route" -d '{"action":"abort"}'-assert_not_ok "rejects empty pattern"+ # Schemes like javascript: / data: / file: / chrome: must never be fulfilled+ # regardless of the host allowlist. Validation is at the bridge boundary so+ # the rule itself is rejected on installation.+ # Note: AddRule's scheme reject fires only when the request URL matches at+ # match time, so the install itself succeeds for an arbitrary pattern. But a+ # fulfill rule whose pattern only matches a forbidden-scheme URL has no+ # user-visible path — covered by unit tests. Here we sanity-check missing+ # pattern still 400s.+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"action":"abort"}'+ assert_not_ok "rejects empty pattern"-end_test+ end_test-# ─────────────────────────────────────────────────────────────────-start_test "DELETE /tabs/{id}/network/route?pattern=… removes one rule"+ # ─────────────────────────────────────────────────────────────────+ start_test "DELETE /tabs/{id}/network/route?pattern=… removes one rule"-pt_delete "/tabs/${TAB_ID}/network/route?pattern=%2A.png"-assert_ok "remove one rule"-assert_json_eq "$RESULT" '.removed' '1'+ pt_delete "/tabs/${TAB_ID}/network/route?pattern=%2A.png"+ assert_ok "remove one rule"+ assert_json_eq "$RESULT" '.removed' '1'-end_test+ end_test-# ─────────────────────────────────────────────────────────────────-start_test "DELETE /tabs/{id}/network/route (no pattern) clears remaining rules"+ # ─────────────────────────────────────────────────────────────────+ start_test "DELETE /tabs/{id}/network/route (no pattern) clears remaining rules"-pt_delete "/tabs/${TAB_ID}/network/route"-assert_ok "clear all"+ pt_delete "/tabs/${TAB_ID}/network/route"+ assert_ok "clear all"-end_test+ end_test-# ─────────────────────────────────────────────────────────────────-start_test "DELETE /tabs/{id}/network/route again returns 404 (tab not routed)"+ # ─────────────────────────────────────────────────────────────────+ start_test "DELETE /tabs/{id}/network/route again returns 404 (tab not routed)"-# After clearing, the route manager forgets the tab. A second unroute should-# distinguish that from "rule matched nothing" by 404'ing.-pt_delete "/tabs/${TAB_ID}/network/route"-assert_not_ok "second unroute on cleared tab returns error"+ # After clearing, the route manager forgets the tab. A second unroute should+ # distinguish that from "rule matched nothing" by 404'ing.+ pt_delete "/tabs/${TAB_ID}/network/route"+ assert_not_ok "second unroute on cleared tab returns error"-end_test+ end_test-# ─────────────────────────────────────────────────────────────────-start_test "POST /network/clear works when capability on (full-permissive)"+ # ─────────────────────────────────────────────────────────────────+ start_test "POST /network/clear works when capability on (full-permissive)"-pt_post /network/clear "{\"tabId\":\"${TAB_ID}\"}"-assert_ok "clear network data"+ pt_post /network/clear "{\"tabId\":\"${TAB_ID}\"}"+ assert_ok "clear network data"-end_test+ end_test+}-netroute_restore_server-trap - EXIT+with_server "$E2E_FULL_SERVER" netroute_full_server_testsdiff --git a/tests/e2e/scenarios/api/network-route-smoke.sh b/tests/e2e/scenarios/api/network-route-smoke.shindex d4006e54..a8916599 100755--- a/tests/e2e/scenarios/api/network-route-smoke.sh+++ b/tests/e2e/scenarios/api/network-route-smoke.sh@@ -20,100 +20,100 @@ if [ -z "${E2E_FULL_SERVER:-}" ]; thenreturn 0 2>/dev/null || exit 0fi-NETROUTE_SMOKE_OLD_SERVER="$E2E_SERVER"-E2E_SERVER="$E2E_FULL_SERVER"-trap 'E2E_SERVER="$NETROUTE_SMOKE_OLD_SERVER"' EXIT--# Land on a known fixture so any subsequent fetches share that origin (the-# fixtures host is in allowedDomains, which is what we exercise below).-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"-assert_ok "navigate to fixture"-TAB_ID=$(echo "$RESULT" | jq -r '.tabId')--# Drive a fetch from inside the page and capture {ok,status,text} or {error}.-# Uses mode:'no-cors' so a cross-origin fulfill (which we deliberately do NOT-# decorate with ACAO headers) resolves opaquely instead of being rejected by-# CORS — otherwise the page-level promise would throw a TypeError that is-# indistinguishable from a real network failure, and we couldn't tell whether-# the rule fired. Same-origin fetches (covered by the allowlisted-host case)-# are unaffected: text() still returns the real body.-fetch_in_page() {- local url="$1"- local expr- expr=$(jq -n --arg u "$url" '- {- expression: ("(async () => { try { const r = await fetch(\($u | tojson), {mode:\"no-cors\"}); return JSON.stringify({ok:r.ok,status:r.status,type:r.type,text:(await r.text()).slice(0,200)}); } catch(e) { return JSON.stringify({error:String(e)}); } })()"),- awaitPromise: true- }')- pt_post /evaluate -d "$expr"+netroute_smoke_tests() {+ # Land on a known fixture so any subsequent fetches share that origin (the+ # fixtures host is in allowedDomains, which is what we exercise below).+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"+ assert_ok "navigate to fixture"+ TAB_ID=$(echo "$RESULT" | jq -r '.tabId')++ # Drive a fetch from inside the page and capture {ok,status,text} or {error}.+ # Uses mode:'no-cors' so a cross-origin fulfill (which we deliberately do NOT+ # decorate with ACAO headers) resolves opaquely instead of being rejected by+ # CORS — otherwise the page-level promise would throw a TypeError that is+ # indistinguishable from a real network failure, and we couldn't tell whether+ # the rule fired. Same-origin fetches (covered by the allowlisted-host case)+ # are unaffected: text() still returns the real body.+ fetch_in_page() {+ local url="$1"+ local expr+ expr=$(jq -n --arg u "$url" '+ {+ expression: ("(async () => { try { const r = await fetch(\($u | tojson), {mode:\"no-cors\"}); return JSON.stringify({ok:r.ok,status:r.status,type:r.type,text:(await r.text()).slice(0,200)}); } catch(e) { return JSON.stringify({error:String(e)}); } })()"),+ awaitPromise: true+ }')+ pt_post /evaluate -d "$expr"+ }++ # ─────────────────────────────────────────────────────────────────+ start_test "abort rule turns matching fetches into network errors"++ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"abort-target.invalid","action":"abort"}'+ assert_ok "install abort rule"++ fetch_in_page "https://abort-target.invalid/api"+ # fetch() throws TypeError on a network-level abort; the shim returns the+ # error string in that case.+ assert_json_contains "$RESULT" '.result' 'error' "fetch errored (request aborted)"++ pt_delete "/tabs/${TAB_ID}/network/route" >/dev/null+ end_test++ # ─────────────────────────────────────────────────────────────────+ start_test "fulfill on UNLISTED host: rule fires (fetch does not throw)"++ # Baseline: without the rule, the fetch to a .invalid host throws (DNS+ # fails). Establish that first so the with-rule comparison is meaningful.+ fetch_in_page "https://mock-target.invalid/api"+ assert_json_contains "$RESULT" '.result' 'error' "baseline: bare fetch to .invalid throws"++ # Install fulfill on the unlisted host. Cross-origin response is opaque to+ # the page (we don't set ACAO — that would be the CORS bypass we explicitly+ # guard against), so we can't read the body. We *can* verify the rule+ # intercepted by checking fetch resolved instead of throwing.+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"mock-target.invalid","action":"fulfill","body":"{\"forged\":true}","status":200,"contentType":"application/json"}'+ assert_ok "install fulfill rule on unlisted host"++ fetch_in_page "https://mock-target.invalid/api"+ # After fulfill: fetch resolves (with an opaque response). The shim's catch+ # branch — the only path that emits an "error" key — does NOT fire.+ assert_json_eq "$RESULT" '(.result | contains("error"))' 'false' "fetch resolved (rule intercepted)"++ pt_delete "/tabs/${TAB_ID}/network/route" >/dev/null+ end_test++ # ─────────────────────────────────────────────────────────────────+ start_test "fulfill on ALLOWLISTED host falls through to real fetch"++ # allowedDomains in pinchtab-full-permissive includes the fixtures host. Per+ # the inverted policy, fulfill must NOT win here — the real fixtures content+ # must come back. Same-origin fetch, so the body is fully readable.+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"buttons.html","action":"fulfill","body":"{\"forged\":true}","status":200,"contentType":"application/json"}'+ assert_ok "install fulfill rule on allowlisted host"++ fetch_in_page "${FIXTURES_URL}/buttons.html"+ # If fulfill had won, the body would be {"forged":true}. We assert the real+ # fixture HTML came through instead.+ assert_json_eq "$RESULT" '(.result | fromjson | .text | contains("forged") | not)' 'true' "fulfill blocked: body is real fixture, not forged"++ pt_delete "/tabs/${TAB_ID}/network/route" >/dev/null+ end_test++ # ─────────────────────────────────────────────────────────────────+ start_test "fulfill with --resource-type=script does not match a fetch()"++ # Scope the rule to ResourceType=script. fetch() carries resource type+ # "fetch" or "xhr" — neither matches "script", so the rule must NOT fire,+ # the request must reach the (nonexistent) host, and the page must see a+ # network error.+ pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"resource-target.invalid","action":"fulfill","body":"{\"forged\":true}","status":200,"contentType":"application/json","resourceType":"script"}'+ assert_ok "install resource-type-scoped rule"++ fetch_in_page "https://resource-target.invalid/api"+ assert_json_contains "$RESULT" '.result' 'error' "resource-type filter excludes fetch()"++ pt_delete "/tabs/${TAB_ID}/network/route" >/dev/null+ end_test}-# ─────────────────────────────────────────────────────────────────-start_test "abort rule turns matching fetches into network errors"--pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"abort-target.invalid","action":"abort"}'-assert_ok "install abort rule"--fetch_in_page "https://abort-target.invalid/api"-# fetch() throws TypeError on a network-level abort; the shim returns the-# error string in that case.-assert_json_contains "$RESULT" '.result' 'error' "fetch errored (request aborted)"--pt_delete "/tabs/${TAB_ID}/network/route" >/dev/null-end_test--# ─────────────────────────────────────────────────────────────────-start_test "fulfill on UNLISTED host: rule fires (fetch does not throw)"--# Baseline: without the rule, the fetch to a .invalid host throws (DNS-# fails). Establish that first so the with-rule comparison is meaningful.-fetch_in_page "https://mock-target.invalid/api"-assert_json_contains "$RESULT" '.result' 'error' "baseline: bare fetch to .invalid throws"--# Install fulfill on the unlisted host. Cross-origin response is opaque to-# the page (we don't set ACAO — that would be the CORS bypass we explicitly-# guard against), so we can't read the body. We *can* verify the rule-# intercepted by checking fetch resolved instead of throwing.-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"mock-target.invalid","action":"fulfill","body":"{\"forged\":true}","status":200,"contentType":"application/json"}'-assert_ok "install fulfill rule on unlisted host"--fetch_in_page "https://mock-target.invalid/api"-# After fulfill: fetch resolves (with an opaque response). The shim's catch-# branch — the only path that emits an "error" key — does NOT fire.-assert_json_eq "$RESULT" '(.result | contains("error"))' 'false' "fetch resolved (rule intercepted)"--pt_delete "/tabs/${TAB_ID}/network/route" >/dev/null-end_test--# ─────────────────────────────────────────────────────────────────-start_test "fulfill on ALLOWLISTED host falls through to real fetch"--# allowedDomains in pinchtab-full-permissive includes the fixtures host. Per-# the inverted policy, fulfill must NOT win here — the real fixtures content-# must come back. Same-origin fetch, so the body is fully readable.-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"buttons.html","action":"fulfill","body":"{\"forged\":true}","status":200,"contentType":"application/json"}'-assert_ok "install fulfill rule on allowlisted host"--fetch_in_page "${FIXTURES_URL}/buttons.html"-# If fulfill had won, the body would be {"forged":true}. We assert the real-# fixture HTML came through instead.-assert_json_eq "$RESULT" '(.result | fromjson | .text | contains("forged") | not)' 'true' "fulfill blocked: body is real fixture, not forged"--pt_delete "/tabs/${TAB_ID}/network/route" >/dev/null-end_test--# ─────────────────────────────────────────────────────────────────-start_test "fulfill with --resource-type=script does not match a fetch()"--# Scope the rule to ResourceType=script. fetch() carries resource type-# "fetch" or "xhr" — neither matches "script", so the rule must NOT fire,-# the request must reach the (nonexistent) host, and the page must see a-# network error.-pt_post "/tabs/${TAB_ID}/network/route" -d '{"pattern":"resource-target.invalid","action":"fulfill","body":"{\"forged\":true}","status":200,"contentType":"application/json","resourceType":"script"}'-assert_ok "install resource-type-scoped rule"--fetch_in_page "https://resource-target.invalid/api"-assert_json_contains "$RESULT" '.result' 'error' "resource-type filter excludes fetch()"--pt_delete "/tabs/${TAB_ID}/network/route" >/dev/null-end_test+with_server "$E2E_FULL_SERVER" netroute_smoke_testsdiff --git a/tests/e2e/scenarios/api/secrets-extended.sh b/tests/e2e/scenarios/api/secrets-extended.shindex 77c9ea03..e975d7c1 100644--- a/tests/e2e/scenarios/api/secrets-extended.sh+++ b/tests/e2e/scenarios/api/secrets-extended.sh@@ -118,9 +118,6 @@ assert_field_value "#new-password" "$SECRET" "new-password value persisted afterend_test-# Scenarios are SOURCED into one shell, and finish_suite exits when any earlier-# test has failed — unguarded, this file amputates every scenario after it as-# soon as something upstream goes red. Same guard the other scenarios use.if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; thenfinish_suitefidiff --git a/tests/e2e/scenarios/api/tabs-autoclose-smoke.sh b/tests/e2e/scenarios/api/tabs-autoclose-smoke.shindex 71be9318..22f5230d 100755--- a/tests/e2e/scenarios/api/tabs-autoclose-smoke.sh+++ b/tests/e2e/scenarios/api/tabs-autoclose-smoke.sh@@ -14,163 +14,165 @@GROUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"source "${GROUP_DIR}/../../helpers/api.sh"-AUTOCLOSE_ORIG_SERVER="$E2E_SERVER"-if [ -n "${E2E_AUTOCLOSE_SERVER:-}" ]; then- E2E_SERVER="$E2E_AUTOCLOSE_SERVER"-fi+AUTOCLOSE_SERVER="${E2E_AUTOCLOSE_SERVER:-$E2E_SERVER}"++autoclose_lifecycle_configured() {+ e2e_curl -sf "${E2E_SERVER}/api/config" 2>/dev/null |+ jq -e '(.config // .).instanceDefaults.tabPolicy.lifecycle == "close_idle" and ((.config // .).instanceDefaults.tabPolicy.closeDelaySec | tonumber) == 1' >/dev/null 2>&1+}-AUTOCLOSE_CONFIG=$(e2e_curl -sf "${E2E_SERVER}/api/config" 2>/dev/null || true)-if ! echo "$AUTOCLOSE_CONFIG" | jq -e '(.config // .).instanceDefaults.tabPolicy.lifecycle == "close_idle" and ((.config // .).instanceDefaults.tabPolicy.closeDelaySec | tonumber) == 1' >/dev/null 2>&1; then- echo -e " ${YELLOW}⚠${NC} auto-close lifecycle server not configured at ${E2E_SERVER}, skipping"- E2E_SERVER="$AUTOCLOSE_ORIG_SERVER"+if ! with_server "$AUTOCLOSE_SERVER" autoclose_lifecycle_configured; then+ echo -e " ${YELLOW}⚠${NC} auto-close lifecycle server not configured at ${AUTOCLOSE_SERVER}, skipping"return 0 2>/dev/null || exit 0fi-# Auto-close delay in seconds (must match closeDelaySec in pinchtab-autoclose.json).-CLOSE_DELAY=1-# A safety margin past the delay before asserting the tab is gone.-PAST_CLOSE_WAIT=1.8-# A short interval well under the delay, used to verify reset semantics.-WITHIN_DELAY=0.4--tab_id_exists() {- local tab_id="$1"- local tabs_json- tabs_json=$(e2e_curl -sf "${E2E_SERVER}/tabs" 2>/dev/null || true)- if [ -z "$tabs_json" ]; then- return 2- fi-- echo "$tabs_json" | jq -e --arg id "$tab_id" 'any(.tabs[]?; .id == $id)' >/dev/null 2>&1-}+autoclose_tests() {+ # Auto-close delay in seconds (must match closeDelaySec in pinchtab-autoclose.json).+ CLOSE_DELAY=1+ # A safety margin past the delay before asserting the tab is gone.+ PAST_CLOSE_WAIT=1.8+ # A short interval well under the delay, used to verify reset semantics.+ WITHIN_DELAY=0.4++ tab_id_exists() {+ local tab_id="$1"+ local tabs_json+ tabs_json=$(e2e_curl -sf "${E2E_SERVER}/tabs" 2>/dev/null || true)+ if [ -z "$tabs_json" ]; then+ return 2+ fi-assert_tab_id_open() {- local tab_id="$1"- local desc="${2:-tab is open}"-- tab_id_exists "$tab_id"- local status=$?- if [ "$status" -eq 0 ]; then- echo -e " ${GREEN}✓${NC} ${desc}: ${tab_id:0:12}..."- ((ASSERTIONS_PASSED++)) || true- elif [ "$status" -eq 1 ]; then- echo -e " ${RED}✗${NC} ${desc}: tab ${tab_id:0:12}... is missing"- ((ASSERTIONS_FAILED++)) || true- else- echo -e " ${RED}✗${NC} ${desc}: unable to fetch tab list"- ((ASSERTIONS_FAILED++)) || true- fi-}+ echo "$tabs_json" | jq -e --arg id "$tab_id" 'any(.tabs[]?; .id == $id)' >/dev/null 2>&1+ }-wait_for_tab_id_closed() {- local tab_id="$1"- local desc="${2:-tab closed}"- local attempts="${3:-20}"- local delay="${4:-0.25}"+ assert_tab_id_open() {+ local tab_id="$1"+ local desc="${2:-tab is open}"- for _ in $(seq 1 "$attempts"); dotab_id_exists "$tab_id"local status=$?- if [ "$status" -eq 1 ]; then+ if [ "$status" -eq 0 ]; thenecho -e " ${GREEN}✓${NC} ${desc}: ${tab_id:0:12}..."((ASSERTIONS_PASSED++)) || true- return 0+ elif [ "$status" -eq 1 ]; then+ echo -e " ${RED}✗${NC} ${desc}: tab ${tab_id:0:12}... is missing"+ ((ASSERTIONS_FAILED++)) || true+ else+ echo -e " ${RED}✗${NC} ${desc}: unable to fetch tab list"+ ((ASSERTIONS_FAILED++)) || truefi- sleep "$delay"- done-- echo -e " ${RED}✗${NC} ${desc}: tab ${tab_id:0:12}... is still open"- ((ASSERTIONS_FAILED++)) || true- return 1-}+ }++ wait_for_tab_id_closed() {+ local tab_id="$1"+ local desc="${2:-tab closed}"+ local attempts="${3:-20}"+ local delay="${4:-0.25}"++ for _ in $(seq 1 "$attempts"); do+ tab_id_exists "$tab_id"+ local status=$?+ if [ "$status" -eq 1 ]; then+ echo -e " ${GREEN}✓${NC} ${desc}: ${tab_id:0:12}..."+ ((ASSERTIONS_PASSED++)) || true+ return 0+ fi+ sleep "$delay"+ done++ echo -e " ${RED}✗${NC} ${desc}: tab ${tab_id:0:12}... is still open"+ ((ASSERTIONS_FAILED++)) || true+ return 1+ }-# ─────────────────────────────────────────────────────────────────-start_test "auto-close: /text arms a timer that fires after the delay"+ # ─────────────────────────────────────────────────────────────────+ start_test "auto-close: /text arms a timer that fires after the delay"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"-TAB_ID=$(get_tab_id)-show_tab "created" "$TAB_ID"+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"+ TAB_ID=$(get_tab_id)+ show_tab "created" "$TAB_ID"-pt_get "/text?tabId=${TAB_ID}&format=text"-assert_ok "tab text (arms auto-close)"+ pt_get "/text?tabId=${TAB_ID}&format=text"+ assert_ok "tab text (arms auto-close)"-wait_for_tab_id_closed "$TAB_ID" "tab closed after /text"+ wait_for_tab_id_closed "$TAB_ID" "tab closed after /text"-end_test+ end_test-# ─────────────────────────────────────────────────────────────────-start_test "auto-close: a second /text within the delay window resets the timer"+ # ─────────────────────────────────────────────────────────────────+ start_test "auto-close: a second /text within the delay window resets the timer"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"-TAB_ID=$(get_tab_id)+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"+ TAB_ID=$(get_tab_id)-pt_get "/text?tabId=${TAB_ID}&format=text"-assert_ok "first /text"+ pt_get "/text?tabId=${TAB_ID}&format=text"+ assert_ok "first /text"-# Second /text well within the delay — must reset the timer.-sleep "$WITHIN_DELAY"-pt_get "/text?tabId=${TAB_ID}&format=text"-assert_ok "second /text resets timer"+ # Second /text well within the delay — must reset the timer.+ sleep "$WITHIN_DELAY"+ pt_get "/text?tabId=${TAB_ID}&format=text"+ assert_ok "second /text resets timer"-# Wait less than (CLOSE_DELAY + WITHIN_DELAY) but more than CLOSE_DELAY since-# the first /text — if reset worked, the tab is still alive here.-sleep "$WITHIN_DELAY"-assert_tab_id_open "$TAB_ID" "tab still open after reset"+ # Wait less than (CLOSE_DELAY + WITHIN_DELAY) but more than CLOSE_DELAY since+ # the first /text — if reset worked, the tab is still alive here.+ sleep "$WITHIN_DELAY"+ assert_tab_id_open "$TAB_ID" "tab still open after reset"-# Now wait past the second timer's deadline; the tab should be gone.-wait_for_tab_id_closed "$TAB_ID" "tab closed after reset deadline"+ # Now wait past the second timer's deadline; the tab should be gone.+ wait_for_tab_id_closed "$TAB_ID" "tab closed after reset deadline"-end_test+ end_test-# ─────────────────────────────────────────────────────────────────-start_test "auto-close: /navigate cancels a pending timer"+ # ─────────────────────────────────────────────────────────────────+ start_test "auto-close: /navigate cancels a pending timer"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"-TAB_ID=$(get_tab_id)+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"+ TAB_ID=$(get_tab_id)-pt_get "/text?tabId=${TAB_ID}&format=text"-assert_ok "/text arms auto-close"+ pt_get "/text?tabId=${TAB_ID}&format=text"+ assert_ok "/text arms auto-close"-# Re-navigate well within the close delay — should cancel the pending timer.-sleep "$WITHIN_DELAY"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/form.html\",\"tabId\":\"${TAB_ID}\"}"-assert_ok "/navigate cancels pending close"+ # Re-navigate well within the close delay — should cancel the pending timer.+ sleep "$WITHIN_DELAY"+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/form.html\",\"tabId\":\"${TAB_ID}\"}"+ assert_ok "/navigate cancels pending close"-# Wait past the original deadline; the tab must still be alive because-# /navigate dropped the timer and no further /text re-armed it.-sleep "$PAST_CLOSE_WAIT"-assert_tab_id_open "$TAB_ID" "tab survived after /navigate cancel"+ # Wait past the original deadline; the tab must still be alive because+ # /navigate dropped the timer and no further /text re-armed it.+ sleep "$PAST_CLOSE_WAIT"+ assert_tab_id_open "$TAB_ID" "tab survived after /navigate cancel"-# Clean up: explicit close so this test doesn't leak a tab into the next.-pt_post "/tabs/${TAB_ID}/close" -d '{}' >/dev/null+ # Clean up: explicit close so this test doesn't leak a tab into the next.+ pt_post "/tabs/${TAB_ID}/close" -d '{}' >/dev/null-end_test+ end_test-# ─────────────────────────────────────────────────────────────────-start_test "auto-close: /snapshot also arms the timer"+ # ─────────────────────────────────────────────────────────────────+ start_test "auto-close: /snapshot also arms the timer"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"-TAB_ID=$(get_tab_id)+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"+ TAB_ID=$(get_tab_id)-pt_get "/snapshot?tabId=${TAB_ID}"-assert_ok "/snapshot arms auto-close"+ pt_get "/snapshot?tabId=${TAB_ID}"+ assert_ok "/snapshot arms auto-close"-wait_for_tab_id_closed "$TAB_ID" "tab closed after /snapshot"+ wait_for_tab_id_closed "$TAB_ID" "tab closed after /snapshot"-end_test+ end_test-# ─────────────────────────────────────────────────────────────────-start_test "auto-close: /action also arms the timer"+ # ─────────────────────────────────────────────────────────────────+ start_test "auto-close: /action also arms the timer"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"-TAB_ID=$(get_tab_id)+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"+ TAB_ID=$(get_tab_id)-# A read-style action: pressing a key is sufficient to mark the tab "used".-pt_post /action -d "{\"kind\":\"press\",\"key\":\"Tab\",\"tabId\":\"${TAB_ID}\"}"-assert_ok "/action arms auto-close"+ # A read-style action: pressing a key is sufficient to mark the tab "used".+ pt_post /action -d "{\"kind\":\"press\",\"key\":\"Tab\",\"tabId\":\"${TAB_ID}\"}"+ assert_ok "/action arms auto-close"-wait_for_tab_id_closed "$TAB_ID" "tab closed after /action"+ wait_for_tab_id_closed "$TAB_ID" "tab closed after /action"-end_test+ end_test+}-E2E_SERVER="$AUTOCLOSE_ORIG_SERVER"+with_server "$AUTOCLOSE_SERVER" autoclose_testsdiff --git a/tests/e2e/scenarios/api/tabs-extended.sh b/tests/e2e/scenarios/api/tabs-extended.shindex 1b5482b9..b93c2b12 100644--- a/tests/e2e/scenarios/api/tabs-extended.sh+++ b/tests/e2e/scenarios/api/tabs-extended.sh@@ -109,180 +109,179 @@ assert_ok "unlock download tab"end_test-ORIG_URL="$E2E_SERVER"-E2E_SERVER="$E2E_SECURE_SERVER"+secure_server_tests() {+ short_ordering_wait() {+ sleep 0.1+ }-short_ordering_wait() {- sleep 0.1-}+ # ─────────────────────────────────────────────────────────────────+ start_test "LRU eviction: open 2 tabs (at limit)"-# ─────────────────────────────────────────────────────────────────-start_test "LRU eviction: open 2 tabs (at limit)"+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"+ TAB1=$(echo "$RESULT" | jq -r '.tabId')+ assert_ok "open tab 1 (index)"+ echo -e " ${MUTED}tab1: ${TAB1:0:12}...${NC}"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"-TAB1=$(echo "$RESULT" | jq -r '.tabId')-assert_ok "open tab 1 (index)"-echo -e " ${MUTED}tab1: ${TAB1:0:12}...${NC}"+ short_ordering_wait-short_ordering_wait+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/form.html\"}"+ TAB2=$(echo "$RESULT" | jq -r '.tabId')+ assert_ok "open tab 2 (form)"+ echo -e " ${MUTED}tab2: ${TAB2:0:12}...${NC}"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/form.html\"}"-TAB2=$(echo "$RESULT" | jq -r '.tabId')-assert_ok "open tab 2 (form)"-echo -e " ${MUTED}tab2: ${TAB2:0:12}...${NC}"+ pt_get "/tabs/$TAB1/snapshot" > /dev/null+ assert_ok "tab1 accessible"+ pt_get "/tabs/$TAB2/snapshot" > /dev/null+ assert_ok "tab2 accessible"-pt_get "/tabs/$TAB1/snapshot" > /dev/null-assert_ok "tab1 accessible"-pt_get "/tabs/$TAB2/snapshot" > /dev/null-assert_ok "tab2 accessible"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "LRU eviction: 3rd tab evicts least recently used"-# ─────────────────────────────────────────────────────────────────-start_test "LRU eviction: 3rd tab evicts least recently used"+ short_ordering_wait+ pt_get "/tabs/$TAB2/snapshot" > /dev/null+ short_ordering_wait-short_ordering_wait-pt_get "/tabs/$TAB2/snapshot" > /dev/null-short_ordering_wait+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"+ TAB3=$(echo "$RESULT" | jq -r '.tabId')+ assert_ok "open tab 3 (triggers eviction)"+ echo -e " ${MUTED}tab3: ${TAB3:0:12}...${NC}"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/buttons.html\"}"-TAB3=$(echo "$RESULT" | jq -r '.tabId')-assert_ok "open tab 3 (triggers eviction)"-echo -e " ${MUTED}tab3: ${TAB3:0:12}...${NC}"+ pt_get "/tabs/$TAB1/snapshot"+ assert_http_error 404 "" "tab1 evicted (LRU)"-pt_get "/tabs/$TAB1/snapshot"-assert_http_error 404 "" "tab1 evicted (LRU)"+ pt_get "/tabs/$TAB2/snapshot" > /dev/null+ assert_ok "tab2 survived (recently used)"-pt_get "/tabs/$TAB2/snapshot" > /dev/null-assert_ok "tab2 survived (recently used)"+ pt_get "/tabs/$TAB3/snapshot" > /dev/null+ assert_ok "tab3 accessible"-pt_get "/tabs/$TAB3/snapshot" > /dev/null-assert_ok "tab3 accessible"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "LRU eviction: continuous eviction works"-# ─────────────────────────────────────────────────────────────────-start_test "LRU eviction: continuous eviction works"+ short_ordering_wait+ pt_get "/tabs/$TAB3/snapshot" > /dev/null+ short_ordering_wait-short_ordering_wait-pt_get "/tabs/$TAB3/snapshot" > /dev/null-short_ordering_wait+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/table.html\"}"+ TAB4=$(echo "$RESULT" | jq -r '.tabId')+ assert_ok "open tab 4 (triggers second eviction)"-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/table.html\"}"-TAB4=$(echo "$RESULT" | jq -r '.tabId')-assert_ok "open tab 4 (triggers second eviction)"+ pt_get "/tabs/$TAB2/snapshot"+ assert_http_error 404 "" "tab2 evicted (LRU)"-pt_get "/tabs/$TAB2/snapshot"-assert_http_error 404 "" "tab2 evicted (LRU)"+ pt_get "/tabs/$TAB3/snapshot" > /dev/null+ assert_ok "tab3 survived"+ pt_get "/tabs/$TAB4/snapshot" > /dev/null+ assert_ok "tab4 accessible"-pt_get "/tabs/$TAB3/snapshot" > /dev/null-assert_ok "tab3 survived"-pt_get "/tabs/$TAB4/snapshot" > /dev/null-assert_ok "tab4 accessible"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "tabs: list returns array"-# ─────────────────────────────────────────────────────────────────-start_test "tabs: list returns array"+ pt_get /tabs+ assert_ok "list tabs"+ assert_json_exists "$RESULT" '.tabs'+ assert_json_length_gte "$RESULT" '.tabs' '1' "at least 1 tab"-pt_get /tabs-assert_ok "list tabs"-assert_json_exists "$RESULT" '.tabs'-assert_json_length_gte "$RESULT" '.tabs' '1' "at least 1 tab"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "tabs: new + close roundtrip"-# ─────────────────────────────────────────────────────────────────-start_test "tabs: new + close roundtrip"+ pt_post /tab "{\"action\":\"new\",\"url\":\"${FIXTURES_URL}/index.html\"}"+ assert_ok "new tab"+ NEW_TAB=$(echo "$RESULT" | jq -r '.tabId')-pt_post /tab "{\"action\":\"new\",\"url\":\"${FIXTURES_URL}/index.html\"}"-assert_ok "new tab"-NEW_TAB=$(echo "$RESULT" | jq -r '.tabId')+ pt_post /close "{\"tabId\":\"${NEW_TAB}\"}"+ assert_ok "close tab"-pt_post /close "{\"tabId\":\"${NEW_TAB}\"}"-assert_ok "close tab"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "tabs: close without tabId closes default tab"-# ─────────────────────────────────────────────────────────────────-start_test "tabs: close without tabId closes default tab"+ pt_post /tab "{\"action\":\"new\",\"url\":\"${FIXTURES_URL}/index.html\"}"+ assert_ok "new default tab"+ DEFAULT_CLOSE_TAB=$(echo "$RESULT" | jq -r '.tabId')-pt_post /tab "{\"action\":\"new\",\"url\":\"${FIXTURES_URL}/index.html\"}"-assert_ok "new default tab"-DEFAULT_CLOSE_TAB=$(echo "$RESULT" | jq -r '.tabId')+ pt_post /close '{}'+ assert_ok "close default tab"+ assert_result_eq '.tabId' "$DEFAULT_CLOSE_TAB" "default close returned the created tabId"-pt_post /close '{}'-assert_ok "close default tab"-assert_result_eq '.tabId' "$DEFAULT_CLOSE_TAB" "default close returned the created tabId"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "tabs: bad action → 400"-# ─────────────────────────────────────────────────────────────────-start_test "tabs: bad action → 400"+ pt_post /tab '{"action":"explode"}'+ assert_http_status "400" "rejects bad action"-pt_post /tab '{"action":"explode"}'-assert_http_status "400" "rejects bad action"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "tabs: new tab returns tabId"-# ─────────────────────────────────────────────────────────────────-start_test "tabs: new tab returns tabId"+ pt_post /tab '{"action":"new","url":"about:blank"}'+ assert_ok "new tab"+ assert_tab_id "new tab returns tabId"-pt_post /tab '{"action":"new","url":"about:blank"}'-assert_ok "new tab"-assert_tab_id "new tab returns tabId"+ pt_post /close "{\"tabId\":\"${TAB_ID}\"}"-pt_post /close "{\"tabId\":\"${TAB_ID}\"}"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "tabs: nonexistent tab → 404"-# ─────────────────────────────────────────────────────────────────-start_test "tabs: nonexistent tab → 404"+ FAKE_TAB="A25658CE1BA82659EBE9C93C46CEE63A"-FAKE_TAB="A25658CE1BA82659EBE9C93C46CEE63A"+ pt_post "/tabs/${FAKE_TAB}/navigate" "{\"url\":\"${FIXTURES_URL}/index.html\"}"+ assert_http_status "404" "navigate on fake tab"-pt_post "/tabs/${FAKE_TAB}/navigate" "{\"url\":\"${FIXTURES_URL}/index.html\"}"-assert_http_status "404" "navigate on fake tab"+ pt_get "/tabs/${FAKE_TAB}/snapshot"+ assert_http_status "404" "snapshot on fake tab"-pt_get "/tabs/${FAKE_TAB}/snapshot"-assert_http_status "404" "snapshot on fake tab"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "tab lock: lock and unlock"-# ─────────────────────────────────────────────────────────────────-start_test "tab lock: lock and unlock"+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"+ TAB_ID=$(get_tab_id)-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"-TAB_ID=$(get_tab_id)+ pt_post /lock -d "{\"tabId\":\"${TAB_ID}\",\"owner\":\"test-agent\"}"+ assert_ok "lock tab"+ assert_json_eq "$RESULT" '.locked' 'true' "tab is locked"+ assert_json_eq "$RESULT" '.owner' 'test-agent' "owner matches"-pt_post /lock -d "{\"tabId\":\"${TAB_ID}\",\"owner\":\"test-agent\"}"-assert_ok "lock tab"-assert_json_eq "$RESULT" '.locked' 'true' "tab is locked"-assert_json_eq "$RESULT" '.owner' 'test-agent' "owner matches"+ pt_post /unlock -d "{\"tabId\":\"${TAB_ID}\",\"owner\":\"test-agent\"}"+ assert_ok "unlock tab"+ assert_json_eq "$RESULT" '.unlocked' 'true' "tab is unlocked"-pt_post /unlock -d "{\"tabId\":\"${TAB_ID}\",\"owner\":\"test-agent\"}"-assert_ok "unlock tab"-assert_json_eq "$RESULT" '.unlocked' 'true' "tab is unlocked"+ end_test-end_test+ # ─────────────────────────────────────────────────────────────────+ start_test "tab lock: wrong owner cannot unlock"-# ─────────────────────────────────────────────────────────────────-start_test "tab lock: wrong owner cannot unlock"+ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"+ TAB_ID=$(get_tab_id)-pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"-TAB_ID=$(get_tab_id)+ pt_post /lock -d "{\"tabId\":\"${TAB_ID}\",\"owner\":\"agent-a\"}"+ assert_ok "lock tab"-pt_post /lock -d "{\"tabId\":\"${TAB_ID}\",\"owner\":\"agent-a\"}"-assert_ok "lock tab"+ pt_post /unlock -d "{\"tabId\":\"${TAB_ID}\",\"owner\":\"agent-b\"}"+ assert_not_ok "wrong owner rejected"-pt_post /unlock -d "{\"tabId\":\"${TAB_ID}\",\"owner\":\"agent-b\"}"-assert_not_ok "wrong owner rejected"+ pt_post /unlock -d "{\"tabId\":\"${TAB_ID}\",\"owner\":\"agent-a\"}"-pt_post /unlock -d "{\"tabId\":\"${TAB_ID}\",\"owner\":\"agent-a\"}"--end_test+ end_test+}-E2E_SERVER="$ORIG_URL"+with_server "$E2E_SECURE_SERVER" secure_server_testswait_for_handoff_status() {local tab_id="$1" wanted="$2" attempts="${3:-30}"diff --git a/tests/e2e/scenarios/cli/dashboard-basic.sh b/tests/e2e/scenarios/cli/dashboard-basic.shindex 425c61ab..30b9cc26 100644--- a/tests/e2e/scenarios/cli/dashboard-basic.sh+++ b/tests/e2e/scenarios/cli/dashboard-basic.sh@@ -7,15 +7,6 @@ source "${GROUP_DIR}/../../helpers/cli.sh"# ─────────────────────────────────────────────────────────────────start_test "pinchtab dashboard --no-open prints URL"-config_setup() {- TMPDIR=$(mktemp -d)- CFG="$TMPDIR/config.json"-}--config_cleanup() {- rm -rf "$TMPDIR"-}-config_setupcat > "$CFG" <<'EOF'{diff --git a/tests/e2e/scenarios/cli/system-basic.sh b/tests/e2e/scenarios/cli/system-basic.shindex 292d1eca..10303da3 100644--- a/tests/e2e/scenarios/cli/system-basic.sh+++ b/tests/e2e/scenarios/cli/system-basic.sh@@ -24,19 +24,6 @@ end_test# Note: instance start is implicitly tested (server is running)-config_setup() {- TMPDIR=$(mktemp -d)- CFG="$TMPDIR/config.json"-}--config_cleanup() {- rm -rf "$TMPDIR"-}--config_init() {- PINCHTAB_CONFIG="$CFG" HOME="$TMPDIR" pt_ok config init-}-assert_config_field() {local path="$1" expected="$2" desc="$3"local actualdiff --git a/tests/e2e/scenarios/cli/system-extended.sh b/tests/e2e/scenarios/cli/system-extended.shindex d7d80410..ebfc2322 100644--- a/tests/e2e/scenarios/cli/system-extended.sh+++ b/tests/e2e/scenarios/cli/system-extended.sh@@ -7,10 +7,7 @@ source "${GROUP_DIR}/../../helpers/cli.sh"# ─────────────────────────────────────────────────────────────────start_test "pinchtab transport failure exits non-zero"-ORIGINAL_E2E_SERVER="$E2E_SERVER"-E2E_SERVER="http://127.0.0.1:1"-pt health-E2E_SERVER="$ORIGINAL_E2E_SERVER"+with_server "http://127.0.0.1:1" pt healthassert_exit_code 1 "connection failure is reported to automation"end_testdiff --git a/tests/e2e/scenarios/infra/auth-extended.sh b/tests/e2e/scenarios/infra/auth-extended.shindex d8c10ab7..25e9aed0 100644--- a/tests/e2e/scenarios/infra/auth-extended.sh+++ b/tests/e2e/scenarios/infra/auth-extended.sh@@ -8,7 +8,9 @@ AUTH_COOKIE_FILE="/tmp/pinchtab-auth-cookie-$$.txt"AUTH_HEADERS_FILE="/tmp/pinchtab-auth-headers-$$.txt"AUTH_BODY_FILE="/tmp/pinchtab-auth-body-$$.txt"-trap 'rm -f "$AUTH_COOKIE_FILE" "$AUTH_HEADERS_FILE" "$AUTH_BODY_FILE"' EXIT+scenario_cleanup() {+ rm -f "$AUTH_COOKIE_FILE" "$AUTH_HEADERS_FILE" "$AUTH_BODY_FILE"+}auth_reset_session() {rm -f "$AUTH_COOKIE_FILE" "$AUTH_HEADERS_FILE" "$AUTH_BODY_FILE"@@ -284,50 +286,48 @@ end_test# ─────────────────────────────────────────────────────────────────start_test "auth: screencast websocket rejects bad origin for cookie session"-OLD_SERVER="$E2E_SERVER"-E2E_SERVER="${E2E_FULL_SERVER:-$E2E_SERVER}"--pt_get /instances-SCREENCAST_INST_ID=$(echo "$RESULT" | jq -r '.[0].id')-assert_ok "list instances for screencast"--pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/table.html\"}"-SCREENCAST_TAB_ID=$(get_tab_id)-assert_ok "navigate for screencast auth boundary"--auth_reset_session-auth_post_json /api/auth/login "{\"token\":\"${E2E_SERVER_TOKEN}\"}"-assert_http_status 200 "login succeeds"-auth_ws_get "/instances/${SCREENCAST_INST_ID}/proxy/screencast?tabId=${SCREENCAST_TAB_ID}" -H "Origin: http://evil.example"-assert_http_status 403 "bad origin websocket upgrade blocked"-assert_contains "$RESULT" "origin_forbidden" "websocket origin error returned"+screencast_bad_origin_checks() {+ pt_get /instances+ SCREENCAST_INST_ID=$(echo "$RESULT" | jq -r '.[0].id')+ assert_ok "list instances for screencast"++ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/table.html\"}"+ SCREENCAST_TAB_ID=$(get_tab_id)+ assert_ok "navigate for screencast auth boundary"++ auth_reset_session+ auth_post_json /api/auth/login "{\"token\":\"${E2E_SERVER_TOKEN}\"}"+ assert_http_status 200 "login succeeds"+ auth_ws_get "/instances/${SCREENCAST_INST_ID}/proxy/screencast?tabId=${SCREENCAST_TAB_ID}" -H "Origin: http://evil.example"+ assert_http_status 403 "bad origin websocket upgrade blocked"+ assert_contains "$RESULT" "origin_forbidden" "websocket origin error returned"+}-E2E_SERVER="$OLD_SERVER"+with_server "${E2E_FULL_SERVER:-$E2E_SERVER}" screencast_bad_origin_checksend_test# ─────────────────────────────────────────────────────────────────start_test "auth: screencast websocket allows same-origin cookie session"-OLD_SERVER="$E2E_SERVER"-E2E_SERVER="${E2E_FULL_SERVER:-$E2E_SERVER}"--pt_get /instances-SCREENCAST_INST_ID=$(echo "$RESULT" | jq -r '.[0].id')-assert_ok "list instances for same-origin screencast"--pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/table.html\"}"-SCREENCAST_TAB_ID=$(get_tab_id)-assert_ok "navigate for same-origin screencast"--auth_reset_session-auth_post_json /api/auth/login "{\"token\":\"${E2E_SERVER_TOKEN}\"}"-assert_http_status 200 "login succeeds"-auth_ws_get "/instances/${SCREENCAST_INST_ID}/proxy/screencast?tabId=${SCREENCAST_TAB_ID}" -H "Origin: ${E2E_SERVER}"-assert_http_status 101 "same-origin websocket upgrade allowed"-assert_auth_header_contains "101 Switching Protocols" "websocket handshake completed"+screencast_same_origin_checks() {+ pt_get /instances+ SCREENCAST_INST_ID=$(echo "$RESULT" | jq -r '.[0].id')+ assert_ok "list instances for same-origin screencast"++ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/table.html\"}"+ SCREENCAST_TAB_ID=$(get_tab_id)+ assert_ok "navigate for same-origin screencast"++ auth_reset_session+ auth_post_json /api/auth/login "{\"token\":\"${E2E_SERVER_TOKEN}\"}"+ assert_http_status 200 "login succeeds"+ auth_ws_get "/instances/${SCREENCAST_INST_ID}/proxy/screencast?tabId=${SCREENCAST_TAB_ID}" -H "Origin: ${E2E_SERVER}"+ assert_http_status 101 "same-origin websocket upgrade allowed"+ assert_auth_header_contains "101 Switching Protocols" "websocket handshake completed"+}-E2E_SERVER="$OLD_SERVER"+with_server "${E2E_FULL_SERVER:-$E2E_SERVER}" screencast_same_origin_checksend_testdiff --git a/tests/e2e/scenarios/infra/browser-routing-extended.sh b/tests/e2e/scenarios/infra/browser-routing-extended.shindex 9e671f3e..e15728eb 100755--- a/tests/e2e/scenarios/infra/browser-routing-extended.sh+++ b/tests/e2e/scenarios/infra/browser-routing-extended.sh@@ -34,31 +34,19 @@ if ! requires_providers; thenfighostchrome_get() {- local old="$E2E_SERVER"- E2E_SERVER="$E2E_SERVER_GHOSTCHROME"- pt_get "$1"- E2E_SERVER="$old"+ with_server "$E2E_SERVER_GHOSTCHROME" pt_get "$1"}ghostchrome_post() {- local old="$E2E_SERVER"- E2E_SERVER="$E2E_SERVER_GHOSTCHROME"- pt_post "$1" "$2"- E2E_SERVER="$old"+ with_server "$E2E_SERVER_GHOSTCHROME" pt_post "$1" "$2"}secure_get() {- local old="$E2E_SERVER"- E2E_SERVER="$E2E_SECURE_SERVER"- pt_get "$1"- E2E_SERVER="$old"+ with_server "$E2E_SECURE_SERVER" pt_get "$1"}secure_post() {- local old="$E2E_SERVER"- E2E_SERVER="$E2E_SECURE_SERVER"- pt_post "$1" "$2"- E2E_SERVER="$old"+ with_server "$E2E_SECURE_SERVER" pt_post "$1" "$2"}# ═══════════════════════════════════════════════════════════════════diff --git a/tests/e2e/scenarios/infra/idpi-extended.sh b/tests/e2e/scenarios/infra/idpi-extended.shindex f6c4cf1f..576c955e 100644--- a/tests/e2e/scenarios/infra/idpi-extended.sh+++ b/tests/e2e/scenarios/infra/idpi-extended.sh@@ -12,21 +12,11 @@ GROUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"source "${GROUP_DIR}/../../helpers/api.sh"secure_get() {- local path="$1"- shift- local old_url="$E2E_SERVER"- E2E_SERVER="$E2E_SECURE_SERVER"- pt_get "$path" "$@"- E2E_SERVER="$old_url"+ with_server "$E2E_SECURE_SERVER" pt_get "$@"}secure_post() {- local path="$1"- shift- local old_url="$E2E_SERVER"- E2E_SERVER="$E2E_SECURE_SERVER"- pt_post "$path" "$@"- E2E_SERVER="$old_url"+ with_server "$E2E_SECURE_SERVER" pt_post "$@"}# ═══════════════════════════════════════════════════════════════════diff --git a/tests/e2e/scenarios/infra/screencast-cloak-diag.sh b/tests/e2e/scenarios/infra/screencast-cloak-diag.shindex 758bab14..da67c14f 100644--- a/tests/e2e/scenarios/infra/screencast-cloak-diag.sh+++ b/tests/e2e/scenarios/infra/screencast-cloak-diag.sh@@ -141,77 +141,76 @@ if [ -n "${E2E_FULL_SERVER:-}" ]; thenstart_test "screencast-diag: dashboard proxy screencast (polling)"-SAVED_SERVER="$E2E_SERVER"-E2E_SERVER="${E2E_FULL_SERVER}"--pt_get "/instances/tabs?fresh=1"-assert_ok "list tabs for proxy screencast"--INST_ID=$(echo "$RESULT" | jq -r '.[] | select((.url // "") | contains("evaluate.html")) | .instanceId // empty' | head -n 1)-PROXY_TAB_ID=$(echo "$RESULT" | jq -r '.[] | select((.url // "") | contains("evaluate.html")) | .id // empty' | head -n 1)--if [ -n "${INST_ID}" ] && [ -n "${PROXY_TAB_ID}" ]; then- pass_assert "found instance ${INST_ID} with tab ${PROXY_TAB_ID:0:12}..."-- PROXY_WS_HEADERS=$(mktemp)- PROXY_WS_BODY=$(mktemp)-- (- e2e_curl -s --http1.1 \- -X GET \- "${E2E_SERVER}/instances/${INST_ID}/proxy/screencast?tabId=${PROXY_TAB_ID}&fps=5&everyNthFrame=1&quality=20&maxWidth=320" \- -D "${PROXY_WS_HEADERS}" \- -o "${PROXY_WS_BODY}" \- -H "Origin: ${E2E_SERVER}" \- -H "Connection: Upgrade" \- -H "Upgrade: websocket" \- -H "Sec-WebSocket-Version: 13" \- -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" \- --max-time 15 >/dev/null 2>&1 || true- ) &- PROXY_WS_PID=$!-- PROXY_WS_STATUS=""- for _ in $(seq 1 20); do- PROXY_WS_STATUS=$(grep '^HTTP/' "${PROXY_WS_HEADERS}" | tail -n 1 | awk '{print $2}')- if [ -n "${PROXY_WS_STATUS}" ]; then- break+proxy_screencast_checks() {+ pt_get "/instances/tabs?fresh=1"+ assert_ok "list tabs for proxy screencast"++ INST_ID=$(echo "$RESULT" | jq -r '.[] | select((.url // "") | contains("evaluate.html")) | .instanceId // empty' | head -n 1)+ PROXY_TAB_ID=$(echo "$RESULT" | jq -r '.[] | select((.url // "") | contains("evaluate.html")) | .id // empty' | head -n 1)++ if [ -n "${INST_ID}" ] && [ -n "${PROXY_TAB_ID}" ]; then+ pass_assert "found instance ${INST_ID} with tab ${PROXY_TAB_ID:0:12}..."++ PROXY_WS_HEADERS=$(mktemp)+ PROXY_WS_BODY=$(mktemp)++ (+ e2e_curl -s --http1.1 \+ -X GET \+ "${E2E_SERVER}/instances/${INST_ID}/proxy/screencast?tabId=${PROXY_TAB_ID}&fps=5&everyNthFrame=1&quality=20&maxWidth=320" \+ -D "${PROXY_WS_HEADERS}" \+ -o "${PROXY_WS_BODY}" \+ -H "Origin: ${E2E_SERVER}" \+ -H "Connection: Upgrade" \+ -H "Upgrade: websocket" \+ -H "Sec-WebSocket-Version: 13" \+ -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" \+ --max-time 15 >/dev/null 2>&1 || true+ ) &+ PROXY_WS_PID=$!++ PROXY_WS_STATUS=""+ for _ in $(seq 1 20); do+ PROXY_WS_STATUS=$(grep '^HTTP/' "${PROXY_WS_HEADERS}" | tail -n 1 | awk '{print $2}')+ if [ -n "${PROXY_WS_STATUS}" ]; then+ break+ fi+ sleep 0.2+ done++ if [ "${PROXY_WS_STATUS}" = "101" ]; then+ pass_assert "proxy screencast WS upgraded (101)"+ else+ fail_assert "proxy screencast WS upgrade failed (status: ${PROXY_WS_STATUS:-none})"fi- sleep 0.2- done- if [ "${PROXY_WS_STATUS}" = "101" ]; then- pass_assert "proxy screencast WS upgraded (101)"- else- fail_assert "proxy screencast WS upgrade failed (status: ${PROXY_WS_STATUS:-none})"- fi+ PROXY_FRAME_BYTES=0+ PROXY_START=$(get_time_ms)+ for _ in $(seq 1 40); do+ PROXY_FRAME_BYTES=$(wc -c < "${PROXY_WS_BODY}" | tr -d '[:space:]')+ if [ "${PROXY_FRAME_BYTES}" -gt 0 ]; then+ break+ fi+ sleep 0.2+ done+ PROXY_END=$(get_time_ms)+ PROXY_LATENCY=$((PROXY_END - PROXY_START))- PROXY_FRAME_BYTES=0- PROXY_START=$(get_time_ms)- for _ in $(seq 1 40); do- PROXY_FRAME_BYTES=$(wc -c < "${PROXY_WS_BODY}" | tr -d '[:space:]')if [ "${PROXY_FRAME_BYTES}" -gt 0 ]; then- break+ pass_assert "proxy first frame arrived (${PROXY_FRAME_BYTES} bytes in ${PROXY_LATENCY}ms)"+ else+ fail_assert "proxy screencast: no frames within 8s — frames lost in proxy hop"fi- sleep 0.2- done- PROXY_END=$(get_time_ms)- PROXY_LATENCY=$((PROXY_END - PROXY_START))- if [ "${PROXY_FRAME_BYTES}" -gt 0 ]; then- pass_assert "proxy first frame arrived (${PROXY_FRAME_BYTES} bytes in ${PROXY_LATENCY}ms)"+ kill "${PROXY_WS_PID}" 2>/dev/null || true+ wait "${PROXY_WS_PID}" 2>/dev/null || true+ rm -f "${PROXY_WS_HEADERS}" "${PROXY_WS_BODY}"else- fail_assert "proxy screencast: no frames within 8s — frames lost in proxy hop"+ skip_assert "no evaluate.html tab found — cannot test proxy screencast"fi+}- kill "${PROXY_WS_PID}" 2>/dev/null || true- wait "${PROXY_WS_PID}" 2>/dev/null || true- rm -f "${PROXY_WS_HEADERS}" "${PROXY_WS_BODY}"-else- skip_assert "no evaluate.html tab found — cannot test proxy screencast"-fi--E2E_SERVER="${SAVED_SERVER}"+with_server "${E2E_FULL_SERVER}" proxy_screencast_checksend_testdiff --git a/tests/e2e/scenarios/infra/security-extended.sh b/tests/e2e/scenarios/infra/security-extended.shindex d6a64e3d..4c155190 100644--- a/tests/e2e/scenarios/infra/security-extended.sh+++ b/tests/e2e/scenarios/infra/security-extended.sh@@ -5,21 +5,11 @@ GROUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"source "${GROUP_DIR}/../../helpers/api.sh"secure_get() {- local path="$1"- shift- local old_url="$E2E_SERVER"- E2E_SERVER="$E2E_SECURE_SERVER"- pt_get "$path" "$@"- E2E_SERVER="$old_url"+ with_server "$E2E_SECURE_SERVER" pt_get "$@"}secure_post() {- local path="$1"- shift- local old_url="$E2E_SERVER"- E2E_SERVER="$E2E_SECURE_SERVER"- pt_post "$path" "$@"- E2E_SERVER="$old_url"+ with_server "$E2E_SECURE_SERVER" pt_post "$@"}start_test "security: evaluate BLOCKED when disabled"diff --git a/tests/e2e/scenarios/infra/security-smoke.sh b/tests/e2e/scenarios/infra/security-smoke.shindex e108352b..cc29137c 100644--- a/tests/e2e/scenarios/infra/security-smoke.sh+++ b/tests/e2e/scenarios/infra/security-smoke.sh@@ -5,21 +5,11 @@ GROUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"source "${GROUP_DIR}/../../helpers/api.sh"secure_get() {- local path="$1"- shift- local old_url="$E2E_SERVER"- E2E_SERVER="$E2E_SECURE_SERVER"- pt_get "$path" "$@"- E2E_SERVER="$old_url"+ with_server "$E2E_SECURE_SERVER" pt_get "$@"}secure_post() {- local path="$1"- shift- local old_url="$E2E_SERVER"- E2E_SERVER="$E2E_SECURE_SERVER"- pt_post "$path" "$@"- E2E_SERVER="$old_url"+ with_server "$E2E_SECURE_SERVER" pt_post "$@"}PIVOT_URL="http://pivot-target:80/index.html"diff --git a/tests/e2e/scenarios/infra/stealth-extended.sh b/tests/e2e/scenarios/infra/stealth-extended.shindex a55eeb48..f020c8a5 100644--- a/tests/e2e/scenarios/infra/stealth-extended.sh+++ b/tests/e2e/scenarios/infra/stealth-extended.sh@@ -560,38 +560,37 @@ echo ""echo -e "${BLUE}Testing FULL stealth mode (restrictive instance)${NC}"echo -e "${YELLOW}Note: evaluate disabled on restrictive instance, testing navigation only${NC}"-ORIG_URL="$E2E_SERVER"-E2E_SERVER="$E2E_SECURE_SERVER"+full_stealth_checks() {+ start_test "bot-detect-full: can navigate with full stealth"-start_test "bot-detect-full: can navigate with full stealth"--pt_post /navigate "{\"url\":\"${FIXTURES_URL}/bot-detect.html\"}"-assert_ok "navigate to bot-detect fixture (full stealth)"+ pt_post /navigate "{\"url\":\"${FIXTURES_URL}/bot-detect.html\"}"+ assert_ok "navigate to bot-detect fixture (full stealth)"-TAB_ID=$(echo "$RESULT" | jq -r '.tabId // empty')-if [ -n "$TAB_ID" ]; then- echo -e " ${GREEN}✓${NC} Got tabId: $TAB_ID"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${RED}✗${NC} No tabId in response"- ((ASSERTIONS_FAILED++)) || true-fi+ TAB_ID=$(echo "$RESULT" | jq -r '.tabId // empty')+ if [ -n "$TAB_ID" ]; then+ echo -e " ${GREEN}✓${NC} Got tabId: $TAB_ID"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} No tabId in response"+ ((ASSERTIONS_FAILED++)) || true+ fi-end_test+ end_test-start_test "bot-detect-full: page title loaded correctly"+ start_test "bot-detect-full: page title loaded correctly"-TITLE=$(echo "$RESULT" | jq -r '.title // empty')-if [ "$TITLE" = "Bot Detection Tests" ]; then- echo -e " ${GREEN}✓${NC} Page title: $TITLE"- ((ASSERTIONS_PASSED++)) || true-else- echo -e " ${YELLOW}⚠${NC} Unexpected title: $TITLE"-fi+ TITLE=$(echo "$RESULT" | jq -r '.title // empty')+ if [ "$TITLE" = "Bot Detection Tests" ]; then+ echo -e " ${GREEN}✓${NC} Page title: $TITLE"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${YELLOW}⚠${NC} Unexpected title: $TITLE"+ fi-end_test+ end_test+}-E2E_SERVER="$ORIG_URL"+with_server "$E2E_SECURE_SERVER" full_stealth_checksif [[ "${BASH_SOURCE[0]}" == "${0}" ]]; thenfinish_suite