High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat: pdev test command + deduplicate test logic
Datacf7dbcb62aee
diff --git a/pdev b/pdevindex 765948ad..bcadff47 100755--- a/pdev+++ b/pdev@@ -20,6 +20,9 @@ COMMANDS=("check:π§ͺ:All checks (Go + Dashboard)"" check go:π§ͺ:Go only"" check dashboard:π§ͺ:Dashboard only"+ "test:π¬:All tests (unit + integration)"+ " test unit:π¬:Unit tests only"+ " test integration:π¬:Integration tests only""build:π:Build & run server + dashboard""doctor:π©Ί:Setup dev environment""security:π:Gosec security scan"@@ -76,6 +79,21 @@ run_command() {echo ""exec bash scripts/check-dashboard.sh;;+ "test")+ echo " ${ACCENT}${BOLD}π¬ All tests${NC}"+ echo ""+ exec bash scripts/test.sh all+ ;;+ "test unit")+ echo " ${ACCENT}${BOLD}π¬ Unit tests${NC}"+ echo ""+ exec bash scripts/test.sh unit+ ;;+ "test integration")+ echo " ${ACCENT}${BOLD}π¬ Integration tests${NC}"+ echo ""+ exec bash scripts/test.sh integration+ ;;"build") exec bash scripts/dev.sh ;;"doctor") exec bash scripts/doctor.sh ;;"security") exec bash scripts/check-gosec.sh ;;@@ -153,6 +171,13 @@ if [ $# -gt 0 ]; thenrun_command "check"fi;;+ test)+ if [ $# -gt 1 ]; then+ run_command "test $2"+ else+ run_command "test"+ fi+ ;;*) run_command "$1" ;;esacfidiff --git a/scripts/check.sh b/scripts/check.shindex 7788a49f..d51f2c4f 100755--- a/scripts/check.sh+++ b/scripts/check.sh@@ -2,7 +2,9 @@set -e# check.sh β Local pre-push checks matching GitHub Actions CI-# Uses gotestsum for structured test output with summaries+# Runs: format β vet β build β tests (via test.sh) β lint++cd "$(dirname "$0")/.."BOLD=$'\033[1m'ACCENT=$'\033[38;2;251;191;36m'@@ -12,151 +14,24 @@ ERROR=$'\033[38;2;230;57;70m'MUTED=$'\033[38;2;90;100;128m'NC=$'\033[0m'-CORE_REGEX='^Test(Health|Orchestrator_|Navigate_|Tabs_|Config_|Metrics_|Cookies_|Error_|Eval_|Upload_|Screenshot_)'-TMPDIR_CHECK=$(mktemp -d)-trap 'rm -rf "$TMPDIR_CHECK" pinchtab coverage.out 2>/dev/null' EXIT--ok() { echo -e " ${SUCCESS}β${NC} $1"; }-fail() { echo -e " ${ERROR}β${NC} $1"; [ -n "${2:-}" ] && echo -e " ${MUTED}$2${NC}"; }-hint() { echo -e " ${MUTED}$1${NC}"; }+ok() { echo -e " ${SUCCESS}β${NC} $1"; }+fail() { echo -e " ${ERROR}β${NC} $1"; [ -n "${2:-}" ] && echo -e " ${MUTED}$2${NC}"; }+hint() { echo -e " ${MUTED}$1${NC}"; }section() {echo ""echo -e "${ACCENT}${BOLD}$1${NC}"}-# Parse gotestsum JSON events and print summary-test_summary() {- local json_file="$1"- local label="$2"-- if [ ! -s "$json_file" ]; then- echo -e " ${MUTED}No test events recorded${NC}"- return- fi-- local total=0 pass=0 fail=0 skip=0- read total pass fail skip <<<"$(jq -r \- 'select(.Test != null and (.Action == "pass" or .Action == "fail" or .Action == "skip"))- | [.Package, .Test, .Action] | @tsv' "$json_file" \- | awk -F'\t' 'NF == 3 { key = $1 "\t" $2; status[key] = $3 }- END {- for (k in status) {- t++- if (status[k] == "pass") p++- else if (status[k] == "fail") f++- else if (status[k] == "skip") s++- }- printf "%d %d %d %d\n", t+0, p+0, f+0, s+0- }')"-- echo ""- echo -e " ${BOLD}$label${NC}"- echo -e " ${MUTED}ββββββββββββββββββββββββββββ${NC}"- echo -e " Total: ${BOLD}$total${NC}"- [ "$pass" -gt 0 ] && echo -e " Passed: ${SUCCESS}$pass${NC}"- [ "$fail" -gt 0 ] && echo -e " Failed: ${ERROR}$fail${NC}"- [ "$skip" -gt 0 ] && echo -e " Skipped: ${ACCENT}$skip${NC}"-- # Show failed test names- if [ "$fail" -gt 0 ]; then- echo ""- echo -e " ${ERROR}Failed tests:${NC}"- jq -r 'select(.Test != null and .Action == "fail") | " β \(.Test)"' "$json_file" | sort -u- fi-}--# ββ Start ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+trap 'rm -f pinchtab coverage.out 2>/dev/null' EXITecho ""echo -e " ${ACCENT}${BOLD}π¦ Pinchtab Check${NC}"echo -e " ${INFO}Running pre-push checks (matches GitHub Actions CI)...${NC}"-# ββ Check gotestsum ββββββββββββββββββββββββββββββββββββββββββββββββββ--HAS_GOTESTSUM=false-if command -v gotestsum &>/dev/null; then- HAS_GOTESTSUM=true-fi--# Run unit tests with dots progress-# Usage: run_unit_tests <json_file> <go test args...>-run_unit_tests() {- local json_file="$1"; shift- local exit_code=0-- if $HAS_GOTESTSUM; then- gotestsum --format dots --jsonfile "$json_file" -- "$@" 2>&1 || exit_code=$?- else- go test "$@" 2>&1 | grep -E '^(ok|FAIL|---) ' || exit_code=${PIPESTATUS[0]}- fi-- echo ""- return $exit_code-}--# Run integration tests with live progress counter-# Pipes go test -json directly for real-time output-# Usage: run_integration_tests <json_file> <go test args...>-run_integration_tests() {- local json_file="$1"; shift- local exit_code=0- local count=0-- # Stream JSON events from go test, tee to file, show live progress- go test -json "$@" 2>&1 | tee "$json_file" | while IFS= read -r line; do- local action test_name- action=$(echo "$line" | jq -r '.Action // empty' 2>/dev/null) || continue- test_name=$(echo "$line" | jq -r '.Test // empty' 2>/dev/null) || continue-- [ -z "$test_name" ] && continue-- # Track elapsed time from Elapsed field- local elapsed- elapsed=$(echo "$line" | jq -r '.Elapsed // empty' 2>/dev/null)-- # Truncate long test names- local display_name="$test_name"- local max_len=40- if [ ${#display_name} -gt $max_len ]; then- display_name="${display_name:0:$((max_len - 1))}β¦"- fi-- case "$action" in- run)- printf "\r ${MUTED}βΈ %-${max_len}s${NC} \r" "$display_name"- ;;- pass)- count=$((count + 1))- if [ -n "$elapsed" ]; then- printf "\r ${SUCCESS}β${NC} ${MUTED}[%2d]${NC} %-${max_len}s ${MUTED}%6ss${NC}\n" "$count" "$display_name" "$elapsed"- else- printf "\r ${SUCCESS}β${NC} ${MUTED}[%2d]${NC} %-${max_len}s\n" "$count" "$display_name"- fi- ;;- fail)- count=$((count + 1))- if [ -n "$elapsed" ]; then- printf "\r ${ERROR}β${NC} ${MUTED}[%2d]${NC} %-${max_len}s ${MUTED}%6ss${NC}\n" "$count" "$display_name" "$elapsed"- else- printf "\r ${ERROR}β${NC} ${MUTED}[%2d]${NC} %-${max_len}s\n" "$count" "$display_name"- fi- ;;- skip)- count=$((count + 1))- printf "\r ${ACCENT}Β·${NC} ${MUTED}[%2d]${NC} %-${max_len}s ${MUTED} skip${NC}\n" "$count" "$display_name"- ;;- esac- done- exit_code=${PIPESTATUS[0]}- printf "\r%*s\r" 60 "" # clear last line-- return $exit_code-}-# ββ Format βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ-section "Format Check"+section "Format"unformatted=$(gofmt -l .)if [ -n "$unformatted" ]; then@@ -169,7 +44,7 @@ ok "gofmt"# ββ Vet ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ-section "Go Vet"+section "Vet"if ! go vet ./... 2>&1; thenfail "go vet"@@ -187,57 +62,9 @@ if ! go build -o pinchtab ./cmd/pinchtab 2>&1; thenfiok "go build"-# ββ Unit Tests βββββββββββββββββββββββββββββββββββββββββββββββββββββββ--section "Unit Tests"--UNIT_JSON="$TMPDIR_CHECK/unit-events.json"--if ! run_unit_tests "$UNIT_JSON" \- -count=1 -coverprofile=coverage.out -covermode=atomic ./...; then- fail "Unit tests"- test_summary "$UNIT_JSON" "Unit Test Results"- exit 1-fi-ok "Unit tests"-test_summary "$UNIT_JSON" "Unit Test Results"--echo ""-echo -e " ${BOLD}Coverage${NC}"-echo -e " ${MUTED}ββββββββββββββββββββββββββββ${NC}"-go tool cover -func=coverage.out | tail -1 | awk '{printf " %s\n", $0}'+# ββ Tests (delegates to test.sh) βββββββββββββββββββββββββββββββββββββ-# ββ Integration Tests (Core) ββββββββββββββββββββββββββββββββββββββββ--section "Integration Tests (Core)"--CORE_JSON="$TMPDIR_CHECK/core-events.json"--if ! run_integration_tests "$CORE_JSON" \- -tags integration -timeout 10m -count=1 \- -run "$CORE_REGEX" ./tests/integration/; then- fail "Integration core"- test_summary "$CORE_JSON" "Core Test Results"- exit 1-fi-ok "Integration core"-test_summary "$CORE_JSON" "Core Test Results"--# ββ Integration Tests (Rest) ββββββββββββββββββββββββββββββββββββββββ--section "Integration Tests (Rest)"--REST_JSON="$TMPDIR_CHECK/rest-events.json"--if ! run_integration_tests "$REST_JSON" \- -tags integration -timeout 12m -count=1 \- -run '^Test' -skip "$CORE_REGEX" ./tests/integration/; then- fail "Integration rest"- test_summary "$REST_JSON" "Rest Test Results"- exit 1-fi-ok "Integration rest"-test_summary "$REST_JSON" "Rest Test Results"+bash scripts/test.sh all# ββ Lint βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββdiff --git a/scripts/test.sh b/scripts/test.shnew file mode 100755index 00000000..151a2ba1--- /dev/null+++ b/scripts/test.sh@@ -0,0 +1,176 @@+#!/bin/bash+set -e++# test.sh β Run Go tests with optional scope+# Usage: test.sh [unit|integration|all]+# Default: all++cd "$(dirname "$0")/.."++BOLD=$'\033[1m'+ACCENT=$'\033[38;2;251;191;36m'+SUCCESS=$'\033[38;2;0;229;204m'+ERROR=$'\033[38;2;230;57;70m'+MUTED=$'\033[38;2;90;100;128m'+NC=$'\033[0m'++CORE_REGEX='^Test(Health|Orchestrator_|Navigate_|Tabs_|Config_|Metrics_|Cookies_|Error_|Eval_|Upload_|Screenshot_)'++ok() { echo -e " ${SUCCESS}β${NC} $1"; }+fail() { echo -e " ${ERROR}β${NC} $1"; }++section() {+ echo ""+ echo -e "${ACCENT}${BOLD}$1${NC}"+}++# Parse gotestsum JSON and print summary+test_summary() {+ local json_file="$1"+ local label="$2"++ [ ! -s "$json_file" ] && return++ local total=0 pass=0 fail=0 skip=0+ read total pass fail skip <<<"$(jq -r \+ 'select(.Test != null and (.Action == "pass" or .Action == "fail" or .Action == "skip"))+ | [.Package, .Test, .Action] | @tsv' "$json_file" \+ | awk -F'\t' 'NF == 3 { key = $1 "\t" $2; status[key] = $3 }+ END {+ for (k in status) {+ t+++ if (status[k] == "pass") p+++ else if (status[k] == "fail") f+++ else if (status[k] == "skip") s+++ }+ printf "%d %d %d %d\n", t+0, p+0, f+0, s+0+ }')"++ echo ""+ echo -e " ${BOLD}$label${NC}"+ echo -e " ${MUTED}ββββββββββββββββββββββββββββ${NC}"+ echo -e " Total: ${BOLD}$total${NC}"+ [ "$pass" -gt 0 ] && echo -e " Passed: ${SUCCESS}$pass${NC}"+ [ "$fail" -gt 0 ] && echo -e " Failed: ${ERROR}$fail${NC}"+ [ "$skip" -gt 0 ] && echo -e " Skipped: ${ACCENT}$skip${NC}"++ if [ "$fail" -gt 0 ]; then+ echo ""+ echo -e " ${ERROR}Failed tests:${NC}"+ jq -r 'select(.Test != null and .Action == "fail") | " β \(.Test)"' "$json_file" | sort -u+ fi+}++# Live progress for integration tests+run_integration() {+ local json_file="$1"; shift+ local count=0+ local max_len=40++ go test -json "$@" 2>&1 | tee "$json_file" | while IFS= read -r line; do+ local action test_name elapsed+ action=$(echo "$line" | jq -r '.Action // empty' 2>/dev/null) || continue+ test_name=$(echo "$line" | jq -r '.Test // empty' 2>/dev/null) || continue+ elapsed=$(echo "$line" | jq -r '.Elapsed // empty' 2>/dev/null)++ [ -z "$test_name" ] && continue++ local display="$test_name"+ if [ ${#display} -gt $max_len ]; then+ display="${display:0:$((max_len - 1))}β¦"+ fi++ case "$action" in+ run) printf "\r ${MUTED}βΈ %-${max_len}s${NC} \r" "$display" ;;+ pass) count=$((count + 1))+ if [ -n "$elapsed" ]; then+ printf "\r ${SUCCESS}β${NC} ${MUTED}[%2d]${NC} %-${max_len}s ${MUTED}%6ss${NC}\n" "$count" "$display" "$elapsed"+ else+ printf "\r ${SUCCESS}β${NC} ${MUTED}[%2d]${NC} %-${max_len}s\n" "$count" "$display"+ fi ;;+ fail) count=$((count + 1))+ if [ -n "$elapsed" ]; then+ printf "\r ${ERROR}β${NC} ${MUTED}[%2d]${NC} %-${max_len}s ${MUTED}%6ss${NC}\n" "$count" "$display" "$elapsed"+ else+ printf "\r ${ERROR}β${NC} ${MUTED}[%2d]${NC} %-${max_len}s\n" "$count" "$display"+ fi ;;+ skip) count=$((count + 1))+ printf "\r ${ACCENT}Β·${NC} ${MUTED}[%2d]${NC} %-${max_len}s ${MUTED} skip${NC}\n" "$count" "$display" ;;+ esac+ done+ return ${PIPESTATUS[0]}+}++SCOPE="${1:-all}"+TMPDIR_TEST=$(mktemp -d)+trap 'rm -rf "$TMPDIR_TEST"' EXIT++HAS_GOTESTSUM=false+command -v gotestsum &>/dev/null && HAS_GOTESTSUM=true++# ββ Unit tests βββββββββββββββββββββββββββββββββββββββββββββββββββββββ++if [ "$SCOPE" = "all" ] || [ "$SCOPE" = "unit" ]; then+ section "Unit Tests"++ UNIT_JSON="$TMPDIR_TEST/unit.json"++ if $HAS_GOTESTSUM; then+ if ! gotestsum --format dots --jsonfile "$UNIT_JSON" -- -count=1 ./...; then+ fail "Unit tests"+ test_summary "$UNIT_JSON" "Unit Test Results"+ exit 1+ fi+ else+ if ! go test -json -count=1 ./... > "$UNIT_JSON" 2>&1; then+ fail "Unit tests"+ test_summary "$UNIT_JSON" "Unit Test Results"+ exit 1+ fi+ fi+ ok "Unit tests"+ test_summary "$UNIT_JSON" "Unit Test Results"+fi++# ββ Integration tests (Core) ββββββββββββββββββββββββββββββββββββββββ++if [ "$SCOPE" = "all" ] || [ "$SCOPE" = "integration" ]; then+ section "Integration Tests (Core)"++ CORE_JSON="$TMPDIR_TEST/core.json"++ if ! run_integration "$CORE_JSON" \+ -tags integration -timeout 10m -count=1 \+ -run "$CORE_REGEX" ./tests/integration/; then+ fail "Integration core"+ test_summary "$CORE_JSON" "Core Test Results"+ exit 1+ fi+ printf "\r%*s\r" 60 ""+ ok "Integration core"+ test_summary "$CORE_JSON" "Core Test Results"++ # ββ Integration tests (Rest) ββββββββββββββββββββββββββββββββββββ++ section "Integration Tests (Rest)"++ REST_JSON="$TMPDIR_TEST/rest.json"++ if ! run_integration "$REST_JSON" \+ -tags integration -timeout 12m -count=1 \+ -run '^Test' -skip "$CORE_REGEX" ./tests/integration/; then+ fail "Integration rest"+ test_summary "$REST_JSON" "Rest Test Results"+ exit 1+ fi+ printf "\r%*s\r" 60 ""+ ok "Integration rest"+ test_summary "$REST_JSON" "Rest Test Results"+fi++# ββ Summary ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ++section "Summary"+echo ""+echo -e " ${SUCCESS}${BOLD}All tests passed!${NC}"+echo ""