Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix(doctor): binary_starts opened a browser window and called it a version

Darshan Jainaa11349fb838
diff --git a/internal/doctor/checks_binary.go b/internal/doctor/checks_binary.go
index f374ab5d..bf22ad45 100644
--- a/internal/doctor/checks_binary.go
+++ b/internal/doctor/checks_binary.go
@@ -4,9 +4,7 @@ import (
"context"
"fmt"
"os"
- "os/exec"
"strings"
- "time"
"github.com/pinchtab/pinchtab/internal/browserprobe"
"github.com/pinchtab/pinchtab/internal/config"
@@ -77,21 +75,33 @@ func checkBinaryStarts(ctx context.Context, cfg *config.RuntimeConfig) CheckResu
if bin == "" {
return CheckResult{Status: StatusSkip, Detail: "browser.binary not set; relying on provider discovery"}
}
- cctx, cancel := context.WithTimeout(ctx, 5*time.Second)
- defer cancel()
-
- cmd := exec.CommandContext(cctx, bin, "--version") // #nosec G204 -- bin is a browser path from config/discovery, not user input
- out, err := cmd.CombinedOutput()
+ // This used to run `bin --version` itself, a second copy of a probe
+ // browserprobe already owns — and the copy still had the Windows defect the
+ // original was fixed for. There `--version` prints no version: the process
+ // forwards its arguments to the running browser and prints "Opening in
+ // existing browser session.", so `pinchtab doctor` opened a window on the
+ // user's desktop and then reported that sentence as the browser's version
+ // (issue #649). browserprobe.RunVersion reads the install layout on Windows
+ // and starts nothing.
+ version, err := browserprobe.RunVersion(ctx, bin)
if err != nil {
return CheckResult{
Status: StatusFail,
- Detail: fmt.Sprintf("--version failed: %v", err),
+ Detail: fmt.Sprintf("version probe failed: %v", err),
Err: err,
}
}
- version := parseVersionLine(string(out))
- if version == "" {
- version = strings.TrimSpace(string(out))
+ if parsed := parseVersionLine(version); parsed != "" {
+ version = parsed
+ }
+ // A probe that answers something with no version in it has not identified the
+ // browser, whatever its exit code was. Reporting Pass on that is how the
+ // "Opening in existing browser session." sentence reached users as a version.
+ if extractVersionToken(version) == "" {
+ return CheckResult{
+ Status: StatusWarn,
+ Detail: fmt.Sprintf("%s: probe returned no version (%q)", bin, version),
+ }
}
return CheckResult{
Status: StatusPass,
diff --git a/internal/doctor/runner_test.go b/internal/doctor/runner_test.go
index 80217549..7ddc112e 100644
--- a/internal/doctor/runner_test.go
+++ b/internal/doctor/runner_test.go
@@ -284,3 +284,58 @@ func TestCheckResultMarshalsDurationInMilliseconds(t *testing.T) {
t.Fatalf("expected durationMs in milliseconds, got %s", data)
}
}
+
+// TestBinaryStarts_DoesNotRunTheBrowserOnWindows is the regression for the
+// binary_starts half of issue #649. The check ran `bin --version` itself, a
+// second copy of a probe browserprobe owns. On Windows that switch prints no
+// version — the process forwards its arguments to the running browser — so
+// `pinchtab doctor` opened a window and reported "Opening in existing browser
+// session." as the version.
+//
+// The stub here is not a runnable image. If the check execs it the probe fails,
+// which is the point: the version has to come from the install layout beside it.
+func TestBinaryStarts_DoesNotRunTheBrowserOnWindows(t *testing.T) {
+ if runtime.GOOS != "windows" {
+ t.Skip("install-layout version reading is windows-only")
+ }
+ dir := t.TempDir()
+ path := filepath.Join(dir, "fake-chrome.exe")
+ if err := os.WriteFile(path, []byte("not a PE image"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Mkdir(filepath.Join(dir, "151.0.7922.175"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+
+ cfg := &config.RuntimeConfig{BrowserBinary: path}
+ r := checkBinaryStarts(context.Background(), cfg)
+ if r.Status != StatusPass {
+ t.Fatalf("status = %v, want pass; detail=%q err=%v", r.Status, r.Detail, r.Err)
+ }
+ if !strings.Contains(r.Detail, "151.0.7922.175") {
+ t.Errorf("detail = %q, want the version from the install layout", r.Detail)
+ }
+}
+
+// A probe that comes back without a version in it has not identified the
+// browser, whatever the exit code was. Passing on that is how the sentence
+// "Opening in existing browser session." reached users as a version string.
+func TestBinaryStarts_DoesNotPassWithoutAVersion(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("shell-script fake binary requires unix")
+ }
+ dir := t.TempDir()
+ path := filepath.Join(dir, "fake-chrome-chatty")
+ script := "#!/bin/sh\necho 'Opening in existing browser session.'\n"
+ if err := os.WriteFile(path, []byte(script), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ cfg := &config.RuntimeConfig{BrowserBinary: path}
+ r := checkBinaryStarts(context.Background(), cfg)
+ if r.Status == StatusPass {
+ t.Fatalf("status = pass for a probe with no version in it; detail=%q", r.Detail)
+ }
+ if !strings.Contains(r.Detail, "no version") {
+ t.Errorf("detail = %q, want it to say no version was returned", r.Detail)
+ }
+}