Skip to content

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

test(e2e): CLI text, drag, mouse down and mouse up with no --tab act on the CLI's current tab while another client's tab is the server's last touched (PIN-431)

Luigi Agosti20d4c0cd256d
diff --git a/tests/e2e/fixtures/drag-drop.html b/tests/e2e/fixtures/drag-drop.html
new file mode 100644
index 00000000..886ffd71
--- /dev/null
+++ b/tests/e2e/fixtures/drag-drop.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>E2E Test - Drag Drop</title>
+ <style>
+ body { font-family: sans-serif; padding: 32px; }
+ #drag, #drop { width: 160px; height: 80px; border: 2px solid #2d6cdf; margin: 16px 0; }
+ #drag { background: #eef4ff; cursor: grab; }
+ #drop { background: #fafcff; }
+ </style>
+</head>
+<body>
+ <h1 id="label">Drag Drop Fixture</h1>
+ <p id="marker">Tab marker: <span id="marker-value">none</span></p>
+ <div id="drag" draggable="true">Drag me</div>
+ <div id="drop">empty</div>
+ <p>Down count: <span id="down-count">0</span> Up count: <span id="up-count">0</span></p>
+
+ <script>
+ // ?label=X names the page so two tabs on this fixture read differently.
+ const label = new URLSearchParams(location.search).get('label') || 'none';
+ document.getElementById('marker-value').textContent = 'marker-' + label;
+
+ window.dragDropState = { down: 0, up: 0, dropped: false };
+ const drop = document.getElementById('drop');
+ function markDropped() {
+ window.dragDropState.dropped = true;
+ drop.textContent = 'dropped';
+ }
+ drop.addEventListener('dragover', (e) => e.preventDefault());
+ drop.addEventListener('drop', (e) => { e.preventDefault(); markDropped(); });
+ drop.addEventListener('mouseup', markDropped);
+ document.getElementById('drag').addEventListener('dragstart', (e) => {
+ e.dataTransfer.setData('text/plain', 'drag');
+ });
+ document.addEventListener('mousedown', () => {
+ window.dragDropState.down += 1;
+ document.getElementById('down-count').textContent = String(window.dragDropState.down);
+ });
+ document.addEventListener('mouseup', () => {
+ window.dragDropState.up += 1;
+ document.getElementById('up-count').textContent = String(window.dragDropState.up);
+ });
+ </script>
+</body>
+</html>
diff --git a/tests/e2e/scenarios/cli/tab-default-basic.sh b/tests/e2e/scenarios/cli/tab-default-basic.sh
new file mode 100644
index 00000000..59240ea0
--- /dev/null
+++ b/tests/e2e/scenarios/cli/tab-default-basic.sh
@@ -0,0 +1,110 @@
+#!/bin/bash
+# tab-default-basic.sh — commands with no --tab act on the CLI's current tab
+# (the one `nav` wrote to the state file), not on whichever tab another client
+# last touched on the shared server. Covers text, drag, mouse down and mouse up,
+# the verbs whose PreRunE once shadowed the state-file default (PIN-431).
+
+GROUP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+source "${GROUP_DIR}/../../helpers/cli.sh"
+
+# eval_on_tab runs an expression on one tab over HTTP and prints its result.
+# An explicit-tab request also makes that tab the server's current tab.
+eval_on_tab() {
+ local tab_id="$1" expr="$2"
+ e2e_curl -s -X POST "${E2E_SERVER}/evaluate" \
+ -H "Content-Type: application/json" \
+ -d "$(jq -n --arg t "$tab_id" --arg e "$expr" '{tabId: $t, expression: $e}')" |
+ jq -r '.result'
+}
+
+drag_state() {
+ eval_on_tab "$1" "JSON.stringify(window.dragDropState)"
+}
+
+# touch_b makes the other client's tab the server's last-touched tab, and
+# proves it: a tab-less HTTP read now lands on B.
+touch_b() {
+ drag_state "$TAB_B" >/dev/null
+ local body
+ body=$(e2e_curl -s "${E2E_SERVER}/text?mode=raw")
+ if [[ "$body" == *"marker-B"* ]]; then
+ pass_assert "server's tab-less current tab is B"
+ else
+ fail_assert "server's tab-less current tab is not B (got: ${body:0:200})"
+ fi
+}
+
+# ─────────────────────────────────────────────────────────────────
+start_test "two clients: CLI owns tab A, another client last touched tab B"
+
+pt_ok nav "${FIXTURES_URL}/drag-drop.html?label=A" --new-tab
+TAB_A=$(echo "$PT_OUT" | tr -d '[:space:]')
+
+NAV_B=$(e2e_curl -s -X POST "${E2E_SERVER}/navigate" \
+ -H "Content-Type: application/json" \
+ -d "{\"url\":\"${FIXTURES_URL}/drag-drop.html?label=B\",\"newTab\":true}")
+TAB_B=$(echo "$NAV_B" | jq -r '.tabId // empty')
+
+if [ -n "$TAB_A" ] && [ -n "$TAB_B" ] && [ "$TAB_A" != "$TAB_B" ]; then
+ pass_assert "two distinct tabs (A=$TAB_A B=$TAB_B)"
+else
+ fail_assert "expected two distinct tabs (A='$TAB_A' B='$TAB_B', nav B: ${NAV_B:0:200})"
+fi
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab text with no --tab reads the CLI's tab A"
+
+touch_b
+pt_ok text
+assert_output_contains "marker-A" "text returns A's content"
+assert_output_not_contains "marker-B" "text does not return B's content"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab drag with no --tab drops on tab A, not B"
+
+touch_b
+pt_ok drag "#drag" "#drop"
+assert_output_contains "OK" "drag reports OK"
+
+assert_json_jq "$(drag_state "$TAB_A")" '.dropped == true' \
+ "A's drop zone received the drop" "A's drop zone did not receive the drop"
+assert_json_jq "$(drag_state "$TAB_B")" '.dropped == false and .down == 0' \
+ "B is untouched by the drag" "drag mutated B"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab mouse down / mouse up with no --tab press on tab A, not B"
+
+A_BEFORE=$(drag_state "$TAB_A")
+DOWN_BEFORE=$(echo "$A_BEFORE" | jq -r '.down')
+UP_BEFORE=$(echo "$A_BEFORE" | jq -r '.up')
+
+touch_b
+pt_ok mouse down "#drop" --button left
+assert_output_contains "OK" "mouse down reports OK"
+touch_b
+pt_ok mouse up "#drop" --button left
+assert_output_contains "OK" "mouse up reports OK"
+
+assert_json_jq "$(drag_state "$TAB_A")" \
+ ".down == ($DOWN_BEFORE + 1) and .up == ($UP_BEFORE + 1)" \
+ "A received one mouse down and one mouse up" "A did not receive the mouse down/up"
+assert_json_jq "$(drag_state "$TAB_B")" '.down == 0 and .up == 0' \
+ "B received no mouse down/up" "mouse down/up landed on B"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab text --markdown --full still refuses locally"
+
+pt_fail text --markdown --full
+
+end_test
+
+pt tab close "$TAB_A" >/dev/null
+pt tab close "$TAB_B" >/dev/null
diff --git a/tests/e2e/scenarios/manifest.json b/tests/e2e/scenarios/manifest.json
index 6ceec8fa..91c07d03 100644
--- a/tests/e2e/scenarios/manifest.json
+++ b/tests/e2e/scenarios/manifest.json
@@ -64,6 +64,14 @@
"pr"
]
},
+ "cli/tab-default-basic.sh": {
+ "tags": [
+ "tabs",
+ "text",
+ "mouse",
+ "pr"
+ ]
+ },
"cli/a11y-axe-basic.sh": {
"tags": [
"a11y",