High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat(e2e): add CLI E2E test infrastructure
Boschc92f632b553c
diff --git a/.github/workflows/e2e-cli.yml b/.github/workflows/e2e-cli.ymlnew file mode 100644index 00000000..89b7d133--- /dev/null+++ b/.github/workflows/e2e-cli.yml@@ -0,0 +1,69 @@+name: E2E CLI Tests++on:+ workflow_dispatch:+ push:+ branches: [main]+ paths:+ - 'cmd/**'+ - 'internal/**'+ - 'tests/e2e/**'+ - '.github/workflows/e2e-cli.yml'+ pull_request:+ branches: [main]+ paths:+ - 'cmd/**'+ - 'internal/**'+ - 'tests/e2e/**'+ - '.github/workflows/e2e-cli.yml'++jobs:+ e2e-cli:+ name: CLI End-to-End Tests+ runs-on: ubuntu-latest+ steps:+ - name: Checkout+ uses: actions/checkout@v4++ - name: Set up Go+ uses: actions/setup-go@v5+ with:+ go-version: '1.24'++ - name: Build pinchtab binary+ run: |+ go build -o tests/e2e/runner-cli/pinchtab ./cmd/pinchtab++ - name: Set up Docker Buildx+ uses: docker/setup-buildx-action@v3++ - name: Run CLI E2E tests+ working-directory: tests/e2e+ run: |+ docker compose -f docker-compose-cli.yml up \+ --build \+ --abort-on-container-exit \+ --exit-code-from runner++ - name: Copy results from container+ if: always()+ working-directory: tests/e2e+ run: |+ docker compose -f docker-compose-cli.yml cp runner:/results ./results || true++ - name: Upload results+ if: always()+ uses: actions/upload-artifact@v4+ with:+ name: cli-e2e-results+ path: tests/e2e/results/+ retention-days: 7++ - name: Show logs on failure+ if: failure()+ working-directory: tests/e2e+ run: |+ echo "=== CLI Runner Logs ==="+ docker compose -f docker-compose-cli.yml logs runner || true+ echo "=== Pinchtab Logs ==="+ docker compose -f docker-compose-cli.yml logs pinchtab || truediff --git a/tests/e2e/docker-compose-cli.yml b/tests/e2e/docker-compose-cli.ymlnew file mode 100644index 00000000..fd0d35b1--- /dev/null+++ b/tests/e2e/docker-compose-cli.yml@@ -0,0 +1,46 @@+services:+ # Main pinchtab instance+ pinchtab:+ build:+ context: ../..+ dockerfile: Dockerfile+ environment:+ PINCHTAB_CONFIG: /config/pinchtab.json+ PINCHTAB_PORT: "9999"+ volumes:+ - ./config/pinchtab.json:/config/pinchtab.json:ro+ ports:+ - "9999:9999"+ shm_size: '2gb'+ healthcheck:+ test: ["CMD-SHELL", "wget -q -O /dev/null http://localhost:9999/health"]+ interval: 3s+ timeout: 10s+ retries: 20+ start_period: 15s++ fixtures:+ image: nginx:alpine+ volumes:+ - ./fixtures:/usr/share/nginx/html:ro+ healthcheck:+ test: ["CMD-SHELL", "wget -q -O /dev/null http://localhost:80/"]+ interval: 2s+ timeout: 5s+ retries: 5++ runner:+ build:+ context: ./runner-cli+ depends_on:+ pinchtab:+ condition: service_healthy+ fixtures:+ condition: service_healthy+ environment:+ - PINCHTAB_URL=http://pinchtab:9999+ - FIXTURES_URL=http://fixtures:80+ volumes:+ - ./scenarios-cli:/scenarios:ro+ - ./results:/results+ command: ["/scenarios/run-all.sh"]diff --git a/tests/e2e/runner-cli/.gitignore b/tests/e2e/runner-cli/.gitignorenew file mode 100644index 00000000..07911d1d--- /dev/null+++ b/tests/e2e/runner-cli/.gitignore@@ -0,0 +1,3 @@+# The pinchtab binary is built by CI before docker build+# Don't commit it to the repo+pinchtabdiff --git a/tests/e2e/runner-cli/Dockerfile b/tests/e2e/runner-cli/Dockerfilenew file mode 100644index 00000000..aa7a374f--- /dev/null+++ b/tests/e2e/runner-cli/Dockerfile@@ -0,0 +1,23 @@+# CLI E2E test runner+# Includes pinchtab binary for testing CLI commands++FROM alpine:3.21++# Install test dependencies+RUN apk add --no-cache \+ bash \+ curl \+ jq \+ coreutils++# Copy pre-built pinchtab binary (built by CI before docker build)+COPY pinchtab /usr/local/bin/pinchtab+RUN chmod +x /usr/local/bin/pinchtab++# Create results directory+RUN mkdir -p /results++WORKDIR /scenarios++# Default command runs all tests+CMD ["/scenarios/run-all.sh"]diff --git a/tests/e2e/scenarios-cli/01-nav.sh b/tests/e2e/scenarios-cli/01-nav.shnew file mode 100755index 00000000..7beb96f5--- /dev/null+++ b/tests/e2e/scenarios-cli/01-nav.sh@@ -0,0 +1,34 @@+#!/bin/bash+# 01-nav.sh — CLI navigation commands++source "$(dirname "$0")/common.sh"++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab nav <url>"++pt_ok nav "${FIXTURES_URL}/index.html"+assert_output_json+assert_output_contains "tabId" "returns tab ID"+assert_output_contains "title" "returns page title"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab nav (invalid URL)"++pt_fail nav "not-a-valid-url"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab nav --tab <id>"++# First navigate to get a tab+pt_ok nav "${FIXTURES_URL}/index.html"+TAB_ID=$(echo "$PT_OUT" | jq -r '.tabId')++# Navigate same tab to different page+pt_ok nav --tab "$TAB_ID" "${FIXTURES_URL}/form.html"+assert_output_contains "form.html" "navigated to form.html"++end_testdiff --git a/tests/e2e/scenarios-cli/02-snap.sh b/tests/e2e/scenarios-cli/02-snap.shnew file mode 100755index 00000000..e451a8d6--- /dev/null+++ b/tests/e2e/scenarios-cli/02-snap.sh@@ -0,0 +1,45 @@+#!/bin/bash+# 02-snap.sh — CLI snapshot commands++source "$(dirname "$0")/common.sh"++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab snap (JSON format)"++pt_ok nav "${FIXTURES_URL}/form.html"+pt_ok snap+assert_output_json+assert_output_contains "nodes" "returns nodes array"+assert_output_contains "title" "returns page title"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab snap --format text"++pt_ok snap --format text+assert_output_contains "[e" "contains element refs"+assert_output_not_contains "{" "not JSON format"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab snap --filter interactive"++pt_ok snap --filter interactive+assert_output_json+assert_output_contains "textbox" "contains form inputs"+assert_output_contains "button" "contains buttons"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab snap --tab <id>"++pt_ok nav "${FIXTURES_URL}/buttons.html"+TAB_ID=$(echo "$PT_OUT" | jq -r '.tabId')++pt_ok snap --tab "$TAB_ID"+assert_output_contains "buttons.html" "snapshot from correct tab"++end_testdiff --git a/tests/e2e/scenarios-cli/03-actions.sh b/tests/e2e/scenarios-cli/03-actions.shnew file mode 100755index 00000000..5b3288aa--- /dev/null+++ b/tests/e2e/scenarios-cli/03-actions.sh@@ -0,0 +1,71 @@+#!/bin/bash+# 03-actions.sh — CLI action commands (click, type, press)++source "$(dirname "$0")/common.sh"++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab click <ref>"++pt_ok nav "${FIXTURES_URL}/buttons.html"+pt_ok snap --filter interactive --format text++# Find a button ref from snapshot+# The buttons.html has an increment button+pt_ok click --css "#increment"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab click --css <selector>"++pt_ok nav "${FIXTURES_URL}/form.html"+pt_ok click --css "#username"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab type --css <selector> <text>"++pt_ok nav "${FIXTURES_URL}/form.html"+pt_ok type --css "#username" "testuser"+assert_output_contains "typed" "confirms text was typed"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab press <key>"++pt_ok press Escape+assert_output_contains "pressed" "confirms key was pressed"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab press Enter (does not type text)"++pt_ok nav "${FIXTURES_URL}/form.html"+pt_ok type --css "#username" "hello"+pt_ok press Enter++# Verify via eval that username doesn't contain "Enter"+pt_ok eval "document.getElementById('username').value"+assert_output_not_contains "Enter" "Enter key dispatched, not typed"+assert_output_contains "hello" "original text preserved"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab focus --css <selector>"++pt_ok nav "${FIXTURES_URL}/form.html"+pt_ok focus --css "#email"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab hover --css <selector>"++pt_ok nav "${FIXTURES_URL}/buttons.html"+pt_ok hover --css "#increment"++end_testdiff --git a/tests/e2e/scenarios-cli/04-tabs.sh b/tests/e2e/scenarios-cli/04-tabs.shnew file mode 100755index 00000000..ff3944ac--- /dev/null+++ b/tests/e2e/scenarios-cli/04-tabs.sh@@ -0,0 +1,30 @@+#!/bin/bash+# 04-tabs.sh — CLI tab management commands++source "$(dirname "$0")/common.sh"++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab tabs (list)"++# Create a tab first+pt_ok nav "${FIXTURES_URL}/index.html"++pt_ok tabs+assert_output_json+assert_output_contains "tabs" "returns tabs array"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab tabs close <id>"++pt_ok nav "${FIXTURES_URL}/form.html"+TAB_ID=$(echo "$PT_OUT" | jq -r '.tabId')++pt_ok tabs close "$TAB_ID"++# Verify tab is gone+pt_ok tabs+assert_output_not_contains "$TAB_ID" "tab was closed"++end_testdiff --git a/tests/e2e/scenarios-cli/05-eval.sh b/tests/e2e/scenarios-cli/05-eval.shnew file mode 100755index 00000000..16a6ffe2--- /dev/null+++ b/tests/e2e/scenarios-cli/05-eval.sh@@ -0,0 +1,41 @@+#!/bin/bash+# 05-eval.sh — CLI evaluate command++source "$(dirname "$0")/common.sh"++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab eval <expression>"++pt_ok nav "${FIXTURES_URL}/index.html"+pt_ok eval "1 + 1"+assert_output_contains "2" "evaluates simple expression"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab eval (DOM query)"++pt_ok nav "${FIXTURES_URL}/form.html"+pt_ok eval "document.title"+assert_output_contains "Form" "returns page title"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab eval (JSON result)"++pt_ok eval "JSON.stringify({a: 1, b: 2})"+assert_output_contains '"a"' "returns JSON object"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab eval --tab <id>"++pt_ok nav "${FIXTURES_URL}/buttons.html"+TAB_ID=$(echo "$PT_OUT" | jq -r '.tabId')++pt_ok eval --tab "$TAB_ID" "document.title"+assert_output_contains "Button" "evaluates in correct tab"++end_testdiff --git a/tests/e2e/scenarios-cli/06-find.sh b/tests/e2e/scenarios-cli/06-find.shnew file mode 100755index 00000000..f818ae94--- /dev/null+++ b/tests/e2e/scenarios-cli/06-find.sh@@ -0,0 +1,23 @@+#!/bin/bash+# 06-find.sh — CLI semantic find command++source "$(dirname "$0")/common.sh"++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab find <query>"++pt_ok nav "${FIXTURES_URL}/form.html"+pt_ok find "submit button"+assert_output_json+assert_output_contains "matches" "returns matches"++end_test++# ─────────────────────────────────────────────────────────────────+start_test "pinchtab find (input field)"++pt_ok nav "${FIXTURES_URL}/form.html"+pt_ok find "username input"+assert_output_contains "textbox" "finds input element"++end_testdiff --git a/tests/e2e/scenarios-cli/common.sh b/tests/e2e/scenarios-cli/common.shnew file mode 100755index 00000000..fe3c6c8e--- /dev/null+++ b/tests/e2e/scenarios-cli/common.sh@@ -0,0 +1,195 @@+#!/bin/bash+# Common utilities for CLI E2E tests++set -uo pipefail++# Colors+RED='\033[0;31m'+GREEN='\033[0;32m'+YELLOW='\033[0;33m'+BLUE='\033[0;34m'+NC='\033[0m'++# Environment+PINCHTAB_URL="${PINCHTAB_URL:-http://localhost:9999}"+FIXTURES_URL="${FIXTURES_URL:-http://localhost:8080}"+RESULTS_DIR="${RESULTS_DIR:-/results}"++# Test tracking+TESTS_PASSED=0+TESTS_FAILED=0+ASSERTIONS_PASSED=0+ASSERTIONS_FAILED=0+CURRENT_TEST=""++# Extract host:port from URL for CLI+PINCHTAB_HOST=$(echo "$PINCHTAB_URL" | sed 's|http://||' | cut -d'/' -f1)++# ─────────────────────────────────────────────────────────────────+# Test lifecycle+# ─────────────────────────────────────────────────────────────────++start_test() {+ CURRENT_TEST="$1"+ echo -e "${BLUE}▶ ${CURRENT_TEST}${NC}"+}++end_test() {+ if [ "$ASSERTIONS_FAILED" -gt 0 ]; then+ echo -e "${RED}✗ ${CURRENT_TEST} failed${NC}"+ ((TESTS_FAILED++)) || true+ else+ echo -e "${GREEN}✓ ${CURRENT_TEST}${NC}"+ ((TESTS_PASSED++)) || true+ fi+ ASSERTIONS_FAILED=0+ ASSERTIONS_PASSED=0+ echo ""+}++# ─────────────────────────────────────────────────────────────────+# CLI execution helpers+# ─────────────────────────────────────────────────────────────────++# Run pinchtab CLI command+# Usage: pt <command> [args...]+# Sets $PT_OUT (stdout), $PT_ERR (stderr), $PT_CODE (exit code)+pt() {+ local tmpout=$(mktemp)+ local tmperr=$(mktemp)++ echo -e " ${BLUE}→ pinchtab --url $PINCHTAB_URL $@${NC}"++ set +e+ pinchtab --url "$PINCHTAB_URL" "$@" > "$tmpout" 2> "$tmperr"+ PT_CODE=$?+ set -e++ PT_OUT=$(cat "$tmpout")+ PT_ERR=$(cat "$tmperr")+ rm -f "$tmpout" "$tmperr"++ if [ -n "$PT_OUT" ]; then+ echo "$PT_OUT" | head -5+ fi+}++# Run pinchtab and expect success (exit 0)+# Usage: pt_ok <command> [args...]+pt_ok() {+ pt "$@"+ if [ "$PT_CODE" -eq 0 ]; then+ echo -e " ${GREEN}✓${NC} exit 0"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} expected exit 0, got $PT_CODE"+ echo -e " ${RED}stderr: $PT_ERR${NC}"+ ((ASSERTIONS_FAILED++)) || true+ fi+}++# Run pinchtab and expect failure (non-zero exit)+# Usage: pt_fail <command> [args...]+pt_fail() {+ pt "$@"+ if [ "$PT_CODE" -ne 0 ]; then+ echo -e " ${GREEN}✓${NC} exit $PT_CODE (expected failure)"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} expected non-zero exit, got 0"+ ((ASSERTIONS_FAILED++)) || true+ fi+}++# ─────────────────────────────────────────────────────────────────+# Assertions+# ─────────────────────────────────────────────────────────────────++# Assert PT_OUT contains string+assert_output_contains() {+ local expected="$1"+ local desc="${2:-output contains '$expected'}"++ if echo "$PT_OUT" | grep -q "$expected"; then+ echo -e " ${GREEN}✓${NC} $desc"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} $desc"+ echo -e " ${RED} output was: $PT_OUT${NC}"+ ((ASSERTIONS_FAILED++)) || true+ fi+}++# Assert PT_OUT does not contain string+assert_output_not_contains() {+ local forbidden="$1"+ local desc="${2:-output does not contain '$forbidden'}"++ if echo "$PT_OUT" | grep -q "$forbidden"; then+ echo -e " ${RED}✗${NC} $desc"+ echo -e " ${RED} output was: $PT_OUT${NC}"+ ((ASSERTIONS_FAILED++)) || true+ else+ echo -e " ${GREEN}✓${NC} $desc"+ ((ASSERTIONS_PASSED++)) || true+ fi+}++# Assert PT_OUT is valid JSON+assert_output_json() {+ local desc="${1:-output is valid JSON}"++ if echo "$PT_OUT" | jq . > /dev/null 2>&1; then+ echo -e " ${GREEN}✓${NC} $desc"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} $desc"+ echo -e " ${RED} output was: $PT_OUT${NC}"+ ((ASSERTIONS_FAILED++)) || true+ fi+}++# Assert PT_OUT JSON field equals value+assert_json_field() {+ local path="$1"+ local expected="$2"+ local desc="${3:-$path equals '$expected'}"++ local actual+ actual=$(echo "$PT_OUT" | jq -r "$path" 2>/dev/null)++ if [ "$actual" = "$expected" ]; then+ echo -e " ${GREEN}✓${NC} $desc"+ ((ASSERTIONS_PASSED++)) || true+ else+ echo -e " ${RED}✗${NC} $desc (got '$actual')"+ ((ASSERTIONS_FAILED++)) || true+ fi+}++# ─────────────────────────────────────────────────────────────────+# Summary+# ─────────────────────────────────────────────────────────────────++print_summary() {+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"+ echo ""+ local total=$((TESTS_PASSED + TESTS_FAILED))+ if [ "$TESTS_FAILED" -eq 0 ]; then+ echo -e " ${GREEN}All $total CLI tests passed!${NC}"+ else+ echo -e " ${GREEN}Passed:${NC} $TESTS_PASSED/$total"+ echo -e " ${RED}Failed:${NC} $TESTS_FAILED/$total"+ fi+ echo ""+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"++ # Save results+ if [ -d "${RESULTS_DIR:-}" ]; then+ echo "passed=$TESTS_PASSED" > "${RESULTS_DIR}/summary.txt"+ echo "failed=$TESTS_FAILED" >> "${RESULTS_DIR}/summary.txt"+ fi++ # Exit with failure if any tests failed+ [ "$TESTS_FAILED" -eq 0 ]+}diff --git a/tests/e2e/scenarios-cli/run-all.sh b/tests/e2e/scenarios-cli/run-all.shnew file mode 100755index 00000000..9935dffc--- /dev/null+++ b/tests/e2e/scenarios-cli/run-all.sh@@ -0,0 +1,49 @@+#!/bin/bash+# Run all CLI E2E test scenarios++set -uo pipefail++SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"++# Source common utilities (initializes counters)+source "$SCRIPT_DIR/common.sh"++echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"+echo " 🦀 PinchTab CLI E2E Tests"+echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"+echo ""+echo " Server: $PINCHTAB_URL"+echo " Fixtures: $FIXTURES_URL"+echo ""++# Wait for server to be ready+echo "Waiting for pinchtab server..."+for i in $(seq 1 30); do+ if curl -s "$PINCHTAB_URL/health" > /dev/null 2>&1; then+ echo "Server ready!"+ break+ fi+ sleep 1+done++# Verify pinchtab CLI is available+if ! command -v pinchtab &> /dev/null; then+ echo "ERROR: pinchtab CLI not found in PATH"+ exit 1+fi++echo ""+echo "Running CLI tests..."+echo ""++# Find and run all test scripts in order+for script in "$SCRIPT_DIR"/[0-9][0-9]-*.sh; do+ if [ -f "$script" ]; then+ echo -e "${YELLOW}Running: $(basename "$script")${NC}"+ echo ""+ source "$script"+ echo ""+ fi+done++print_summary