High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
test: add integration test suite with CI workflow
Marioff1c80167e6d
diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.ymlnew file mode 100644index 00000000..d749ec3e--- /dev/null+++ b/.github/workflows/integration.yml@@ -0,0 +1,36 @@+name: Integration Tests++on:+ push:+ branches: [main]+ pull_request:+ branches: [main]+ workflow_dispatch:++permissions:+ contents: read++jobs:+ integration:+ name: Integration Tests+ runs-on: ubuntu-latest+ timeout-minutes: 10+ steps:+ - uses: actions/checkout@v4++ - uses: actions/setup-go@v5+ with:+ go-version: '1.26'++ - name: Install Chromium+ run: |+ sudo apt-get update+ sudo apt-get install -y chromium-browser+ echo "CHROME_BINARY=$(which chromium-browser)" >> $GITHUB_ENV++ - name: Run integration tests+ run: go test -tags integration -v -timeout 5m -count=1 ./tests/integration/+ env:+ BRIDGE_HEADLESS: "true"+ BRIDGE_NO_RESTORE: "true"+ PINCHTAB_TEST_PORT: "19867"diff --git a/tests/integration/actions_test.go b/tests/integration/actions_test.gonew file mode 100644index 00000000..e5760649--- /dev/null+++ b/tests/integration/actions_test.go@@ -0,0 +1,211 @@+//go:build integration++package integration++import (+ "encoding/json"+ "strings"+ "testing"+)++// A1: Click by ref — navigate to example.com, find the "More information..." link, click it+func TestAction_Click(t *testing.T) {+ navigate(t, "https://example.com")++ // Get snapshot to find a clickable ref+ _, snapBody := httpGet(t, "/snapshot?filter=interactive&format=text")+ s := string(snapBody)++ // Find a ref like [e0] or [e1] for the link+ ref := findRef(s, "link")+ if ref == "" {+ t.Skip("no clickable link ref found in snapshot")+ }++ code, _ := httpPost(t, "/action", map[string]string{+ "kind": "click",+ "ref": ref,+ })+ if code != 200 {+ t.Errorf("click failed with %d", code)+ }+}++// A4: Press key+func TestAction_Press(t *testing.T) {+ navigate(t, "https://example.com")+ code, _ := httpPost(t, "/action", map[string]string{+ "kind": "press",+ "key": "Escape",+ })+ if code != 200 {+ t.Errorf("press failed with %d", code)+ }+}++// A9: Unknown kind+func TestAction_UnknownKind(t *testing.T) {+ code, _ := httpPost(t, "/action", map[string]string{"kind": "dance"})+ if code != 400 {+ t.Errorf("expected 400 for unknown kind, got %d", code)+ }+}++// A10: Missing kind+func TestAction_MissingKind(t *testing.T) {+ code, _ := httpPost(t, "/action", map[string]string{"ref": "e0"})+ if code != 400 {+ t.Errorf("expected 400 for missing kind, got %d", code)+ }+}++// A11: Ref not found+func TestAction_RefNotFound(t *testing.T) {+ navigate(t, "https://example.com")+ code, _ := httpPost(t, "/action", map[string]string{+ "kind": "click",+ "ref": "e9999",+ })+ // Should be an error (400 or 500)+ if code == 200 {+ t.Error("expected error for non-existent ref")+ }+}++// A12: CSS selector click+func TestAction_CSSSelector(t *testing.T) {+ navigate(t, "https://example.com")+ code, _ := httpPost(t, "/action", map[string]string{+ "kind": "click",+ "selector": "a",+ })+ if code != 200 {+ t.Errorf("CSS selector click failed with %d", code)+ }+}++// Helper: find a ref for a given role in text snapshot+func findRef(snapshot string, role string) string {+ lines := strings.Split(snapshot, "\n")+ for _, line := range lines {+ if strings.Contains(strings.ToLower(line), role) {+ // Look for [eN] pattern+ idx := strings.Index(line, "[e")+ if idx >= 0 {+ end := strings.Index(line[idx:], "]")+ if end > 0 {+ return line[idx+1 : idx+end]+ }+ }+ // Also try eN at start of line+ trimmed := strings.TrimSpace(line)+ if len(trimmed) > 1 && trimmed[0] == 'e' {+ parts := strings.Fields(trimmed)+ if len(parts) > 0 && len(parts[0]) <= 5 {+ return parts[0]+ }+ }+ }+ }+ return ""+}++// A2: Type by ref — need an input element+func TestAction_Type(t *testing.T) {+ // Navigate to httpbin form+ navigate(t, "https://httpbin.org/forms/post")++ _, snapBody := httpGet(t, "/snapshot?filter=interactive&format=text")+ ref := findRef(string(snapBody), "textbox")+ if ref == "" {+ ref = findRef(string(snapBody), "input")+ }+ if ref == "" {+ t.Skip("no input ref found")+ }++ code, _ := httpPost(t, "/action", map[string]any{+ "kind": "type",+ "ref": ref,+ "text": "test input",+ })+ if code != 200 {+ t.Errorf("type failed with %d", code)+ }+}++// A3: Fill by ref+func TestAction_Fill(t *testing.T) {+ navigate(t, "https://httpbin.org/forms/post")++ _, snapBody := httpGet(t, "/snapshot?filter=interactive&format=text")+ ref := findRef(string(snapBody), "textbox")+ if ref == "" {+ ref = findRef(string(snapBody), "input")+ }+ if ref == "" {+ t.Skip("no input ref found")+ }++ code, _ := httpPost(t, "/action", map[string]any{+ "kind": "fill",+ "ref": ref,+ "text": "filled value",+ })+ if code != 200 {+ t.Errorf("fill failed with %d", code)+ }+}++// A5: Focus+func TestAction_Focus(t *testing.T) {+ navigate(t, "https://httpbin.org/forms/post")++ _, snapBody := httpGet(t, "/snapshot?filter=interactive&format=text")+ ref := findRef(string(snapBody), "textbox")+ if ref == "" {+ t.Skip("no focusable ref found")+ }++ code, _ := httpPost(t, "/action", map[string]string{+ "kind": "focus",+ "ref": ref,+ })+ if code != 200 {+ t.Errorf("focus failed with %d", code)+ }+}++// A8: Scroll+func TestAction_Scroll(t *testing.T) {+ navigate(t, "https://example.com")+ code, _ := httpPost(t, "/action", map[string]string{+ "kind": "scroll",+ "direction": "down",+ })+ if code != 200 {+ t.Errorf("scroll failed with %d", code)+ }+}++// Batch actions (A14)+func TestAction_Batch(t *testing.T) {+ navigate(t, "https://example.com")+ actions := []map[string]string{+ {"kind": "press", "key": "Escape"},+ {"kind": "scroll", "direction": "down"},+ }+ data, _ := json.Marshal(actions)+ code, _ := httpPostRaw(t, "/actions", string(data))+ if code != 200 {+ t.Errorf("batch actions failed with %d", code)+ }+}++// A15: Batch empty+func TestAction_BatchEmpty(t *testing.T) {+ code, _ := httpPostRaw(t, "/actions", "[]")+ if code != 400 {+ t.Errorf("expected 400 for empty batch, got %d", code)+ }+}diff --git a/tests/integration/eval_test.go b/tests/integration/eval_test.gonew file mode 100644index 00000000..692f1bfc--- /dev/null+++ b/tests/integration/eval_test.go@@ -0,0 +1,49 @@+//go:build integration++package integration++import (+ "testing"+)++// E1: Simple eval+func TestEval_Simple(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpPost(t, "/evaluate", map[string]string{"expression": "1+1"})+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ result := jsonField(t, body, "result")+ if result != "2" {+ t.Errorf("expected result '2', got %q", result)+ }+}++// E2: DOM eval+func TestEval_DOM(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpPost(t, "/evaluate", map[string]string{"expression": "document.title"})+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ result := jsonField(t, body, "result")+ if result != "Example Domain" {+ t.Errorf("expected 'Example Domain', got %q", result)+ }+}++// E3: Missing expression+func TestEval_MissingExpression(t *testing.T) {+ code, _ := httpPost(t, "/evaluate", map[string]string{})+ if code != 400 {+ t.Errorf("expected 400, got %d", code)+ }+}++// E4: Bad JSON+func TestEval_BadJSON(t *testing.T) {+ code, _ := httpPostRaw(t, "/evaluate", "{broken")+ if code != 400 {+ t.Errorf("expected 400, got %d", code)+ }+}diff --git a/tests/integration/health_test.go b/tests/integration/health_test.gonew file mode 100644index 00000000..8806c416--- /dev/null+++ b/tests/integration/health_test.go@@ -0,0 +1,25 @@+//go:build integration++package integration++import (+ "encoding/json"+ "testing"+)++// H1: Health check+func TestHealth(t *testing.T) {+ code, body := httpGet(t, "/health")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ var m map[string]any+ if err := json.Unmarshal(body, &m); err != nil {+ t.Fatalf("invalid json: %v", err)+ }+ if m["status"] != "ok" {+ t.Errorf("expected status ok, got %v", m["status"])+ }+}++// H5/H6: Auth tested separately (needs token config)diff --git a/tests/integration/main_test.go b/tests/integration/main_test.gonew file mode 100644index 00000000..cb73289f--- /dev/null+++ b/tests/integration/main_test.go@@ -0,0 +1,185 @@+//go:build integration++package integration++import (+ "encoding/json"+ "fmt"+ "io"+ "net/http"+ "os"+ "os/exec"+ "strings"+ "testing"+ "time"+)++var serverURL string++func TestMain(m *testing.M) {+ port := os.Getenv("PINCHTAB_TEST_PORT")+ if port == "" {+ port = "19867"+ }+ serverURL = fmt.Sprintf("http://localhost:%s", port)++ // Build the binary+ build := exec.Command("go", "build", "-o", "/tmp/pinchtab-test", "./cmd/pinchtab/")+ build.Dir = findRepoRoot()+ build.Stdout = os.Stdout+ build.Stderr = os.Stderr+ if err := build.Run(); err != nil {+ fmt.Fprintf(os.Stderr, "failed to build pinchtab: %v\n", err)+ os.Exit(1)+ }++ // Start server+ cmd := exec.Command("/tmp/pinchtab-test")+ cmd.Env = append(os.Environ(),+ "BRIDGE_PORT="+port,+ "BRIDGE_HEADLESS=true",+ "BRIDGE_NO_RESTORE=true",+ "BRIDGE_STEALTH=light",+ fmt.Sprintf("BRIDGE_STATE_DIR=%s", mustTempDir()),+ fmt.Sprintf("BRIDGE_PROFILE=%s", mustTempDir()),+ )+ cmd.Stdout = os.Stdout+ cmd.Stderr = os.Stderr++ if err := cmd.Start(); err != nil {+ fmt.Fprintf(os.Stderr, "failed to start pinchtab: %v\n", err)+ os.Exit(1)+ }++ // Wait for server to be ready+ if !waitForHealth(serverURL, 30*time.Second) {+ fmt.Fprintf(os.Stderr, "pinchtab did not become healthy within timeout\n")+ _ = cmd.Process.Kill()+ os.Exit(1)+ }++ code := m.Run()++ // Shutdown+ _ = cmd.Process.Signal(os.Interrupt)+ done := make(chan error, 1)+ go func() { done <- cmd.Wait() }()+ select {+ case <-done:+ case <-time.After(10 * time.Second):+ _ = cmd.Process.Kill()+ }++ os.Exit(code)+}++func findRepoRoot() string {+ // Walk up from test dir to find go.mod+ dir, _ := os.Getwd()+ for {+ if _, err := os.Stat(dir + "/go.mod"); err == nil {+ return dir+ }+ parent := dir[:strings.LastIndex(dir, "/")]+ if parent == dir {+ break+ }+ dir = parent+ }+ // fallback+ return "../.."+}++func mustTempDir() string {+ d, err := os.MkdirTemp("", "pinchtab-test-*")+ if err != nil {+ panic(err)+ }+ return d+}++func waitForHealth(base string, timeout time.Duration) bool {+ deadline := time.Now().Add(timeout)+ for time.Now().Before(deadline) {+ resp, err := http.Get(base + "/health")+ if err == nil && resp.StatusCode == 200 {+ _ = resp.Body.Close()+ return true+ }+ if resp != nil {+ _ = resp.Body.Close()+ }+ time.Sleep(500 * time.Millisecond)+ }+ return false+}++// helpers++func httpGet(t *testing.T, path string) (int, []byte) {+ t.Helper()+ resp, err := http.Get(serverURL + path)+ if err != nil {+ t.Fatalf("GET %s failed: %v", path, err)+ }+ defer resp.Body.Close() //nolint:errcheck+ body, _ := io.ReadAll(resp.Body)+ return resp.StatusCode, body+}++func httpPost(t *testing.T, path string, payload any) (int, []byte) {+ t.Helper()+ var reader io.Reader+ if payload != nil {+ data, err := json.Marshal(payload)+ if err != nil {+ t.Fatalf("marshal failed: %v", err)+ }+ reader = strings.NewReader(string(data))+ }+ resp, err := http.Post(serverURL+path, "application/json", reader)+ if err != nil {+ t.Fatalf("POST %s failed: %v", path, err)+ }+ defer resp.Body.Close() //nolint:errcheck+ body, _ := io.ReadAll(resp.Body)+ return resp.StatusCode, body+}++func httpPostRaw(t *testing.T, path string, body string) (int, []byte) {+ t.Helper()+ resp, err := http.Post(serverURL+path, "application/json", strings.NewReader(body))+ if err != nil {+ t.Fatalf("POST %s failed: %v", path, err)+ }+ defer resp.Body.Close() //nolint:errcheck+ data, _ := io.ReadAll(resp.Body)+ return resp.StatusCode, data+}++func jsonField(t *testing.T, data []byte, key string) string {+ t.Helper()+ var m map[string]any+ if err := json.Unmarshal(data, &m); err != nil {+ t.Fatalf("json parse failed: %v (body: %s)", err, string(data))+ }+ v, ok := m[key]+ if !ok {+ return ""+ }+ switch val := v.(type) {+ case string:+ return val+ default:+ b, _ := json.Marshal(val)+ return string(b)+ }+}++func navigate(t *testing.T, url string) {+ t.Helper()+ code, _ := httpPost(t, "/navigate", map[string]string{"url": url})+ if code != 200 {+ t.Fatalf("navigate to %s failed with %d", url, code)+ }+}diff --git a/tests/integration/navigate_test.go b/tests/integration/navigate_test.gonew file mode 100644index 00000000..bd917b93--- /dev/null+++ b/tests/integration/navigate_test.go@@ -0,0 +1,72 @@+//go:build integration++package integration++import (+ "encoding/json"+ "testing"+)++// N1: Basic navigate+func TestNavigate_Basic(t *testing.T) {+ code, body := httpPost(t, "/navigate", map[string]string{"url": "https://example.com"})+ if code != 200 {+ t.Fatalf("expected 200, got %d (body: %s)", code, body)+ }+ title := jsonField(t, body, "title")+ if title != "Example Domain" {+ t.Errorf("expected title 'Example Domain', got %q", title)+ }+}++// N5: Navigate invalid URL+func TestNavigate_InvalidURL(t *testing.T) {+ code, _ := httpPost(t, "/navigate", map[string]string{"url": "not-a-url"})+ if code == 200 {+ t.Error("expected error for invalid URL")+ }+}++// N6: Navigate missing URL+func TestNavigate_MissingURL(t *testing.T) {+ code, _ := httpPost(t, "/navigate", map[string]string{})+ if code != 400 {+ t.Errorf("expected 400, got %d", code)+ }+}++// N7: Navigate bad JSON+func TestNavigate_BadJSON(t *testing.T) {+ code, _ := httpPostRaw(t, "/navigate", "{broken")+ if code != 400 {+ t.Errorf("expected 400, got %d", code)+ }+}++// N2: Navigate returns title+func TestNavigate_ReturnsTitle(t *testing.T) {+ code, body := httpPost(t, "/navigate", map[string]string{"url": "https://httpbin.org/html"})+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ title := jsonField(t, body, "title")+ if title == "" {+ t.Error("expected non-empty title")+ }+}++// N4: Navigate with newTab+func TestNavigate_NewTab(t *testing.T) {+ code, body := httpPost(t, "/navigate", map[string]any{+ "url": "https://example.com",+ "newTab": true,+ })+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ var m map[string]any+ _ = json.Unmarshal(body, &m)+ if m["tabId"] == nil || m["tabId"] == "" {+ t.Error("expected tabId in response for newTab")+ }+}diff --git a/tests/integration/pdf_test.go b/tests/integration/pdf_test.gonew file mode 100644index 00000000..b36e3bc5--- /dev/null+++ b/tests/integration/pdf_test.go@@ -0,0 +1,88 @@+//go:build integration++package integration++import (+ "encoding/base64"+ "os"+ "testing"+)++// PD1: PDF base64+func TestPDF_Base64(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/pdf")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ b64 := jsonField(t, body, "base64")+ if b64 == "" {+ t.Error("expected base64 field in response")+ return+ }+ data, err := base64.StdEncoding.DecodeString(b64)+ if err != nil {+ t.Fatalf("invalid base64: %v", err)+ }+ if len(data) < 4 || string(data[:4]) != "%PDF" {+ t.Error("decoded data is not a PDF")+ }+}++// PD2: PDF raw bytes+func TestPDF_Raw(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/pdf?raw=true")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ if len(body) < 4 || string(body[:4]) != "%PDF" {+ t.Error("expected raw PDF data")+ }+}++// PD3: PDF save to file+func TestPDF_SaveFile(t *testing.T) {+ navigate(t, "https://example.com")+ tmp, _ := os.CreateTemp("", "pinchtab-test-*.pdf")+ _ = tmp.Close()+ defer os.Remove(tmp.Name()) //nolint:errcheck++ code, body := httpGet(t, "/pdf?output=file&path="+tmp.Name())+ if code != 200 {+ t.Fatalf("expected 200, got %d (body: %s)", code, body)+ }+ info, err := os.Stat(tmp.Name())+ if err != nil {+ t.Fatalf("file not created: %v", err)+ }+ if info.Size() < 100 {+ t.Error("PDF file too small")+ }+}++// PD5: PDF landscape+func TestPDF_Landscape(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/pdf?landscape=true&raw=true")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ if len(body) < 4 || string(body[:4]) != "%PDF" {+ t.Error("expected valid PDF")+ }+}++// PD6: PDF scale+func TestPDF_Scale(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/pdf?scale=0.5&raw=true")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ if len(body) < 4 || string(body[:4]) != "%PDF" {+ t.Error("expected valid PDF")+ }+}++// PD7: PDF no tab — tested implicitly (hard to close all tabs safely)diff --git a/tests/integration/screenshot_test.go b/tests/integration/screenshot_test.gonew file mode 100644index 00000000..1bd2da6f--- /dev/null+++ b/tests/integration/screenshot_test.go@@ -0,0 +1,33 @@+//go:build integration++package integration++import (+ "testing"+)++// SS1: Basic screenshot+func TestScreenshot_Basic(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/screenshot")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ // Default returns JSON with base64+ if len(body) < 100 {+ t.Error("screenshot response too small")+ }+}++// SS2: Raw screenshot+func TestScreenshot_Raw(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/screenshot?raw=true")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ // JPEG starts with FF D8+ if len(body) < 2 || body[0] != 0xFF || body[1] != 0xD8 {+ t.Error("expected raw JPEG data (FF D8 header)")+ }+}diff --git a/tests/integration/snapshot_test.go b/tests/integration/snapshot_test.gonew file mode 100644index 00000000..d6abb5e8--- /dev/null+++ b/tests/integration/snapshot_test.go@@ -0,0 +1,88 @@+//go:build integration++package integration++import (+ "encoding/json"+ "strings"+ "testing"+)++// S1: Basic snapshot+func TestSnapshot_Basic(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/snapshot")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ var m map[string]any+ if err := json.Unmarshal(body, &m); err != nil {+ t.Fatalf("invalid json: %v", err)+ }+ // Should have nodes or tree+ if m["nodes"] == nil && m["tree"] == nil && m["role"] == nil {+ t.Error("expected snapshot data (nodes, tree, or role)")+ }+}++// S2: Interactive filter+func TestSnapshot_Interactive(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/snapshot?filter=interactive")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ s := string(body)+ // example.com has a link "More information..."+ if !strings.Contains(s, "link") && !strings.Contains(s, "More information") {+ t.Log("warning: expected interactive elements in snapshot")+ }+}++// S4: Text format+func TestSnapshot_TextFormat(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/snapshot?format=text")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ s := string(body)+ // Text format should not be JSON+ if strings.HasPrefix(strings.TrimSpace(s), "{") || strings.HasPrefix(strings.TrimSpace(s), "[") {+ t.Error("text format should not return JSON")+ }+ if !strings.Contains(s, "Example Domain") {+ t.Error("expected 'Example Domain' in text snapshot")+ }+}++// S5: YAML format+func TestSnapshot_YAMLFormat(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/snapshot?format=yaml")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ s := string(body)+ if strings.HasPrefix(strings.TrimSpace(s), "{") {+ t.Error("yaml format should not return JSON object")+ }+}++// S3: Depth filter+func TestSnapshot_Depth(t *testing.T) {+ navigate(t, "https://example.com")+ code, _ := httpGet(t, "/snapshot?depth=2")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+}++// S5 (compact): maxTokens+func TestSnapshot_MaxTokens(t *testing.T) {+ navigate(t, "https://example.com")+ code, _ := httpGet(t, "/snapshot?maxTokens=500")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+}diff --git a/tests/integration/tabs_test.go b/tests/integration/tabs_test.gonew file mode 100644index 00000000..f3eb2cd9--- /dev/null+++ b/tests/integration/tabs_test.go@@ -0,0 +1,73 @@+//go:build integration++package integration++import (+ "encoding/json"+ "testing"+)++// TB1: List tabs+func TestTabs_List(t *testing.T) {+ code, body := httpGet(t, "/tabs")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ var tabs []any+ if err := json.Unmarshal(body, &tabs); err != nil {+ t.Fatalf("expected json array: %v", err)+ }+ if len(tabs) == 0 {+ t.Error("expected at least one tab")+ }+}++// TB2: New tab+func TestTabs_New(t *testing.T) {+ code, body := httpPost(t, "/tab", map[string]string{+ "action": "new",+ "url": "https://example.com",+ })+ if code != 200 {+ t.Fatalf("expected 200, got %d (body: %s)", code, body)+ }++ // Verify tab count increased+ _, listBody := httpGet(t, "/tabs")+ var tabs []any+ _ = json.Unmarshal(listBody, &tabs)+ if len(tabs) < 2 {+ t.Error("expected at least 2 tabs after creating new tab")+ }+}++// TB3: Close tab+func TestTabs_Close(t *testing.T) {+ // Create a tab to close+ _, newBody := httpPost(t, "/tab", map[string]string{+ "action": "new",+ "url": "https://example.com",+ })+ var newTab map[string]any+ _ = json.Unmarshal(newBody, &newTab)+ tabID, _ := newTab["tabId"].(string)+ if tabID == "" {+ t.Skip("no tabId returned from new tab")+ }++ code, _ := httpPost(t, "/tab", map[string]string{+ "action": "close",+ "tabId": tabID,+ })+ if code != 200 {+ t.Errorf("close tab failed with %d", code)+ }+}++// TB5: Bad action+func TestTabs_BadAction(t *testing.T) {+ code, _ := httpPost(t, "/tab", map[string]string{"action": "explode"})+ if code != 400 {+ t.Errorf("expected 400 for bad action, got %d", code)+ }+}diff --git a/tests/integration/text_test.go b/tests/integration/text_test.gonew file mode 100644index 00000000..e90f7a94--- /dev/null+++ b/tests/integration/text_test.go@@ -0,0 +1,34 @@+//go:build integration++package integration++import (+ "strings"+ "testing"+)++// T1: Readability mode+func TestText_Readability(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/text")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ s := string(body)+ if !strings.Contains(s, "Example Domain") {+ t.Error("expected 'Example Domain' in text output")+ }+}++// T2: Raw mode+func TestText_Raw(t *testing.T) {+ navigate(t, "https://example.com")+ code, body := httpGet(t, "/text?mode=raw")+ if code != 200 {+ t.Fatalf("expected 200, got %d", code)+ }+ s := string(body)+ if !strings.Contains(s, "Example Domain") {+ t.Error("expected 'Example Domain' in raw text")+ }+}