High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
add test plan and performance docs, remove ad-hoc QA files
L7e381433cdf3
diff --git a/QA-RETEST.md b/QA-RETEST.mddeleted file mode 100644index 4707f5c3..00000000--- a/QA-RETEST.md+++ /dev/null@@ -1,78 +0,0 @@-# Pinchtab QA Retest — 2026-02-15 16:27--**Build:** latest main (no new commits since last QA)-**Tester:** Bosch (automated retest)-------## Bug Fix Results--### 🟡 P1 — `newTab:true` → ✅ PASS-Tabs went from 3→4 after `navigate` with `newTab:true`. New tab opened correctly.--### 🟡 P1 — `/action` Unhelpful Error → ✅ PASS-Response: `{"error":"missing required field 'kind' — valid values: click, type, fill, press, focus, hover, select, scroll"}`-Lists valid values as expected.--### 🟢 P2 — `/navigate` Empty Title → ⚠️ PARTIAL-- **BBC:** ✅ returns `"BBC - Home"`-- **x.com:** ❌ still returns `"title":""`-- x.com uses heavy JS/SPA hydration — title may need longer wait or DOMContentLoaded fallback--### 🟢 P2 — `/text` Google Language Blob → ✅ PASS-Language picker blob (Afrikaans, azərbaycanca, etc.) is gone. Google /text now returns clean content.-------## 🔴 P0 — Active Tab Tracking — STILL BROKEN--This is the **critical outstanding bug**. After `/navigate`, `/text` and `/snapshot` frequently return data from a **stale tab** instead of the most recently navigated one.--**Evidence from retest:**-| Navigated to | /text returned | /snapshot returned |-|---|---|---|-| x.com | Google data (stale) | Google snapshot (stale) |-| LinkedIn | GitHub data (stale) | GitHub snapshot (stale) |--The active tab pointer drifts, especially when navigating rapidly between sites. Sometimes it works (Google→BBC was fine), sometimes it doesn't.-------## Performance — Token Counts (Corrected for Active Sites Only)--Only showing results where active tab was correctly tracked:--| Site | /snapshot tokens | /text tokens | Previous /snapshot | Previous /text |-|------|-----------------|-------------|-------------------|---------------|-| Google | ~848 | ~143 | ~2K | ~764 |-| GitHub | ~9,835 | ~1,249 | ~9.8K | ~1.2K |-| BBC | ~26,598 | ~3,479 | ~26.7K | ~3.5K |-| Wikipedia | ~20,474 | ~3,306 | ~20.5K | ~3.5K |-| x.com | ❌ stale | ❌ stale | ~2K | ~121 |-| LinkedIn | ❌ stale | ❌ stale | ~7.5K | ~6.1K |--**Changes from previous benchmarks:**-- Google /text dropped significantly (~764→~143 tokens) — likely the language picker fix removing bloat ✅-- Google /snapshot also smaller (~2K→~848) — same reason-- All other tracked sites are essentially unchanged-- x.com and LinkedIn couldn't be measured due to active tab bug-------## Summary--| Fix | Status |-|-----|--------|-| `newTab:true` opens new tab | ✅ PASS |-| `/action` missing kind lists valid values | ✅ PASS |-| `/navigate` BBC returns title | ✅ PASS |-| `/navigate` x.com returns title | ❌ FAIL (still empty) |-| `/text` Google language blob removed | ✅ PASS |-| Active tab tracking (P0) | ❌ STILL BROKEN |--**3 of 4 targeted fixes confirmed working.** x.com title remains empty.--**The P0 active tab tracking bug is the main blocker** — it makes sequential navigate→read workflows unreliable. This must be fixed before Pinchtab can be used for multi-site automation.--### Go Tests-`go test ./...` → ✅ all pass (cached)diff --git a/QA.md b/QA.mddeleted file mode 100644index ca711b42..00000000--- a/QA.md+++ /dev/null@@ -1,122 +0,0 @@-# Pinchtab QA Report — 2026-02-15--**Testers:** Bosch, Mario-------## Round 1 — Build 4fc2a3e--### Bugs Found--| # | Severity | Bug | Found by |-|---|----------|-----|----------|-| 1 | 🔴 P0 | Active tab not tracked after `/navigate` — snapshot/text return stale tab | Bosch |-| 2 | 🔴 P0 | Invalid JSON — unescaped control chars in snapshot/text (Yahoo Finance, StackOverflow) | Bosch |-| 3 | 🟡 P1 | `newTab:true` silently ignored on `/navigate` | Mario |-| 4 | 🟡 P1 | Tab close (`POST /tab`) returns 400 — `tabId` field not recognized | Bosch |-| 5 | 🟡 P1 | No tab switch/focus API — no recovery when tracking drifts | Bosch |-| 6 | 🟡 P1 | `/action` missing `kind` returns unhelpful `"unknown action: "` | Mario |-| 7 | 🟢 P2 | `/navigate` returns empty title on some sites (BBC, x.com) — race condition | Mario |-| 8 | 🟢 P2 | `/text` on google.com includes full language picker blob | Mario |-| 9 | 🟢 P2 | Chrome flag warning: `--disable-blink-features=AutomationControlled` | Bosch |-------## Round 2 — Build 723c927 (Mario fixes)--### Re-test Results--| # | Test | Result | Notes |-|---|------|--------|-------|-| 1 | Active tab tracking (1st navigate after startup) | ❌ FAIL | First navigate still returns stale profile tab |-| 2 | Active tab tracking (2nd navigate) | ✅ PASS | Tracks correctly after first |-| 3 | Active tab tracking (3rd navigate) | ✅ PASS | Keeps tracking |-| 4 | JSON validity — Yahoo Finance `/snapshot` | ✅ PASS | **Fixed!** 707 nodes, valid JSON |-| 5 | JSON validity — Yahoo Finance `/text` | ✅ PASS | **Fixed!** |-| 6 | JSON validity — StackOverflow | ✅ PASS | **Fixed!** |-| 7 | Tab close | ❌ FAIL | Now hangs indefinitely instead of 400 (regression) |-| 8 | `/action` error message | ✅ PASS | **Fixed!** Lists valid `kind` values |--### Bug Status After Round 2--| # | Bug | Status |-|---|-----|--------|-| 1 | Active tab tracking | ⚠️ Partial — works after 1st navigate, fails on initial |-| 2 | Invalid JSON | ✅ Fixed |-| 3 | `newTab:true` broken | ❓ Not retested |-| 4 | Tab close | ❌ Regressed — now hangs instead of 400 |-| 5 | No tab switch API | ❌ Still missing |-| 6 | `/action` error message | ✅ Fixed |-| 7 | Empty title on navigate | ❓ Not retested |-| 8 | Google language blob in `/text` | ❓ Not retested |-| 9 | Chrome flag warning | ❌ Still present |--### Remaining Issues (priority order)--1. **Tab close hangs** — regression, was 400 now hangs forever-2. **First navigate doesn't set active tab** — stale profile tabs confuse initial tracking-3. **No tab switch API** — needed for recovery-4. **10 tabs accumulated** during testing with no way to clean up-------## Performance — Token Usage--### Pinchtab `/snapshot` vs `/text` (Mario)--| Site | /snapshot tokens | /text tokens | Savings |-|------|-----------------|-------------|---------|-| Google | ~2K | ~764 | 2.5× |-| GitHub | ~9.8K | ~1.2K | 7.8× |-| x.com | ~2K | ~121 | 17× |-| BBC | ~26.7K | ~3.5K | 7.7× |-| Wikipedia | ~20.5K | ~3.5K | 5.8× |-| LinkedIn | ~7.5K | ~6.1K | 1.2× |--### Pinchtab vs OpenClaw Browser (Bosch)--| Site | Pinchtab snapshot | Pinchtab /text | OpenClaw aria tree |-|------|-------------------|---------------|-------------------|-| Yahoo Finance | ~16K tokens | ~1.4K tokens | ~3.5K tokens |-| Google Finance | ~12K tokens | ~1.1K tokens | ~3.7K tokens |-| Hacker News | ~24K tokens | ~875 tokens | — |--### Key Findings--- **Pinchtab snapshots are 3–4× larger** than OpenClaw aria trees (verbose JSON per node)-- **Pinchtab `/text` is the most token-efficient** (~1K tokens for complex finance pages)-- **OpenClaw aria tree** is the best balance for interactive browsing (~3.5K tokens)-- **Recommendation:** Add a compact text-based snapshot format to close the gap with OpenClaw-------## Retest Results (post-fix, 2026-02-15)--| Bug | Status | Notes |-|-----|--------|-------|-| 🟡 `newTab:true` broken | ✅ FIXED | Creates new CDP tab, returns new tabId |-| 🟡 `/action` unhelpful error | ✅ FIXED | Lists valid `kind` values |-| 🟢 `/navigate` empty title | ✅ PARTIAL | BBC works ("BBC - Home"), x.com still empty (SPA >2s) |-| 🟢 `/text` Google blob | ✅ FIXED | Tokens dropped ~764 → ~143 |-| 🔴 Active tab tracking | ❌ STILL BROKEN | Navigate→read returns stale tab content |--**Active tab tracking remains the critical P0.** After navigating to x.com, `/text` returned Google's content. Sequential navigate→read is unreliable without explicit `tabId` targeting.-------## Sites Tested--**Mario:** Google, GitHub, BBC, Wikipedia, x.com, LinkedIn-**Bosch:** HN, Example.com, Yahoo Finance, Google Finance, Bloomberg, StackOverflow--All loaded fine, no bot detection, zero crashes. ✅--## What Works Well--- ✅ `/navigate` — fast, returns title+URL-- ✅ `/snapshot` — comprehensive a11y tree-- ✅ `/snapshot?filter=interactive` — filters to actionable elements-- ✅ `/text` — clean, compact, token-efficient-- ✅ `/action` with `click` — reliable-- ✅ `/tabs` — accurate listing-- ✅ Fast startup (~3s), headless works, no bot detectiondiff --git a/tests/SPEED-PERFORMANCE-TESTING.md b/tests/SPEED-PERFORMANCE-TESTING.mdnew file mode 100644index 00000000..1f56f0da--- /dev/null+++ b/tests/SPEED-PERFORMANCE-TESTING.md@@ -0,0 +1,147 @@+# Speed Performance Testing++**Goal:** Measure and track endpoint latency so we know where Pinchtab is fast, where it's slow, and whether regressions creep in.++---++## Methodology++### How to Measure++Use `curl` timing or the benchmark script below. All times in milliseconds.++```bash+# Single endpoint timing+curl -o /dev/null -s -w "%{time_total}" localhost:9867/snapshot | awk '{printf "%.0fms\n", $1*1000}'++# With breakdown (DNS, connect, TTFB, total)+curl -o /dev/null -s -w "connect:%{time_connect}s ttfb:%{time_starttransfer}s total:%{time_total}s\n" localhost:9867/snapshot+```++### What to Measure++| Endpoint | Notes |+|----------|-------|+| `GET /health` | Baseline — should be < 1ms |+| `GET /snapshot` | Primary interface — most latency-sensitive |+| `GET /snapshot?filter=interactive` | Should be similar to full snapshot |+| `GET /snapshot?format=text` | Formatting overhead |+| `GET /text` | Includes readability extraction time |+| `GET /screenshot` | Render + encode time |+| `GET /screenshot?raw=true` | Without base64 |+| `POST /action {"kind":"click","ref":"eN"}` | Action execution time |+| `POST /navigate {"url":"..."}` | Includes page load wait |+| `GET /tabs` | Should be instant |+| `GET /cookies` | CDP call overhead |++### Test Conditions++Always document:+- **Headless vs headed** (headless is typically faster)+- **Page state** (what's loaded when measuring snapshot/text)+- **Machine specs** (CPU, RAM, OS)+- **Chrome version**+- **Number of open tabs** (affects memory pressure)++---++## Benchmark Script++```bash+#!/bin/bash+# speed-benchmark.sh — Measure endpoint latency+# Usage: ./speed-benchmark.sh [port] [iterations]++PORT=${1:-9867}+ITERS=${2:-10}+BASE="http://localhost:$PORT"++echo "Pinchtab Speed Benchmark — $ITERS iterations per endpoint"+echo "Port: $PORT"+echo ""++# Navigate to a standard page first+curl -s -X POST "$BASE/navigate" -d '{"url":"https://example.com"}' > /dev/null+sleep 2++endpoints=(+ "GET /health"+ "GET /tabs"+ "GET /snapshot"+ "GET /snapshot?filter=interactive"+ "GET /snapshot?format=text"+ "GET /text"+ "GET /screenshot?raw=true"+)++echo "| Endpoint | Min | Avg | Max | P95 |"+echo "|----------|-----|-----|-----|-----|"++for ep in "${endpoints[@]}"; do+ method=$(echo "$ep" | cut -d' ' -f1)+ path=$(echo "$ep" | cut -d' ' -f2)++ times=()+ for i in $(seq 1 $ITERS); do+ ms=$(curl -o /dev/null -s -w "%{time_total}" "$BASE$path" | awk '{printf "%.0f", $1*1000}')+ times+=("$ms")+ done++ # Sort and compute stats+ sorted=($(printf '%s\n' "${times[@]}" | sort -n))+ min=${sorted[0]}+ max=${sorted[-1]}+ sum=0; for t in "${times[@]}"; do sum=$((sum + t)); done+ avg=$((sum / ITERS))+ p95_idx=$(( (ITERS * 95 / 100) - 1 ))+ [ $p95_idx -lt 0 ] && p95_idx=0+ p95=${sorted[$p95_idx]}++ echo "| $path | ${min}ms | ${avg}ms | ${max}ms | ${p95}ms |"+done++# Action timing (needs a ref from snapshot)+echo ""+echo "Action timing (click on example.com link):"+ref=$(curl -s "$BASE/snapshot?filter=interactive" | python3 -c "import sys,json; nodes=json.load(sys.stdin).get('nodes',[]); print(nodes[0]['ref'] if nodes else 'e0')" 2>/dev/null || echo "e0")+for i in $(seq 1 $ITERS); do+ ms=$(curl -o /dev/null -s -w "%{time_total}" -X POST "$BASE/action" -d "{\"kind\":\"click\",\"ref\":\"$ref\"}" | awk '{printf "%.0f", $1*1000}')+ echo " click: ${ms}ms"+done+```++---++## Baseline Expectations++From previous benchmarks (v0.2.0, headless, MacBook Pro M-series):++| Endpoint | Expected Latency |+|----------|-----------------|+| `/health` | < 1ms |+| `/tabs` | < 5ms |+| `/snapshot` | 20-30ms |+| `/snapshot?filter=interactive` | 20-30ms |+| `/text` | 5-10ms |+| `/screenshot` | 150-250ms |+| `/action` (click) | 5-10ms |+| `/navigate` | 1-5s (page load dependent) |++### Regression Thresholds++Flag a regression if any endpoint is **> 2x** the baseline for the same page/conditions.++---++## Performance Targets++| Metric | Target |+|--------|--------|+| Snapshot latency (simple page) | < 50ms |+| Snapshot latency (complex page) | < 200ms |+| Text extraction | < 50ms |+| Screenshot | < 300ms |+| Action (click/type) | < 20ms |+| Startup to first request | < 5s |+| Memory (idle, 1 tab) | < 200MB |+| Memory (3 tabs, active) | < 500MB |diff --git a/tests/TEST-PLAN.md b/tests/TEST-PLAN.mdnew file mode 100644index 00000000..ac8f0259--- /dev/null+++ b/tests/TEST-PLAN.md@@ -0,0 +1,237 @@+# Pinchtab Test Plan++**Goal:** Establish a repeatable test suite to validate Pinchtab for stable release.++**Scope:** Functional correctness, regression, edge cases. Covers headless and headed modes, single and multi-agent scenarios.++**How to run:** Each scenario can be executed manually via `curl` or scripted. Integration tests requiring Chrome should use build tag `integration`.++---++## 1. Core Endpoints — Headless Single Agent++### 1.1 Health & Startup++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| H1 | Health check | `GET /health` | 200, `{"status":"ok"}` |+| H2 | Startup headless | `BRIDGE_HEADLESS=true ./pinchtab` | Launches, binds port, Chrome not visible |+| H3 | Startup headed | `./pinchtab` | Chrome window opens, visible |+| H4 | Custom port | `BRIDGE_PORT=9999 ./pinchtab` | Binds to 9999 |+| H5 | Auth token required | `BRIDGE_TOKEN=secret ./pinchtab`, then `GET /health` without token | 401 |+| H6 | Auth token accepted | `GET /health` with `Authorization: Bearer secret` | 200 |+| H7 | Graceful shutdown | Send SIGINT | Chrome closes, port released, exit 0 |++### 1.2 Navigation++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| N1 | Basic navigate | `POST /navigate {"url":"https://example.com"}` | 200, title="Example Domain", url matches |+| N2 | Navigate returns title | Navigate to `https://www.bbc.co.uk` | Title = "BBC - Home" (or similar) |+| N3 | Navigate SPA (slow title) | Navigate to `https://x.com` | Title may be empty (known limitation for heavy SPAs) |+| N4 | Navigate with newTab | `POST /navigate {"url":"...","newTab":true}` | New tab created, new tabId returned, tab count +1 |+| N5 | Navigate invalid URL | `POST /navigate {"url":"not-a-url"}` | Error response, no crash |+| N6 | Navigate missing URL | `POST /navigate {}` | 400, clear error message |+| N7 | Navigate bad JSON | `POST /navigate {broken` | 400, JSON parse error |+| N8 | Navigate timeout | Navigate to extremely slow/hanging URL | Returns within timeout, error or partial |++### 1.3 Snapshot (Accessibility Tree)++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| S1 | Basic snapshot | Navigate to example.com, `GET /snapshot` | Valid JSON, nodes array, refs (e0, e1...) |+| S2 | Interactive filter | `GET /snapshot?filter=interactive` | Only buttons, links, inputs returned |+| S3 | Depth filter | `GET /snapshot?depth=2` | Tree truncated at depth 2 |+| S4 | Text format | `GET /snapshot?format=text` | Indented plain text, not JSON |+| S5 | YAML format | `GET /snapshot?format=yaml` | Valid YAML output |+| S6 | Diff mode | Snapshot twice with `?diff=true` on second | Second returns only changes |+| S7 | Diff first call | `GET /snapshot?diff=true` (no prior snapshot) | Full snapshot (no previous to diff against) |+| S8 | File output | `GET /snapshot?output=file&path=/tmp/test.json` | File written, response confirms path |+| S9 | Snapshot with tabId | `GET /snapshot?tabId=<specific>` | Returns snapshot for that specific tab |+| S10 | Snapshot no tab | Close all tabs, `GET /snapshot` | Error: no tab available |+| S11 | Large page | Navigate to Wikipedia article, snapshot | Handles 20K+ token pages without error |+| S12 | Ref stability | Snapshot → click → snapshot | Refs for unchanged elements stay the same |++### 1.4 Text Extraction++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| T1 | Readability mode | Navigate to BBC article, `GET /text` | Clean article text, no nav/ads |+| T2 | Raw mode | `GET /text?mode=raw` | Full innerText including nav/footer |+| T3 | Text with tabId | `GET /text?tabId=<specific>` | Text from correct tab |+| T4 | Text no tab | `GET /text` with no tabs | Error response |+| T5 | Token efficiency | `/text` on Google | ~150 tokens (not 700+, language blob removed) |++### 1.5 Actions++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| A1 | Click by ref | Snapshot, find button ref, `POST /action {"kind":"click","ref":"eN"}` | Click executed, page state changes |+| A2 | Type by ref | Find input ref, `POST /action {"kind":"type","ref":"eN","text":"hello"}` | Text entered in input |+| A3 | Fill by ref | `POST /action {"kind":"fill","ref":"eN","text":"hello"}` | Input value set (no key events) |+| A4 | Press key | `POST /action {"kind":"press","key":"Enter"}` | Key pressed |+| A5 | Focus | `POST /action {"kind":"focus","ref":"eN"}` | Element focused |+| A6 | Hover | `POST /action {"kind":"hover","ref":"eN"}` | Hover state triggered |+| A7 | Select option | Find select ref, `POST /action {"kind":"select","ref":"eN","value":"opt1"}` | Option selected |+| A8 | Scroll | `POST /action {"kind":"scroll","direction":"down"}` | Page scrolls |+| A9 | Unknown kind | `POST /action {"kind":"dance"}` | 400, lists valid kinds |+| A10 | Missing kind | `POST /action {"ref":"e0"}` | 400, clear error about missing kind |+| A11 | Ref not found | `POST /action {"kind":"click","ref":"e9999"}` | Error: ref not found |+| A12 | CSS selector | `POST /action {"kind":"click","selector":"#submit"}` | Click by CSS selector |+| A13 | Action no tab | Close tabs, `POST /action {"kind":"click","ref":"e0"}` | Error: no tab |+| A14 | Batch actions | `POST /actions [{"kind":"click","ref":"e1"},{"kind":"type","ref":"e2","text":"hi"}]` | Both executed in order |+| A15 | Batch empty | `POST /actions []` | Error: empty batch |+| A16 | Human click | `POST /action {"kind":"humanClick","ref":"eN"}` | Bezier mouse movement + click |+| A17 | Human type | `POST /action {"kind":"humanType","ref":"eN","text":"hello"}` | Natural typing with variable delays |++### 1.6 Tabs++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| TB1 | List tabs | `GET /tabs` | Array of tab objects with id, url, title |+| TB2 | New tab | `POST /tab {"action":"new","url":"https://example.com"}` | New tab opened, id returned |+| TB3 | Close tab | `POST /tab {"action":"close","tabId":"<id>"}` | Tab closed, tab count -1 |+| TB4 | Close without tabId | `POST /tab {"action":"close"}` | 400, tabId required |+| TB5 | Bad action | `POST /tab {"action":"explode"}` | 400, invalid action |+| TB6 | Max tabs | Open 3+ tabs (default limit) | Error or blocks at limit |++### 1.7 Screenshots++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| SS1 | Basic screenshot | `GET /screenshot` | JPEG image data |+| SS2 | Raw screenshot | `GET /screenshot?raw=true` | Raw JPEG bytes (no base64) |+| SS3 | Screenshot no tab | `GET /screenshot` with no tabs | Error |++### 1.8 JavaScript Evaluation++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| E1 | Simple eval | `POST /evaluate {"expression":"1+1"}` | `{"result":"2"}` |+| E2 | DOM eval | `POST /evaluate {"expression":"document.title"}` | Returns page title |+| E3 | Missing expression | `POST /evaluate {}` | 400, error message |+| E4 | Bad JSON | `POST /evaluate {broken` | 400, parse error |+| E5 | Eval no tab | `POST /evaluate {"expression":"1"}` with no tabs | Error |++### 1.9 Cookies++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| C1 | Get cookies | Navigate to site, `GET /cookies` | Returns cookie array |+| C2 | Set cookies | `POST /cookies {"url":"...","cookies":[...]}` | Cookies set |+| C3 | Get cookies no tab | `GET /cookies` with no tabs | Error |+| C4 | Set cookies bad JSON | `POST /cookies {broken` | 400 |+| C5 | Set cookies empty | `POST /cookies {"url":"...","cookies":[]}` | Error or no-op |++### 1.10 Stealth++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| ST1 | Stealth status | `GET /stealth/status` | JSON with feature booleans and score |+| ST2 | Webdriver hidden | Navigate, eval `navigator.webdriver` | `undefined` |+| ST3 | Chrome runtime present | Eval `!!window.chrome.runtime` | `true` |+| ST4 | Plugins present | Eval `navigator.plugins.length` | > 0 |+| ST5 | Fingerprint rotate | `POST /fingerprint/rotate {"os":"windows"}` | New fingerprint applied |+| ST6 | Fingerprint rotate random | `POST /fingerprint/rotate {}` | Random OS selected |+| ST7 | Fingerprint no tab | `POST /fingerprint/rotate {}` with no tabs | Error |+| ST8 | Bot detection site | Navigate to `bot.sannysoft.com` | Most checks pass (green) |++### 1.11 Configuration++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| CF1 | Config file | Create `~/.pinchtab/config.json` with port override, start | Uses config port |+| CF2 | Env overrides config | Set `BRIDGE_PORT` env + config file port | Env wins |+| CF3 | CDP_URL external Chrome | `CDP_URL=ws://... ./pinchtab` | Connects to existing Chrome, no launch |+| CF4 | Custom profile dir | `BRIDGE_PROFILE=/tmp/test-profile ./pinchtab` | Uses specified profile |+| CF5 | No restore | `BRIDGE_NO_RESTORE=true ./pinchtab` | Doesn't restore previous tabs |++### 1.12 Session Persistence++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| SP1 | Tab restore | Open tabs, stop, restart | Previous tabs restored |+| SP2 | Cookie persistence | Log into site, restart | Still logged in |+| SP3 | No restore flag | Open tabs, restart with `BRIDGE_NO_RESTORE=true` | Clean start, no old tabs |++---++## 2. Headed Mode — Additional Scenarios++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| HM1 | Chrome visible | Start without `BRIDGE_HEADLESS` | Chrome window visible, interactable |+| HM2 | Manual + API coexist | Manually browse in Chrome + API calls | Both work, no conflicts |+| HM3 | Manual login persists | Log into GitHub manually in Chrome window | `/cookies` shows session, persists on restart |++---++## 3. Multi-Agent Scenarios++Multiple agents (or concurrent scripts) hitting the same Pinchtab instance.++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| MA1 | Concurrent reads | Two agents snapshot different tabs by tabId simultaneously | Both get correct results |+| MA2 | Concurrent navigates | Agent A navigates tab1, Agent B navigates tab2 (by tabId) | Both succeed, no cross-talk |+| MA3 | Tab isolation | Agent A works on tab1, Agent B on tab2 | Actions don't leak across tabs |+| MA4 | Concurrent actions | Agent A clicks on tab1, Agent B types on tab2 | Both succeed |+| MA5 | Ref collision | Both agents snapshot same tab, get same refs | Refs consistent, actions work for both |+| MA6 | Rapid fire | 10 concurrent `/snapshot` requests | All return valid data, no 500s |+| MA7 | Tab limit | Two agents both try to open tabs up to limit | One gets error, no crash |+| MA8 | No tabId default | Agent A navigates, Agent B calls `/snapshot` (no tabId) | Returns *some* tab (undefined which — this is the active tab tracking issue) |++---++## 4. Error Handling & Edge Cases++| # | Scenario | Steps | Expected |+|---|----------|-------|----------|+| ER1 | Chrome crash recovery | Kill Chrome process while Pinchtab running | Pinchtab detects, returns errors (not hang) |+| ER2 | Large page snapshot | Navigate to page with 1000+ a11y nodes | Returns full snapshot, no timeout |+| ER3 | Binary page | Navigate to PDF/image URL | Handles gracefully (error or empty snapshot) |+| ER4 | Rapid navigate | 5 navigates in 1 second | No crash, last one wins |+| ER5 | Unicode content | Navigate to page with CJK/emoji/RTL | Text and snapshot handle correctly |+| ER6 | Empty page | Navigate to `about:blank` | Snapshot returns minimal tree |+| ER7 | Connection refused (CDP_URL) | `CDP_URL=ws://localhost:1111` | Clear error message, exits |+| ER8 | Port in use | Start two instances on same port | Second fails with clear error |++---++## 5. Known Issues (from QA rounds)++Track these separately — they are known bugs, not test failures.++| # | Issue | Severity | Status | Notes |+|---|-------|----------|--------|-------|+| K1 | Active tab tracking unreliable after navigate | 🔴 P0 | OPEN | `/text` and `/snapshot` return stale tab. Workaround: always pass `tabId` explicitly. |+| K2 | Tab close hangs | 🟡 P1 | OPEN | Regression from Round 2 fixes. Was 400, now hangs indefinitely. |+| K3 | x.com title always empty | 🟢 P2 | OPEN | SPA hydration too slow for navigate timeout. |+| K4 | Chrome flag warning banner | 🟢 P2 | OPEN | `--disable-blink-features=AutomationControlled` deprecated in Chrome 144+. |+| K5 | Stealth PRNG weak (8F-2) | 🟡 P1 | OPEN | `Math.sin` seeded PRNG, session seed may drift between navigations. |+| K6 | Chrome UA hardcoded to 131 (8F-6) | 🟡 P1 | OPEN | Current stable is 133+. |+| K7 | Fingerprint rotation JS-only (8F-7) | 🟢 P2 | OPEN | Detectable via `getOwnPropertyDescriptor`. |+| K8 | Timezone hardcoded EST (8F-9) | 🟢 P2 | OPEN | `Intl.DateTimeFormat` leaks real TZ. |+| K9 | Stealth status hardcoded (8F-10) | 🟢 P2 | OPEN | No actual browser probing. |++---++## 6. Release Criteria for Stable v1.0++### Must Pass (P0)+- All Section 1 scenarios (core endpoints) pass in headless+- All Section 1 scenarios pass in headed+- K1 (active tab tracking) fixed OR documented as "always use tabId"+- K2 (tab close hangs) fixed+- Zero crashes across full test suite+- `go test ./...` 100% pass++### Should Pass (P1)+- Section 3 multi-agent scenarios MA1-MA5 pass+- Stealth passes `bot.sannysoft.com` basic checks+- Session persistence works (SP1, SP2)++### Nice to Have (P2)+- Coverage > 30%+- K3-K9 addressed or documented+- Performance benchmarks baselineddiff --git a/tests/TOKEN-PERFORMANCE-TESTING.md b/tests/TOKEN-PERFORMANCE-TESTING.mdnew file mode 100644index 00000000..3f61a63b--- /dev/null+++ b/tests/TOKEN-PERFORMANCE-TESTING.md@@ -0,0 +1,120 @@+# Token Performance Testing++**Goal:** Measure and track how many LLM tokens Pinchtab endpoints consume per page, so we can optimize for cost.++---++## Methodology++### How to Measure Tokens++Tokens ≈ bytes / 4 (rough estimate for English text). For precise counts, pipe output through a tokenizer (e.g. `tiktoken` for OpenAI, or just use byte count / 4).++```bash+# Measure snapshot tokens (approximate)+curl -s localhost:9867/snapshot | wc -c | awk '{print int($1/4)" tokens"}'++# Measure text tokens+curl -s localhost:9867/text | wc -c | awk '{print int($1/4)" tokens"}'++# Measure interactive-only snapshot+curl -s "localhost:9867/snapshot?filter=interactive" | wc -c | awk '{print int($1/4)" tokens"}'++# Measure text format snapshot+curl -s "localhost:9867/snapshot?format=text" | wc -c | awk '{print int($1/4)" tokens"}'+```++### Test Sites (standard set)++Use these consistently across versions for comparable results:++| Site | Type | Why |+|------|------|-----|+| `https://example.com` | Minimal static | Baseline / sanity check |+| `https://www.google.com` | Search engine | Common use case, forms |+| `https://github.com` | Web app | Auth, dynamic content |+| `https://www.bbc.co.uk` | News site | Heavy content, lots of nav |+| `https://en.wikipedia.org/wiki/Go_(programming_language)` | Reference | Long-form content |+| `https://news.ycombinator.com` | Link list | Repetitive structure |+| `https://x.com` | SPA | Client-rendered, auth-gated |++### Endpoints to Measure++For each site, record tokens for:++| Endpoint | What it measures |+|----------|-----------------|+| `GET /snapshot` | Full accessibility tree (JSON) |+| `GET /snapshot?filter=interactive` | Interactive elements only |+| `GET /snapshot?format=text` | Text format (indented tree) |+| `GET /text` | Readability extraction |+| `GET /text?mode=raw` | Raw innerText |++---++## Test Script++```bash+#!/bin/bash+# token-benchmark.sh — Run against a live Pinchtab instance+# Usage: ./token-benchmark.sh [port]++PORT=${1:-9867}+BASE="http://localhost:$PORT"++SITES=(+ "https://example.com"+ "https://www.google.com"+ "https://github.com"+ "https://www.bbc.co.uk"+ "https://en.wikipedia.org/wiki/Go_(programming_language)"+ "https://news.ycombinator.com"+)++echo "| Site | /snapshot | ?filter=interactive | ?format=text | /text | /text?mode=raw |"+echo "|------|----------|---------------------|-------------|-------|----------------|"++for site in "${SITES[@]}"; do+ # Navigate+ curl -s -X POST "$BASE/navigate" -d "{\"url\":\"$site\"}" > /dev/null+ sleep 3++ # Measure each endpoint+ snap=$(curl -s "$BASE/snapshot" | wc -c | awk '{print int($1/4)}')+ interactive=$(curl -s "$BASE/snapshot?filter=interactive" | wc -c | awk '{print int($1/4)}')+ text_fmt=$(curl -s "$BASE/snapshot?format=text" | wc -c | awk '{print int($1/4)}')+ text=$(curl -s "$BASE/text" | wc -c | awk '{print int($1/4)}')+ raw=$(curl -s "$BASE/text?mode=raw" | wc -c | awk '{print int($1/4)}')++ name=$(echo "$site" | sed 's|https://||' | sed 's|www.||' | cut -d'/' -f1)+ echo "| $name | ~${snap} | ~${interactive} | ~${text_fmt} | ~${text} | ~${raw} |"+done+```++---++## What to Track Per Version++For each release, record:++1. **Token counts per endpoint per site** (the table above)+2. **Comparison vs previous version** (regression or improvement)+3. **Snapshot JSON node count** — `curl -s /snapshot | jq '.nodes | length'`+4. **Text format vs JSON ratio** — how much cheaper is `?format=text`++---++## Optimization Targets++| Metric | Current (v0.3.0) | Target |+|--------|-------------------|--------|+| `/text` on news site | ~3,500 tokens | < 3,000 |+| `/snapshot` vs OpenClaw aria | 3-4x larger | < 2x larger |+| `?filter=interactive` vs full | ~60-75% reduction | maintain |+| `?format=text` vs JSON | ~40-60% reduction | maintain |++### Known Optimization Opportunities++- **Snapshot JSON is verbose** — each node has full property objects. A compact format could halve tokens.+- **`/text` on content-heavy sites** — readability extraction is good but still includes some boilerplate.+- **`?format=text` indentation** — uses spaces; could use minimal indentation to save bytes.diff --git a/tests/v0.3.0-performance-history.md b/tests/v0.3.0-performance-history.mdnew file mode 100644index 00000000..91049eaa--- /dev/null+++ b/tests/v0.3.0-performance-history.md@@ -0,0 +1,113 @@+# Pinchtab v0.3.0 Performance History++**Collected:** 2026-02-15, from QA rounds by Bosch and Mario.+**Build:** v0.3.0 (commits 4fc2a3e through c41d2cd)+**Machine:** MacBook Pro (Apple Silicon), Chrome headless+**Go test suite:** 71 tests, 24.6% coverage, all passing++---++## Token Performance++### Full Snapshot (`GET /snapshot`) — Tokens by Site++| Site | Tokens | Notes |+|------|--------|-------|+| Google | ~848 | Down from ~2K after language picker fix |+| GitHub | ~9,835 | Stable |+| x.com | ~2,000 | Measured when active tab worked |+| BBC | ~26,598 | Heavy nav + content |+| Wikipedia | ~20,474 | Long-form article |+| LinkedIn | ~7,500 | Measured when active tab worked |+| Yahoo Finance | ~16,000 | Complex finance page |+| Google Finance | ~12,000 | Finance widgets |+| Hacker News | ~24,000 | Many repetitive link nodes |++### Text Extraction (`GET /text`) — Tokens by Site++| Site | Tokens | Notes |+|------|--------|-------|+| Google | ~143 | Dramatically improved after language blob fix (was ~764) |+| GitHub | ~1,249 | Stable |+| x.com | ~121 | Very compact (mostly auth wall) |+| BBC | ~3,479 | Article content |+| Wikipedia | ~3,306 | Long-form |+| LinkedIn | ~6,100 | Heavy (includes sidebar content) |+| Yahoo Finance | ~1,400 | Good compression |+| Google Finance | ~1,100 | Clean extraction |+| Hacker News | ~875 | Compact |++### Snapshot vs Text Savings++| Site | /snapshot | /text | Savings |+|------|----------|-------|---------|+| Google | ~848 | ~143 | **5.9×** |+| GitHub | ~9,835 | ~1,249 | **7.9×** |+| x.com | ~2,000 | ~121 | **16.5×** |+| BBC | ~26,598 | ~3,479 | **7.6×** |+| Wikipedia | ~20,474 | ~3,306 | **6.2×** |+| LinkedIn | ~7,500 | ~6,100 | **1.2×** |++**Average savings:** `/text` is **~7.5× cheaper** than full snapshot.++### Pinchtab vs OpenClaw Browser Comparison++| Site | Pinchtab /snapshot | Pinchtab /text | OpenClaw aria tree |+|------|-------------------|---------------|-------------------|+| Yahoo Finance | ~16,000 | ~1,400 | ~3,500 |+| Google Finance | ~12,000 | ~1,100 | ~3,700 |++**Key finding:** Pinchtab snapshots are **3-4× larger** than OpenClaw aria trees (verbose JSON per node). Pinchtab `/text` is **2.5-3× cheaper** than OpenClaw aria trees.++---++## Speed Performance++### Endpoint Latency (from Bosch benchmark, v0.2.0 build)++| Endpoint | Latency | Notes |+|----------|---------|-------|+| `/snapshot` | ~26ms | Accessibility tree fetch |+| `/screenshot` | ~200ms | JPEG render + encode |+| `/text` | ~7ms | Readability extraction |+| `/action` (click) | ~7ms | CDP click dispatch |++### Startup++- Cold start to first request: ~3 seconds (headless)+- Chrome launch + profile load included++---++## Stability++### Sites Tested Successfully (no crashes, no bot detection)++Google, GitHub, BBC, Wikipedia, x.com, LinkedIn, Yahoo Finance, Google Finance, Bloomberg, StackOverflow, Hacker News, Example.com++### Known Stability Issues++| Issue | Severity | Impact |+|-------|----------|--------|+| Active tab tracking drift | 🔴 P0 | Sequential navigate→read returns stale tab without explicit tabId |+| Tab close hangs | 🟡 P1 | `POST /tab {"action":"close"}` hangs indefinitely |+| x.com title always empty | 🟢 P2 | SPA hydration too slow for navigate timeout |++---++## Go Test Performance++```+71 tests, 0.2s total runtime+24.6% statement coverage+0 failures, 0 flaky tests+```++---++## Recommendations (from QA)++1. **Always use explicit `tabId`** — active tab tracking is unreliable+2. **Use `/text` for read-only tasks** — 7-16× cheaper than snapshots+3. **Use `?filter=interactive` when acting** — 60-75% fewer tokens than full snapshot+4. **Investigate compact snapshot format** — closing the 3-4× gap with OpenClaw aria trees would be high-value