High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
test(e2e): memory scenarios assert numeric usage, the tab snapshot route, the /health capability listing, and a 413 over the snapshot cap on the medium server (PIN-398)
Luigi Agosti43c13f94efb8
diff --git a/tests/e2e/config/pinchtab-medium-permissive.json b/tests/e2e/config/pinchtab-medium-permissive.jsonindex 9577726b..80cd67e2 100644--- a/tests/e2e/config/pinchtab-medium-permissive.json+++ b/tests/e2e/config/pinchtab-medium-permissive.json@@ -38,6 +38,8 @@"allowCookies": true,"allowUpload": true,"allowStateExport": true,+ "allowMemory": true,+ "memorySnapshotMaxBytes": 65536,"allowedDomains": ["localhost","127.0.0.1",diff --git a/tests/e2e/scenarios/api/memory-basic.sh b/tests/e2e/scenarios/api/memory-basic.shindex 5c511920..ebf1d882 100644--- a/tests/e2e/scenarios/api/memory-basic.sh+++ b/tests/e2e/scenarios/api/memory-basic.sh@@ -18,8 +18,9 @@ TAB_ID=$(echo "$RESULT" | jq -r '.tabId')pt_get "/memory?tabId=${TAB_ID}&gc=true"assert_ok "baseline read with gc"for key in usedJSHeapSize totalJSHeapSize jsHeapSizeLimit documents nodes listeners frames; do- assert_json_exists "$RESULT" ".${key}" "usage reports ${key}"+ assert_json_jq "$RESULT" "(.${key} | type) == \"number\"" "usage reports numeric ${key}" "${key} missing or not a number"done+assert_json_jq "$RESULT" '.usedJSHeapSize > 0 and .jsHeapSizeLimit >= .totalJSHeapSize' "heap sizes are positive and ordered" "heap sizes missing or out of order"BASELINE=$(echo "$RESULT" | jq -r '.usedJSHeapSize')for i in 1 2 3; do@@ -76,6 +77,21 @@ assert_json_jq "$RESULT" '.nodeCount > 0 and .edgeCount > 0' "summary counts nodassert_json_jq "$RESULT" '([.topBySize[].name] + [.topByCount[].name]) | index("Array") != null' "Array is among the top constructors" "Array missing from the top constructors"assert_json_exists "$RESULT" '.duplicateStrings' "summary lists duplicate strings"+pt_post "/tabs/${TAB_ID}/memory/snapshot" -d '{}'+assert_ok "tab-scoped snapshot route"+assert_json_eq "$RESULT" '.tabId' "$TAB_ID" "tab-scoped snapshot names the tab"+TAB_SNAP_ID=$(echo "$RESULT" | jq -r '.id')+if [ -n "$TAB_SNAP_ID" ] && [ "$TAB_SNAP_ID" != "$SNAP_ID" ]; then+ pass_assert "tab-scoped snapshot got its own id ($TAB_SNAP_ID)"+else+ fail_assert "tab-scoped snapshot id '$TAB_SNAP_ID' is empty or reuses '$SNAP_ID'"+fi++pt_get /health+assert_ok "health"+assert_json_jq "$RESULT" '(.security.enabledSensitiveEndpoints // []) | index("memory") != null' \+ "health lists memory among the enabled capabilities" "health does not list memory although allowMemory is on"+pt_get "/memory/snapshot/heap_does_not_exist/summary"assert_http_status 404 "unknown snapshot id"assert_json_eq "$RESULT" '.code' 'memory_snapshot_not_found' "unknown id is memory_snapshot_not_found"diff --git a/tests/e2e/scenarios/api/memory-extended.sh b/tests/e2e/scenarios/api/memory-extended.shindex 442cee07..d7457cf1 100644--- a/tests/e2e/scenarios/api/memory-extended.sh+++ b/tests/e2e/scenarios/api/memory-extended.sh@@ -1,7 +1,9 @@#!/bin/bash# memory-extended.sh — the memory capability refusal on a server whose config leaves-# security.allowMemory off (pinchtab-secure). memory-basic.sh runs the enabled path on-# the default server; the basic lane has one server, so the second config lives here.+# security.allowMemory off (pinchtab-secure), and the snapshot size cap on a server+# with allowMemory on and security.memorySnapshotMaxBytes at 64 KiB (pinchtab-medium).+# memory-basic.sh runs the enabled path on the default server; the basic lane has one+# server, so the other configs live here.GROUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"source "${GROUP_DIR}/../../helpers/api.sh"@@ -10,19 +12,29 @@ memory_disabled_tests() {# ─────────────────────────────────────────────────────────────────start_test "memory: allowMemory off refuses snapshot and summary, usage still answers"+ pt_get /health+ assert_ok "health"+ assert_json_jq "$RESULT" '(.security.enabledSensitiveEndpoints // []) | index("memory") == null' \+ "health does not list memory as enabled" "health lists memory although allowMemory is off"+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/memory-leak.html\"}"assert_ok "navigate to memory-leak.html"TAB_ID=$(echo "$RESULT" | jq -r '.tabId')pt_get "/memory?tabId=${TAB_ID}"assert_ok "GET /memory is not capability-gated"- assert_json_exists "$RESULT" '.usedJSHeapSize' "usage reports usedJSHeapSize"+ assert_json_jq "$RESULT" '(.usedJSHeapSize | type) == "number" and .usedJSHeapSize > 0' \+ "usage reports a numeric usedJSHeapSize" "usedJSHeapSize missing or not a positive number"pt_post /memory/snapshot -d "{\"tabId\":\"${TAB_ID}\"}"assert_http_status 403 "snapshot refused"assert_json_eq "$RESULT" '.code' 'memory_disabled' "snapshot answers memory_disabled"assert_json_eq "$RESULT" '.details.setting' 'security.allowMemory' "refusal names the setting"+ pt_post "/tabs/${TAB_ID}/memory/snapshot" -d '{}'+ assert_http_status 403 "tab-scoped snapshot refused"+ assert_json_eq "$RESULT" '.code' 'memory_disabled' "tab-scoped snapshot answers memory_disabled"+pt_get "/memory/snapshot/heap_any/summary"assert_http_status 403 "summary refused"assert_json_eq "$RESULT" '.code' 'memory_disabled' "summary answers memory_disabled"@@ -30,4 +42,29 @@ memory_disabled_tests() {end_test}+memory_cap_tests() {+ # ─────────────────────────────────────────────────────────────────+ start_test "memory: a snapshot over security.memorySnapshotMaxBytes is refused with 413"++ pt_get /health+ assert_ok "health"+ assert_json_jq "$RESULT" '(.security.enabledSensitiveEndpoints // []) | index("memory") != null' \+ "health lists memory as enabled" "health does not list memory although allowMemory is on"++ pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/memory-leak.html\"}"+ assert_ok "navigate to memory-leak.html"+ TAB_ID=$(echo "$RESULT" | jq -r '.tabId')++ pt_post /memory/snapshot -d "{\"tabId\":\"${TAB_ID}\"}"+ assert_http_status 413 "snapshot over the 64 KiB cap"+ assert_json_eq "$RESULT" '.code' 'memory_snapshot_too_large' "cap refusal is memory_snapshot_too_large"+ assert_json_eq "$RESULT" '.details.maxBytes' '65536' "refusal names the configured cap"++ pt_get "/memory?tabId=${TAB_ID}"+ assert_ok "tab still answers after the aborted snapshot"++ end_test+}+with_server "$E2E_SECURE_SERVER" memory_disabled_tests+with_server "$E2E_MEDIUM_SERVER" memory_cap_testsdiff --git a/tests/e2e/scenarios/manifest.json b/tests/e2e/scenarios/manifest.jsonindex 91c07d03..c315a131 100644--- a/tests/e2e/scenarios/manifest.json+++ b/tests/e2e/scenarios/manifest.json@@ -585,15 +585,18 @@"services": ["pinchtab","pinchtab-secure",+ "pinchtab-medium","fixtures"],"ready": ["E2E_SERVER",- "E2E_SECURE_SERVER"+ "E2E_SECURE_SERVER",+ "E2E_MEDIUM_SERVER"],"tags": ["memory",- "secure"+ "secure",+ "medium"]},"cli/memory-basic.sh": {