High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: browser tests skip as chromium-not-installed because they PATH-probe instead of using discovery PIN-023
Luigi Agosti6258f7db56c3
diff --git a/internal/bridge/action_form_aria_test.go b/internal/bridge/action_form_aria_test.goindex fb49b10d..5aefa9b4 100644--- a/internal/bridge/action_form_aria_test.go+++ b/internal/bridge/action_form_aria_test.go@@ -4,20 +4,17 @@ import ("context""encoding/base64""os"- "os/exec""strings""testing""time""github.com/chromedp/chromedp""github.com/pinchtab/pinchtab/internal/config"+ "github.com/pinchtab/pinchtab/internal/testbrowser")func TestCheckUncheckARIACheckboxAndVerifyState(t *testing.T) {- chromePath, err := exec.LookPath("chromium")- if err != nil {- t.Skip("chromium not installed")- }+ chromePath := testbrowser.Path(t)profile, err := os.MkdirTemp("", "pinchtab-aria-checkbox-")if err != nil {t.Fatal(err)diff --git a/internal/bridge/action_pointer_flyout_test.go b/internal/bridge/action_pointer_flyout_test.goindex 1a824e07..2af167a6 100644--- a/internal/bridge/action_pointer_flyout_test.go+++ b/internal/bridge/action_pointer_flyout_test.go@@ -3,19 +3,16 @@ package bridgeimport ("context""encoding/base64"- "os/exec""testing""time""github.com/chromedp/chromedp""github.com/pinchtab/pinchtab/internal/config"+ "github.com/pinchtab/pinchtab/internal/testbrowser")func TestClickPreservesFloatingFlyoutWithoutScroll(t *testing.T) {- chromePath, err := exec.LookPath("chromium")- if err != nil {- t.Skip("chromium not installed")- }+ chromePath := testbrowser.Path(t)alloc, cancelAlloc := chromedp.NewExecAllocator(context.Background(), append(chromedp.DefaultExecAllocatorOptions[:],chromedp.ExecPath(chromePath),diff --git a/internal/bridge/action_resolve_modal_test.go b/internal/bridge/action_resolve_modal_test.goindex 5b3ab10e..9a747a6f 100644--- a/internal/bridge/action_resolve_modal_test.go+++ b/internal/bridge/action_resolve_modal_test.go@@ -5,20 +5,17 @@ import ("encoding/base64""errors""os"- "os/exec""strings""testing""time""github.com/chromedp/chromedp""github.com/pinchtab/pinchtab/internal/selector"+ "github.com/pinchtab/pinchtab/internal/testbrowser")func TestDialogScopeReproducesGlobalEscapeAndContainsActionsAndReads(t *testing.T) {- chromePath, err := exec.LookPath("chromium")- if err != nil {- t.Skip("chromium not installed")- }+ chromePath := testbrowser.Path(t)profile, err := os.MkdirTemp("", "pinchtab-modal-scope-")if err != nil {t.Fatal(err)@@ -170,10 +167,7 @@ func TestDialogScopeReproducesGlobalEscapeAndContainsActionsAndReads(t *testing.}func TestTopmostModalUsesBrowserPaintOrderAndRejectsFalseOwners(t *testing.T) {- chromePath, err := exec.LookPath("chromium")- if err != nil {- t.Skip("chromium not installed")- }+ chromePath := testbrowser.Path(t)profile, err := os.MkdirTemp("", "pinchtab-modal-order-")if err != nil {t.Fatal(err)@@ -260,10 +254,7 @@ func TestTopmostModalUsesBrowserPaintOrderAndRejectsFalseOwners(t *testing.T) {}func TestDialogScopeContainmentIncludesOpenShadowDescendants(t *testing.T) {- chromePath, err := exec.LookPath("chromium")- if err != nil {- t.Skip("chromium not installed")- }+ chromePath := testbrowser.Path(t)profile, err := os.MkdirTemp("", "pinchtab-modal-shadow-containment-")if err != nil {t.Fatal(err)diff --git a/internal/bridge/attach_indicator_test.go b/internal/bridge/attach_indicator_test.goindex 66e3766f..9dabb0e0 100644--- a/internal/bridge/attach_indicator_test.go+++ b/internal/bridge/attach_indicator_test.go@@ -4,7 +4,6 @@ import ("context""encoding/base64""os"- "os/exec""strings""testing""time"@@ -13,13 +12,11 @@ import ("github.com/chromedp/chromedp""github.com/pinchtab/pinchtab/internal/config""github.com/pinchtab/pinchtab/internal/stealth"+ "github.com/pinchtab/pinchtab/internal/testbrowser")func TestAttachIndicatorNamesPortPersistsAndClears(t *testing.T) {- chromePath, err := exec.LookPath("chromium")- if err != nil {- t.Skip("chromium not installed")- }+ chromePath := testbrowser.Path(t)profile, err := os.MkdirTemp("", "pinchtab-attach-indicator-")if err != nil {t.Fatal(err)diff --git a/internal/bridge/capture_background_tab_test.go b/internal/bridge/capture_background_tab_test.goindex 5a0c61f1..a1852d4c 100644--- a/internal/bridge/capture_background_tab_test.go+++ b/internal/bridge/capture_background_tab_test.go@@ -4,13 +4,13 @@ import ("context""encoding/base64""os"- "os/exec""testing""time""github.com/chromedp/cdproto/page""github.com/chromedp/cdproto/target""github.com/chromedp/chromedp"+ "github.com/pinchtab/pinchtab/internal/testbrowser")// TestCaptureScreenshotOfBackgroundTabCompletesQuickly is a real-Chromium@@ -22,10 +22,7 @@ import (// focus emulation and returns from captureScreenshot immediately regardless// of whether a real tab is actually painting.func TestCaptureScreenshotOfBackgroundTabCompletesQuickly(t *testing.T) {- chromePath, err := exec.LookPath("chromium")- if err != nil {- t.Skip("chromium not installed")- }+ chromePath := testbrowser.Path(t)profile, err := os.MkdirTemp("", "pinchtab-bg-capture-")if err != nil {t.Fatal(err)diff --git a/internal/bridge/debugger_guard_test.go b/internal/bridge/debugger_guard_test.goindex 8ee8b952..2775026d 100644--- a/internal/bridge/debugger_guard_test.go+++ b/internal/bridge/debugger_guard_test.go@@ -4,7 +4,6 @@ import ("context""errors""os"- "os/exec""strings""testing""time"@@ -15,6 +14,7 @@ import ("github.com/chromedp/chromedp""github.com/pinchtab/pinchtab/internal/config""github.com/pinchtab/pinchtab/internal/stealth"+ "github.com/pinchtab/pinchtab/internal/testbrowser")type debuggerCommand struct {@@ -195,10 +195,7 @@ func TestDebuggerPauseGuardLive(t *testing.T) {t.Skip("set PINCHTAB_DEBUGGER_GUARD_LIVE=1 for the local Chromium proof")}- chromePath, err := exec.LookPath("chromium")- if err != nil {- t.Fatal("chromium is required for the live debugger guard proof")- }+ chromePath := testbrowser.MustPath(t)opts := append(chromedp.DefaultExecAllocatorOptions[:], chromedp.ExecPath(chromePath))allocCtx, allocCancel := chromedp.NewExecAllocator(context.Background(), opts...)defer allocCancel()diff --git a/internal/bridge/password_mask_browser_test.go b/internal/bridge/password_mask_browser_test.goindex c510a815..4fc51af8 100644--- a/internal/bridge/password_mask_browser_test.go+++ b/internal/bridge/password_mask_browser_test.go@@ -3,36 +3,19 @@ package bridgeimport ("context""encoding/base64"- "os"- "os/exec"- "strings""testing""time""github.com/chromedp/chromedp"bridgeobserve "github.com/pinchtab/pinchtab/internal/bridge/observe"+ "github.com/pinchtab/pinchtab/internal/testbrowser")-// chromePathForTest deliberately does not go looking for the user's primary-// Google Chrome (issue #583): it takes chromium from PATH, or an explicit-// PINCHTAB_TEST_CHROME override, and skips otherwise.-func chromePathForTest(t *testing.T) string {- t.Helper()- if path := strings.TrimSpace(os.Getenv("PINCHTAB_TEST_CHROME")); path != "" {- return path- }- if path, err := exec.LookPath("chromium"); err == nil {- return path- }- t.Skip("chromium not installed (set PINCHTAB_TEST_CHROME to run against another build)")- return ""-}-// The snapshot pipeline the /snapshot handler runs — fetch the a11y tree, flatten// it, then enrich from the DOM — against a real page, because the defect lives in// what the browser reports for a password field and no stub can stand in for it.func TestSnapshotDistinguishesEmptyAndFilledPasswordInRealBrowser(t *testing.T) {- chromePath := chromePathForTest(t)+ chromePath := testbrowser.Path(t)profile := t.TempDir()alloc, cancelAlloc := chromedp.NewExecAllocator(context.Background(), append(diff --git a/internal/handlers/action_selector_modal_test.go b/internal/handlers/action_selector_modal_test.goindex 897bc24d..90472cb9 100644--- a/internal/handlers/action_selector_modal_test.go+++ b/internal/handlers/action_selector_modal_test.go@@ -7,7 +7,6 @@ import ("net/http""net/http/httptest""os"- "os/exec""strings""testing""time"@@ -15,13 +14,11 @@ import ("github.com/chromedp/chromedp""github.com/pinchtab/pinchtab/internal/bridge""github.com/pinchtab/pinchtab/internal/config"+ "github.com/pinchtab/pinchtab/internal/testbrowser")func TestActionSelectorResolutionDefaultsToTopmostDialog(t *testing.T) {- chromePath, err := exec.LookPath("chromium")- if err != nil {- t.Skip("chromium not installed")- }+ chromePath := testbrowser.Path(t)profile, err := os.MkdirTemp("", "pinchtab-handler-modal-")if err != nil {t.Fatal(err)diff --git a/internal/handlers/interstitial_dismiss_test.go b/internal/handlers/interstitial_dismiss_test.goindex f087e398..d5b75dd4 100644--- a/internal/handlers/interstitial_dismiss_test.go+++ b/internal/handlers/interstitial_dismiss_test.go@@ -7,7 +7,6 @@ import ("net/http/httptest""net/url""os"- "os/exec""strings""testing""time"@@ -15,13 +14,11 @@ import ("github.com/chromedp/chromedp""github.com/pinchtab/pinchtab/internal/bridge""github.com/pinchtab/pinchtab/internal/config"+ "github.com/pinchtab/pinchtab/internal/testbrowser")func TestKnownInterstitialDismissalIsCatalogAndModalScoped(t *testing.T) {- chromePath, err := exec.LookPath("chromium")- if err != nil {- t.Skip("chromium not installed")- }+ chromePath := testbrowser.Path(t)server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {switch r.URL.Query().Get("case") {case "known":diff --git a/internal/testbrowser/testbrowser.go b/internal/testbrowser/testbrowser.gonew file mode 100644index 00000000..cd6b1c1c--- /dev/null+++ b/internal/testbrowser/testbrowser.go@@ -0,0 +1,109 @@+// Package testbrowser resolves a launchable browser for browser-backed tests+// the same way PinchTab resolves one at runtime. Tests used to PATH-probe for a+// binary named "chromium", which finds nothing on a stock macOS even with Chrome+// installed, so every browser-backed test silently skipped on the primary+// development platform.+package testbrowser++import (+ "fmt"+ "os"+ "strings"+ "testing"++ "github.com/pinchtab/pinchtab/internal/browsers"+ _ "github.com/pinchtab/pinchtab/internal/browsers/chrome"+ _ "github.com/pinchtab/pinchtab/internal/browsers/cloak"+ _ "github.com/pinchtab/pinchtab/internal/browsers/ghostchrome"+ "github.com/pinchtab/pinchtab/internal/browsers/runtimekit"+)++// BinaryEnv points the browser-backed tests at a specific binary.+const BinaryEnv = "PINCHTAB_TEST_BROWSER"++// SkipEnv opts out of browser-backed tests entirely, for a lightweight run.+const SkipEnv = "PINCHTAB_SKIP_BROWSER_TESTS"++// preferredIDs is the order providers are tried in: chrome first because these+// tests assert plain Chromium behaviour, then whatever else is registered.+var preferredIDs = []string{"chrome", "cloak", "ghost-chrome"}++// Find returns a launchable browser binary and the locations that were probed to+// reach that answer. The binary is empty when discovery found nothing. Discovery+// is runtimekit's — the same call the server makes when it launches a browser.+func Find() (binary string, probed []string) {+ if override := strings.TrimSpace(os.Getenv(BinaryEnv)); override != "" {+ return override, []string{BinaryEnv + "=" + override}+ }+ for _, id := range providerIDs() {+ if found := strings.TrimSpace(runtimekit.FindBrowserBinary(id)); found != "" {+ return found, probed+ }+ probed = append(probed, probedPathsFor(id)...)+ }+ return "", probed+}++func probedPathsFor(id string) []string {+ b, ok := browsers.Get(id)+ if !ok {+ return nil+ }+ return b.DiscoverBinary().Probed+}++func providerIDs() []string {+ ordered := append([]string(nil), preferredIDs...)+ seen := map[string]bool{}+ for _, id := range ordered {+ seen[id] = true+ }+ for _, id := range browsers.IDs() {+ if !seen[id] {+ ordered = append(ordered, id)+ }+ }+ return ordered+}++// Path returns a launchable browser binary, skipping the test only when the+// machine genuinely has none. The skip names what was searched and how to point+// the tests at a binary, so a real absence is actionable.+func Path(t testing.TB) string {+ t.Helper()+ if skipRequested() {+ t.Skipf("browser-backed test skipped: %s is set", SkipEnv)+ }+ binary, probed := Find()+ if binary == "" {+ t.Skip(notFoundMessage(probed))+ }+ return binary+}++// MustPath is Path for tests a contributor has explicitly opted into: once the+// opt-in is given, a missing browser is a failure rather than a silent skip.+func MustPath(t testing.TB) string {+ t.Helper()+ binary, probed := Find()+ if binary == "" {+ t.Fatal(notFoundMessage(probed))+ }+ return binary+}++func skipRequested() bool {+ v := strings.TrimSpace(os.Getenv(SkipEnv))+ return v != "" && v != "0" && !strings.EqualFold(v, "false")+}++func notFoundMessage(probed []string) string {+ searched := "nothing"+ if len(probed) > 0 {+ searched = strings.Join(probed, ", ")+ }+ return fmt.Sprintf(+ "no browser binary found for %s (searched: %s); set %s=/path/to/browser to point the browser-backed tests at one",+ strings.Join(providerIDs(), "/"), searched, BinaryEnv,+ )+}diff --git a/internal/testbrowser/testbrowser_test.go b/internal/testbrowser/testbrowser_test.gonew file mode 100644index 00000000..d14375d0--- /dev/null+++ b/internal/testbrowser/testbrowser_test.go@@ -0,0 +1,79 @@+package testbrowser++import (+ "strings"+ "testing"+)++func TestFindHonoursTheBinaryOverride(t *testing.T) {+ t.Setenv(BinaryEnv, "/opt/custom/chrome")++ binary, probed := Find()+ if binary != "/opt/custom/chrome" {+ t.Fatalf("binary = %q, want the override", binary)+ }+ if len(probed) != 1 || !strings.Contains(probed[0], BinaryEnv) {+ t.Fatalf("probed = %v, want the override to be named as the source", probed)+ }+}++// A real absence must be actionable: the message has to say what was searched+// and how to point the tests at a binary, not "chromium not installed".+func TestNotFoundMessageNamesTheSearchAndTheOverride(t *testing.T) {+ msg := notFoundMessage([]string{"/usr/bin/chromium", "/Applications/Google Chrome.app"})++ for _, want := range []string{"/usr/bin/chromium", "/Applications/Google Chrome.app", BinaryEnv, "chrome"} {+ if !strings.Contains(msg, want) {+ t.Errorf("message does not mention %q: %s", want, msg)+ }+ }+}++func TestNotFoundMessageWithoutProbedPaths(t *testing.T) {+ msg := notFoundMessage(nil)+ if !strings.Contains(msg, BinaryEnv) {+ t.Errorf("message does not name the override: %s", msg)+ }+}++func TestSkipRequested(t *testing.T) {+ tests := []struct {+ value string+ want bool+ }{+ {value: "", want: false},+ {value: "0", want: false},+ {value: "false", want: false},+ {value: "1", want: true},+ {value: "yes", want: true},+ }+ for _, tt := range tests {+ t.Run("value="+tt.value, func(t *testing.T) {+ t.Setenv(SkipEnv, tt.value)+ if got := skipRequested(); got != tt.want {+ t.Fatalf("skipRequested() = %v, want %v", got, tt.want)+ }+ })+ }+}++// chrome is tried first: these tests assert plain Chromium behaviour, and every+// registered provider must appear so the search is exhaustive.+func TestProviderIDsPrefersChromeAndCoversTheRegistry(t *testing.T) {+ ids := providerIDs()+ if len(ids) == 0 || ids[0] != "chrome" {+ t.Fatalf("providerIDs() = %v, want chrome first", ids)+ }+ for _, want := range []string{"chrome", "cloak", "ghost-chrome"} {+ found := false+ for _, id := range ids {+ if id == want {+ found = true+ break+ }+ }+ if !found {+ t.Errorf("providerIDs() = %v, missing %q", ids, want)+ }+ }+}diff --git a/scripts/test.sh b/scripts/test.shindex b5284d6d..f653d1ee 100755--- a/scripts/test.sh+++ b/scripts/test.sh@@ -59,6 +59,53 @@ resolve_gotestsum() {return 1}+# print_skipped_tests lists every skipped test with the reason it gave, so the+# skip list is reviewable: "skipped because Windows-only" and "skipped because we+# could not find a browser that is in fact installed" otherwise look identical.+# The reason is the last file:line log line the test emitted before it skipped,+# which is exactly what t.Skip writes.+print_skipped_tests() {+ local json_file="$1"++ [ ! -s "$json_file" ] && return++ local lines+ lines="$(+ jq -r '+ select(.Test != null and (.Action == "skip" or .Action == "output"))+ | [.Package, .Test, .Action, ((.Output // "") | gsub("\r?\n$"; ""))] | @tsv+ ' "$json_file" \+ | awk -F'\t' '+ {+ key = $1 "\t" $2+ if ($3 == "output") {+ line = $4+ sub(/^[[:space:]]+/, "", line)+ if (line ~ /\.go:[0-9]+: /) { reason[key] = line }+ } else if ($3 == "skip") {+ skipped[key] = 1+ }+ }+ END {+ for (k in skipped) {+ r = reason[k]+ sub(/^[^ ]*\.go:[0-9]+: /, "", r)+ if (r == "") { r = "(no reason given)" }+ split(k, parts, "\t")+ printf " - %s %s — %s\n", parts[1], parts[2], r+ }+ }' \+ | sort++ )"++ [ -z "$lines" ] && return++ echo ""+ echo -e " ${ACCENT}Skipped tests:${NC}"+ printf '%s\n' "$lines"+}+# Parse gotestsum JSON and print summarytest_summary() {local json_file="$1"@@ -138,6 +185,7 @@ test_summary() {jq -r 'select(.Test != null and .Action == "fail") | " ✗ \(.Test)"' "$json_file" | sort -ufi+ print_skipped_tests "$json_file"}# Live progress for go test -json streams@@ -315,10 +363,12 @@ if [ "$SCOPE" = "all" ] || [ "$SCOPE" = "unit" ]; thenfiif [ -n "$GOTESTSUM_BIN" ]; then- if ! "$GOTESTSUM_BIN" --format=pkgname --hide-summary=output --jsonfile "$UNIT_JSON" -- -p 1 -count=1 ./...; then+ if ! "$GOTESTSUM_BIN" --format=pkgname --hide-summary=output,skipped --jsonfile "$UNIT_JSON" -- -p 1 -count=1 ./...; thenfail "test:🔬:go unit"+ print_skipped_tests "$UNIT_JSON"exit 1fi+ print_skipped_tests "$UNIT_JSON"elseecho -e " ${MUTED}gotestsum not found; using built-in formatter${NC}"echo -e " ${MUTED}Install: go install gotest.tools/gotestsum@latest${NC}"