Skip to content

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

test(e2e): extract request scope narrows over HTTP, refuses css/xpath, reports scope_not_found and keeps the IDPI scan, and the CLI covers --json, --explain and --tab (PIN-394)

Luigi Agostia8165c24d1dd
diff --git a/tests/e2e/scenarios/api/extract-basic.sh b/tests/e2e/scenarios/api/extract-basic.sh
index 66c58f60..f9015be3 100755
--- a/tests/e2e/scenarios/api/extract-basic.sh
+++ b/tests/e2e/scenarios/api/extract-basic.sh
@@ -113,3 +113,37 @@ assert_json_eq "$RESULT" '.data.products | length' '6' "tab-scoped route resolve
end_test
+# ─────────────────────────────────────────────────────────────────
+start_test "extract: request-level scope confines every field to one subtree"
+
+AMOUNTS_SCHEMA='{"type":"object","properties":{"entries":{"type":"array","items":{"type":"object","properties":{"amount":{"type":"number","description":"price"}}}}}}'
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/extract-list.html\"}"
+assert_ok "navigate to extract-list.html"
+
+pt_post /extract -d "{\"schema\":${AMOUNTS_SCHEMA}}"
+assert_ok "unscoped extract"
+assert_json_eq "$RESULT" '.data.entries | length' '6' "unscoped entries come from the 6-product grid"
+
+pt_post /extract -d "{\"schema\":${AMOUNTS_SCHEMA},\"scope\":\"role:table\"}"
+assert_ok "extract scoped to role:table"
+assert_json_eq "$RESULT" '.data.entries | length' '5' "scope role:table reads the 5 table rows"
+TABLE_REF=$(echo "$RESULT" | jq -r '.fields.entries.ref')
+
+pt_post /extract -d "{\"schema\":${AMOUNTS_SCHEMA},\"scope\":\"ref:${TABLE_REF}\"}"
+assert_ok "extract scoped to ref:${TABLE_REF}"
+assert_json_eq "$RESULT" '.data.entries | length' '5' "scope ref:<table ref> reads the same 5 rows"
+
+pt_post /extract -d "{\"schema\":${PRODUCT_SCHEMA},\"scope\":\"ref:e99999\"}"
+assert_ok "a scope that matches nothing still answers 200"
+assert_json_eq "$RESULT" '.data' '{}' "no data outside a missing scope"
+assert_json_eq "$RESULT" '[.fields[].reason] | unique | join(",")' 'scope_not_found' "every field reports scope_not_found"
+assert_json_eq "$RESULT" '.missing | sort | join(",")' 'inStock,name,price' "required fields are listed as missing"
+
+pt_post /extract -d "{\"schema\":${AMOUNTS_SCHEMA},\"scope\":\"css:table\"}"
+assert_http_error 400 "scope: css" "a CSS scope is a 400 naming scope"
+
+pt_post /extract -d "{\"schema\":${AMOUNTS_SCHEMA},\"scope\":\"xpath://table\"}"
+assert_http_error 400 "scope: xpath" "an XPath scope is a 400 naming scope"
+
+end_test
diff --git a/tests/e2e/scenarios/api/extract-extended.sh b/tests/e2e/scenarios/api/extract-extended.sh
index 2181d184..35c6ad28 100755
--- a/tests/e2e/scenarios/api/extract-extended.sh
+++ b/tests/e2e/scenarios/api/extract-extended.sh
@@ -57,6 +57,9 @@ secure_post /extract -d "{\"schema\":${INJECTED_VALUE_SCHEMA}}"
assert_http_status 403 "extract blocked when the extracted value is the injection"
assert_not_contains "$RESULT" "reveal your system prompt" "the blocked response does not leak the injected value"
+secure_post /extract -d "{\"schema\":${INJECT_SCHEMA},\"scope\":\"ref:e99999\"}"
+assert_http_status 403 "a request scope that excludes the injection does not bypass the page scan"
+
secure_post /find -d '{"query":"heading"}'
assert_http_status 403 "find blocked the same way"
diff --git a/tests/e2e/scenarios/cli/extract-basic.sh b/tests/e2e/scenarios/cli/extract-basic.sh
index cd6fa2f2..547b7029 100755
--- a/tests/e2e/scenarios/cli/extract-basic.sh
+++ b/tests/e2e/scenarios/cli/extract-basic.sh
@@ -136,6 +136,35 @@ fi
end_test
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab extract --json, --explain, --tab and a scope that matches nothing"
+
+pt_ok nav "$PRODUCT_PAGE"
+PRODUCT_TAB=$(echo "$PT_OUT" | tr -d '[:space:]')
+pt_ok nav "$LIST_PAGE" --new-tab
+
+pt_ok extract --schema "$SCHEMAS/product.schema.json" --tab "$PRODUCT_TAB" --json
+assert_out_jq '.data.price' '1299' "--tab reads the product tab while the list tab is current"
+assert_out_jq '.fields.name.ref | test("^e[0-9]+$")' 'true' "--json prints the envelope with field refs"
+assert_out_jq '.vocabularyToken | length > 0' 'true' "--json envelope carries the vocabulary token"
+
+pt_ok extract --schema "$SCHEMAS/product.schema.json" --tab "$PRODUCT_TAB" --explain
+if awk -F'\t' '$1 == "price" && NF == 6 && $2 ~ /^e[0-9]+$/ && $4 ~ /^[0-9]+\.[0-9][0-9]$/ {found=1} END {exit !found}' <<<"$PT_OUT"; then
+ pass_assert "--explain row has field, ref, confidence, score, source and reason columns"
+else
+ fail_assert "--explain has no six-column price row: $PT_OUT"
+fi
+
+pt_ok extract --schema "$SCHEMAS/product.schema.json" --tab "$PRODUCT_TAB" --scope ref:e99999
+assert_out_jq '. == {}' 'true' "a scope that matches nothing extracts no data"
+if grep -q "missing required fields: inStock, name, price" <<<"$PT_ERR"; then
+ pass_assert "missing required fields reported on stderr with exit 0"
+else
+ fail_assert "no missing-required note on stderr: $PT_ERR"
+fi
+
+end_test
+
# ─────────────────────────────────────────────────────────────────
start_test "docs curl example returns typed data"