High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
test(e2e): capture, annotate, screenshot --annotate, find and a semantic action publish the vocab token over HTTP and the CLI captures it so the next click is not refused (PIN-424)
Luigi Agosti889fcf72e421
diff --git a/tests/e2e/scenarios/api/vocab-reepoch-basic.sh b/tests/e2e/scenarios/api/vocab-reepoch-basic.shnew file mode 100755index 00000000..6e21ad5c--- /dev/null+++ b/tests/e2e/scenarios/api/vocab-reepoch-basic.sh@@ -0,0 +1,133 @@+#!/bin/bash+# vocab-reepoch-basic.sh — every response that re-epochs a tab's ref cache+# publishes the new vocabulary token (X-PinchTab-Vocab) and the tab it belongs+# to (X-PinchTab-Tab-Id): /find, /tabs/{id}/find, /annotate,+# /screenshot?annotate and an action whose semantic selector refreshed the+# cache. The published token is the one the tab's next /snapshot reports, an+# action echoing it is accepted, and a stale one is refused 409.++GROUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+source "${GROUP_DIR}/../../helpers/api.sh"++PAGE="${FIXTURES_URL}/buttons.html"++# vocab_request METHOD PATH [curl args...] — like pinchtab, plus HDR_VOCAB and+# HDR_TAB from the response headers.+vocab_request() {+ local hdrs+ hdrs=$(mktemp)+ pinchtab "$@" -D "$hdrs"+ HDR_VOCAB=$(grep -i '^X-PinchTab-Vocab:' "$hdrs" | cut -d' ' -f2 | tr -d '\r')+ HDR_TAB=$(grep -i '^X-PinchTab-Tab-Id:' "$hdrs" | cut -d' ' -f2 | tr -d '\r')+ rm -f "$hdrs"+}++fresh_page() {+ pt_post /navigate -d "{\"url\":\"${PAGE}\"}"+ assert_ok "navigate to buttons.html"+ TAB_ID=$(echo "$RESULT" | jq -r '.tabId')+}++assert_published() {+ local what="$1"+ if [ -n "$HDR_VOCAB" ]; then+ pass_assert "$what publishes X-PinchTab-Vocab $HDR_VOCAB"+ else+ fail_assert "$what publishes no X-PinchTab-Vocab"+ fi+ if [ "$HDR_TAB" = "$TAB_ID" ]; then+ pass_assert "$what X-PinchTab-Tab-Id names the navigated tab"+ else+ fail_assert "$what X-PinchTab-Tab-Id '$HDR_TAB', want '$TAB_ID'"+ fi+}++# assert_token_is_live TOKEN REF WHAT — the next snapshot reports TOKEN, a+# click echoing it is accepted and a stale token is refused 409.+assert_token_is_live() {+ local token="$1" ref="$2" what="$3"+ vocab_request GET "/snapshot?filter=interactive"+ assert_ok "snapshot after $what"+ if [ "$HDR_VOCAB" = "$token" ]; then+ pass_assert "next /snapshot reports the token $what published"+ else+ fail_assert "next /snapshot reports '$HDR_VOCAB', $what published '$token'"+ fi++ if [ -z "$ref" ] || [ "$ref" = "null" ]; then+ fail_assert "$what returned no ref for Increment"+ return+ fi+ pt_post /action -d "{\"kind\":\"click\",\"ref\":\"${ref}\",\"vocab\":\"stale-pre-${what// /-}-token\"}"+ assert_http_status 409 "a pre-$what token is refused"+ pt_post /action -d "{\"kind\":\"click\",\"ref\":\"${ref}\",\"vocab\":\"${token}\"}"+ assert_ok "click $ref echoing the token $what published is accepted"+}++# ─────────────────────────────────────────────────────────────────+start_test "vocab: POST /find on a fresh page publishes the token it minted"++fresh_page+vocab_request POST /find -d '{"query":"Increment"}'+assert_ok "find Increment"+assert_published "/find"+assert_token_is_live "$HDR_VOCAB" "$(echo "$RESULT" | jq -r '.best_ref')" "find"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "vocab: POST /tabs/{id}/find on a fresh page publishes the token it minted"++fresh_page+vocab_request POST "/tabs/${TAB_ID}/find" -d '{"query":"Increment"}'+assert_ok "tab-scoped find Increment"+assert_published "/tabs/{id}/find"+assert_token_is_live "$HDR_VOCAB" "$(echo "$RESULT" | jq -r '.best_ref')" "tab find"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "vocab: GET /annotate on a fresh page publishes the token it minted"++fresh_page+vocab_request GET /annotate+assert_ok "annotate"+assert_published "/annotate"+TOKEN="$HDR_VOCAB"+REF=$(echo "$RESULT" | jq -r 'first(.annotations[] | select(.name == "Increment") | .ref) // empty')+pt_get "/annotate?clear=true"+assert_token_is_live "$TOKEN" "$REF" "annotate"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "vocab: GET /screenshot?annotate on a fresh page publishes the token it minted"++fresh_page+vocab_request GET "/screenshot?annotate=true&format=png"+assert_ok "annotated screenshot"+assert_published "/screenshot?annotate"+TOKEN="$HDR_VOCAB"+REF=$(echo "$RESULT" | jq -r 'first(.annotations[] | select(.name == "Increment") | .ref) // empty')+assert_token_is_live "$TOKEN" "$REF" "annotated screenshot"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "vocab: an action whose semantic selector refreshed the cache publishes the token"++fresh_page+vocab_request POST /action -d '{"kind":"hover","selector":"semantic:Increment"}'+assert_ok "hover semantic:Increment"+assert_published "semantic hover"+TOKEN="$HDR_VOCAB"+vocab_request POST /find -d '{"query":"Increment"}'+REF=$(echo "$RESULT" | jq -r '.best_ref')+if [ "$HDR_VOCAB" = "$TOKEN" ]; then+ pass_assert "a find on the same DOM keeps the hover's token"+else+ fail_assert "find published '$HDR_VOCAB' after the hover published '$TOKEN'"+fi+assert_token_is_live "$TOKEN" "$REF" "semantic hover"++end_testdiff --git a/tests/e2e/scenarios/cli/vocab-reepoch-basic.sh b/tests/e2e/scenarios/cli/vocab-reepoch-basic.shnew file mode 100755index 00000000..d3f3fd3d--- /dev/null+++ b/tests/e2e/scenarios/cli/vocab-reepoch-basic.sh@@ -0,0 +1,128 @@+#!/bin/bash+# vocab-reepoch-basic.sh — CLI: every verb that can re-epoch a tab's ref cache+# (capture, annotate, screenshot --annotate, find in all three render paths, and+# an action with a semantic selector) captures the vocabulary token it minted,+# so the next `click <ref>` echoes it instead of a stale one.+#+# Each test files a token with `snap`, navigates again (which drops the tab's+# ref cache), runs the verb, then clicks with no snap in between. Without the+# capture the click echoes the snap's token and is refused 409 vocab_superseded.++GROUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+source "${GROUP_DIR}/../../helpers/cli.sh"++PAGE="${FIXTURES_URL}/buttons.html"++stale_token_on_fresh_page() {+ pt_ok nav "$PAGE"+ pt_ok snap+ pt_ok nav "$PAGE"+}++assert_ref() {+ local ref="$1" verb="$2"+ if [ -n "$ref" ] && [ "$ref" != "null" ]; then+ pass_assert "$verb returned ref $ref for Increment"+ else+ fail_assert "$verb returned no ref for Increment"+ fi+}++click_ref_increments() {+ local ref="$1" verb="$2"+ pt click "$ref"+ if [ "$PT_CODE" -eq 0 ] && ! grep -q "superseded" <<<"$PT_ERR$PT_OUT"; then+ pass_assert "click $ref after $verb accepted with no snap in between"+ else+ fail_assert "click $ref after $verb refused (exit $PT_CODE): $PT_ERR"+ fi+ pt_ok eval "document.getElementById('count').textContent"+ assert_output_contains "1" "click after $verb reached the Increment button"+}++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab find --ref-only then click on a fresh page"++stale_token_on_fresh_page+pt_ok find "Increment" --ref-only+REF=$(head -n1 <<<"$PT_OUT" | tr -d '[:space:]')+assert_ref "$REF" "find --ref-only"+click_ref_increments "$REF" "find --ref-only"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab find --json then click on a fresh page"++stale_token_on_fresh_page+pt_ok find "Increment" --json+REF=$(jq -r '.best_ref // empty' <<<"$PT_OUT")+assert_ref "$REF" "find --json"+click_ref_increments "$REF" "find --json"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab find (terse) then click on a fresh page"++stale_token_on_fresh_page+pt_ok find "Increment"+REF=$(grep -m1 'Increment' <<<"$PT_OUT" | awk '{print $1}')+assert_ref "$REF" "find (terse)"+click_ref_increments "$REF" "find (terse)"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab capture then click on a fresh page"++stale_token_on_fresh_page+OUT_FILE="/tmp/e2e-vocab-capture.jpg"+pt_ok capture --json --wait none -o "$OUT_FILE"+rm -f "$OUT_FILE"+REF=$(jq -r 'first(.snapshot.nodes[] | select(.name == "Increment") | .ref) // empty' <<<"$PT_OUT")+assert_ref "$REF" "capture"+click_ref_increments "$REF" "capture"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab annotate then click on a fresh page"++stale_token_on_fresh_page+pt_ok annotate+REF=$(grep -m1 '"Increment"' <<<"$PT_OUT" | awk '{print $1}')+assert_ref "$REF" "annotate"+click_ref_increments "$REF" "annotate"+pt annotate --clear++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab screenshot --annotate then click on a fresh page"++stale_token_on_fresh_page+OUT_FILE="/tmp/e2e-vocab-annotated.png"+pt_ok screenshot --annotate -o "$OUT_FILE"+rm -f "$OUT_FILE"+REF=$(grep -m1 '"Increment"' <<<"$PT_OUT" | awk '{print $2}')+assert_ref "$REF" "screenshot --annotate"+click_ref_increments "$REF" "screenshot --annotate"++end_test++# ─────────────────────────────────────────────────────────────────+# The semantic hover re-epochs the dropped cache with the interactive filter, so+# the ref comes from an interactive snap of the same DOM taken before the+# second nav; the token the click must echo is the one the hover minted.+start_test "pinchtab hover semantic:<name> then click on a fresh page"++pt_ok nav "$PAGE"+pt_ok snap --interactive --compact=false+REF=$(find_ref_by_name "Increment" "$PT_OUT")+assert_ref "$REF" "snap --interactive"+pt_ok nav "$PAGE"+pt_ok hover "semantic:Increment"+click_ref_increments "$REF" "hover semantic:Increment"++end_testdiff --git a/tests/e2e/scenarios/manifest.json b/tests/e2e/scenarios/manifest.jsonindex e697d155..9876cc8b 100644--- a/tests/e2e/scenarios/manifest.json+++ b/tests/e2e/scenarios/manifest.json@@ -1,5 +1,17 @@{"scenarios": {+ "api/vocab-reepoch-basic.sh": {+ "tags": [+ "vocab",+ "pr"+ ]+ },+ "cli/vocab-reepoch-basic.sh": {+ "tags": [+ "vocab",+ "pr"+ ]+ },"api/wait-url-basic.sh": {"tags": ["wait",