High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(doctor): probe discovered browsers over CDP (PIN-303)
Luigi Agosti47f903c3777b
diff --git a/README.md b/README.mdindex e0d0ccad..9ce8c280 100644--- a/README.md+++ b/README.md@@ -447,7 +447,7 @@ cd pinchtabgo build ./cmd/pinchtab # Build pinchtab binary```-For runtime diagnostics against your installed PinchTab + browser config (binary exists, executes, fingerprint flags accepted, CDP reachable), use:+For diagnostics of your installed PinchTab + browser config (config file loads, browser found and version adequate, a headless launch exposes CDP, request shapes handled; CloakBrowser adds fingerprint-flag and font checks), use:```bashpinchtab doctor # human-readable reportdiff --git a/cmd/pinchtab/cmd_doctor.go b/cmd/pinchtab/cmd_doctor.goindex 6ba3789a..0151fc6b 100644--- a/cmd/pinchtab/cmd_doctor.go+++ b/cmd/pinchtab/cmd_doctor.go@@ -18,13 +18,19 @@ var doctorCmd = &cobra.Command{Use: "doctor",Short: "Run discovery and health checks against the configured browser",Long: `Run a series of read-only diagnostic checks against the current-PinchTab configuration. Initially focused on CloakBrowser discovery-(binary exists, executes, exposes CDP, accepts fingerprint flags),-but the framework is browser-neutral.+PinchTab configuration. On the default provider they cover the config file,+the browser binary (found, version adequate), a headless launch that must+expose CDP, and the request shapes the provider handles; CloakBrowser adds+fingerprint-flag and font checks. The browser is resolved the way the server+resolves it: browser.binary when set, otherwise discovery.-The doctor command does not require a running PinchTab server. It works-directly against the on-disk config and may launch a short-lived browser-subprocess (which is always torn down).+The doctor command inspects the installation and does not require a running+PinchTab server; it may launch a short-lived browser subprocess, which is+always torn down. It never reports on a running browser: if a server answers+at the configured address, doctor names it and the surfaces (/health, pinchtab+security, instance metrics) that carry the runtime state. The summary says+whether any check launched a browser, so a run of skips never reads as a+clean bill of health.Exit codes:0 all checks passed or were skipped@@ -62,13 +68,14 @@ func runDoctorChecks(cmd *cobra.Command, cfg *config.RuntimeConfig, check, errPrresults := doctor.Run(cmd.Context(), cfg, check)browser := config.NormalizeBrowser(cfg.DefaultBrowser)out := cmd.OutOrStdout()+ runtime := doctor.ProbeRuntime(cmd.Context(), cfg)if doctorJSON {- if err := doctor.WriteJSON(out, browser, target, results); err != nil {+ if err := doctor.WriteJSON(out, browser, target, results, runtime); err != nil {return fmt.Errorf("write json: %w", err)}} else {- doctor.WriteText(out, browser, target, results)+ doctor.WriteText(out, browser, target, results, runtime)}summary := doctor.Summarize(results)diff --git a/internal/browsers/chrome/doctor.go b/internal/browsers/chrome/doctor.goindex 18540722..f09d376a 100644--- a/internal/browsers/chrome/doctor.go+++ b/internal/browsers/chrome/doctor.go@@ -5,12 +5,16 @@ import ("fmt""runtime""strings"+ "time""github.com/pinchtab/pinchtab/internal/browserprobe""github.com/pinchtab/pinchtab/internal/browsers")const chromeMinVersion = "120.0.0"+const chromeDoctorLaunchTimeout = 60 * time.Second++var probeCDP = LaunchAndProbefunc (b Browser) DoctorChecks(_ browsers.TargetConfig) []browsers.DoctorCheck {return []browsers.DoctorCheck{@@ -19,6 +23,12 @@ func (b Browser) DoctorChecks(_ browsers.TargetConfig) []browsers.DoctorCheck {Description: "Chrome/Chromium binary found and version adequate",Fn: chromePresenceCheck,},+ {+ ID: "cdp_reachable",+ Description: "Chrome launches headless and accepts CDP attach",+ Fn: cdpReachableCheck,+ LaunchesBrowser: true,+ },{ID: "handle_decisions",Description: "Verify Chrome handles all request shapes",@@ -52,30 +62,45 @@ func (b Browser) DoctorChecks(_ browsers.TargetConfig) []browsers.DoctorCheck {}}-func chromePresenceCheck(ctx context.Context, cfg interface{}) browsers.DoctorCheckResult {- // A configured browser.binary override governs the runtime, so resolve against- // it first. Honoring it here keeps chrome_present consistent with the binary_*- // checks (which already validate the override) — otherwise a working configured- // browser sitting off the static discovery path produces a false FAIL.- override := ""- if env, ok := cfg.(*browsers.DoctorEnv); ok && env != nil {- override = strings.TrimSpace(env.Binary)+func resolveDoctorBinary(cfg interface{}) browsers.DoctorBinary {+ return browsers.ResolveDoctorBinary(cfg, BinaryNames(), CommonPaths(runtime.GOOS))+}++func chromeAbsent(probed []string) browsers.DoctorCheckResult {+ return browsers.DoctorCheckResult{+ Status: browsers.DoctorFail,+ Detail: "no chrome/chromium found. Install Chrome/Chromium (" ++ browsers.InstallHint(runtime.GOOS) + ") or set " ++ "browser.binary to an existing build. Probed: " + strings.Join(probed, ", "),}- overridden := override != ""+}- found := override- if found == "" {- d := browserprobe.DiscoverBinary(BinaryNames(), CommonPaths(runtime.GOOS))- found = d.Found- if found == "" {- return browsers.DoctorCheckResult{- Status: browsers.DoctorFail,- Detail: "no chrome/chromium found. Install Chrome/Chromium (" +- browsers.InstallHint(runtime.GOOS) + ") or set " +- "browser.binary to an existing build. Probed: " + strings.Join(d.Probed, ", "),- }+func cdpReachableCheck(ctx context.Context, cfg interface{}) browsers.DoctorCheckResult {+ binary := resolveDoctorBinary(cfg)+ if binary.Path == "" {+ return chromeAbsent(binary.Probed)+ }+ res, err := probeCDP(ctx, binary.Path, browsers.DoctorSandboxArgs(cfg), chromeDoctorLaunchTimeout)+ if err != nil {+ return browsers.DoctorCheckResult{+ Status: browsers.DoctorFail,+ Detail: fmt.Sprintf("%s: headless launch did not expose CDP: %v", binary.Path, err),+ Err: err,}}+ return browsers.DoctorCheckResult{+ Status: browsers.DoctorPass,+ Detail: fmt.Sprintf("%s: /json/version OK on port %d", binary.Path, res.Port),+ }+}++func chromePresenceCheck(ctx context.Context, cfg interface{}) browsers.DoctorCheckResult {+ binary := resolveDoctorBinary(cfg)+ overridden := binary.Overridden+ found := binary.Path+ if found == "" {+ return chromeAbsent(binary.Probed)+ }line, err := browserprobe.RunVersion(ctx, found)if err != nil {return browsers.DoctorCheckResult{diff --git a/internal/browsers/chrome/doctor_test.go b/internal/browsers/chrome/doctor_test.gonew file mode 100644index 00000000..28c69148--- /dev/null+++ b/internal/browsers/chrome/doctor_test.go@@ -0,0 +1,40 @@+package chrome++import (+ "context"+ "os"+ "path/filepath"+ "runtime"+ "testing"+ "time"++ "github.com/pinchtab/pinchtab/internal/browsers"+)++func TestCDPReachableUsesDiscoveryWithoutABinaryOverride(t *testing.T) {+ if runtime.GOOS == "windows" {+ t.Skip("discovery fixture uses a shell script")+ }+ dir := t.TempDir()+ binary := filepath.Join(dir, BinaryNames()[0])+ if err := os.WriteFile(binary, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {+ t.Fatal(err)+ }+ t.Setenv("PATH", dir)++ original := probeCDP+ var launched string+ probeCDP = func(_ context.Context, path string, _ []string, _ time.Duration) (CDPProbeResult, error) {+ launched = path+ return CDPProbeResult{Port: 9222}, nil+ }+ t.Cleanup(func() { probeCDP = original })++ result := cdpReachableCheck(context.Background(), &browsers.DoctorEnv{})+ if result.Status != browsers.DoctorPass {+ t.Fatalf("status = %v, want pass: %s", result.Status, result.Detail)+ }+ if launched != binary {+ t.Fatalf("launched %q, want discovered binary %q", launched, binary)+ }+}diff --git a/internal/browsers/cloak/doctor.go b/internal/browsers/cloak/doctor.goindex cc98520e..356a3eef 100644--- a/internal/browsers/cloak/doctor.go+++ b/internal/browsers/cloak/doctor.go@@ -23,19 +23,22 @@ var launchAndProbe = chrome.LaunchAndProbefunc (Browser) DoctorChecks(_ browsers.TargetConfig) []browsers.DoctorCheck {return []browsers.DoctorCheck{{- ID: "cloakbrowser_present",- Description: "CloakBrowser binary found and version adequate",- Fn: cloakPresenceCheck,+ ID: "cloakbrowser_present",+ Description: "CloakBrowser binary found and version adequate",+ Fn: cloakPresenceCheck,+ LaunchesBrowser: true,},{- ID: "cdp_reachable",- Description: "CloakBrowser accepts CDP attach headless",- Fn: cdpReachableCheck,+ ID: "cdp_reachable",+ Description: "CloakBrowser accepts CDP attach headless",+ Fn: cdpReachableCheck,+ LaunchesBrowser: true,},{- ID: "fingerprint_flags_accepted",- Description: "CloakBrowser accepts configured fingerprint flags",- Fn: fingerprintFlagsCheck,+ ID: "fingerprint_flags_accepted",+ Description: "CloakBrowser accepts configured fingerprint flags",+ Fn: fingerprintFlagsCheck,+ LaunchesBrowser: true,},{ID: "linux_fonts_present",@@ -75,28 +78,23 @@ func (Browser) DoctorChecks(_ browsers.TargetConfig) []browsers.DoctorCheck {}}+func resolveDoctorBinary(cfg interface{}) browsers.DoctorBinary {+ return browsers.ResolveDoctorBinary(cfg, BinaryNames(), CommonPaths(runtime.GOOS))+}+func cloakPresenceCheck(ctx context.Context, cfg interface{}) browsers.DoctorCheckResult {- // An explicit browser.binary override is what the runtime launches, so resolve- // against it before falling back to discovery. The CloakBrowser installer drops- // its Chromium in a versioned dir that isn't on the static probe list, so without- // this a perfectly working configured binary reports a false FAIL while the- // binary_* checks below it pass.+ binary := resolveDoctorBinary(cfg)override := ""- if env, ok := cfg.(*browsers.DoctorEnv); ok && env != nil {- override = strings.TrimSpace(env.Binary)+ if binary.Overridden {+ override = binary.Path}- found := override- discovered := false+ found := binary.Path+ discovered := !binary.Overriddenif found == "" {- d := browserprobe.DiscoverBinary(BinaryNames(), CommonPaths(runtime.GOOS))- found = d.Found- if found == "" {- return browsers.DoctorCheckResult{- Status: browsers.DoctorFail,- Detail: "cloakbrowser not found; set browser.binary or install CloakBrowser. probed: " + strings.Join(d.Probed, ", "),- }+ return browsers.DoctorCheckResult{+ Status: browsers.DoctorFail,+ Detail: "cloakbrowser not found; set browser.binary or install CloakBrowser. probed: " + strings.Join(binary.Probed, ", "),}- discovered = true}line, err := browserprobe.RunVersion(ctx, found)if err != nil {@@ -159,20 +157,14 @@ func cloakPresenceCheck(ctx context.Context, cfg interface{}) browsers.DoctorChe}}+const noCloakFound = "skipped — no CloakBrowser found by browser.binary or discovery (see cloakbrowser_present)"+func cdpReachableCheck(ctx context.Context, cfg interface{}) browsers.DoctorCheckResult {- env, ok := cfg.(*browsers.DoctorEnv)- if !ok || env == nil {- return browsers.DoctorCheckResult{Status: browsers.DoctorSkip, Detail: "no runtime config"}- }- bin := strings.TrimSpace(env.Binary)+ bin := resolveDoctorBinary(cfg).Pathif bin == "" {- return browsers.DoctorCheckResult{Status: browsers.DoctorSkip, Detail: "skipped — no browser.binary set (see cloakbrowser_present)"}- }- var args []string- if env.NoSandbox {- args = append(args, "--no-sandbox")+ return browsers.DoctorCheckResult{Status: browsers.DoctorSkip, Detail: noCloakFound}}- res, err := launchAndProbe(ctx, bin, args, cloakDoctorLaunchTimeout)+ res, err := launchAndProbe(ctx, bin, browsers.DoctorSandboxArgs(cfg), cloakDoctorLaunchTimeout)if err != nil {return browsers.DoctorCheckResult{Status: browsers.DoctorFail, Detail: err.Error(), Err: err}}@@ -187,9 +179,9 @@ func fingerprintFlagsCheck(ctx context.Context, cfg interface{}) browsers.Doctorif !ok || env == nil {return browsers.DoctorCheckResult{Status: browsers.DoctorSkip, Detail: "no runtime config"}}- bin := strings.TrimSpace(env.Binary)+ bin := resolveDoctorBinary(cfg).Pathif bin == "" {- return browsers.DoctorCheckResult{Status: browsers.DoctorSkip, Detail: "skipped — no browser.binary set (see cloakbrowser_present)"}+ return browsers.DoctorCheckResult{Status: browsers.DoctorSkip, Detail: noCloakFound}}launchCfg := browsers.LaunchConfig{@@ -212,9 +204,7 @@ func fingerprintFlagsCheck(ctx context.Context, cfg interface{}) browsers.Doctorif len(fpFlags) == 0 {return browsers.DoctorCheckResult{Status: browsers.DoctorSkip, Detail: "no cloak fingerprint flags configured"}}- if env.NoSandbox {- fpFlags = append(fpFlags, "--no-sandbox")- }+ fpFlags = append(fpFlags, browsers.DoctorSandboxArgs(cfg)...)res, err := launchAndProbe(ctx, bin, fpFlags, cloakDoctorLaunchTimeout)if err != nil {return browsers.DoctorCheckResult{diff --git a/internal/browsers/cloak/doctor_test.go b/internal/browsers/cloak/doctor_test.goindex 2f9b7146..f7cf01a9 100644--- a/internal/browsers/cloak/doctor_test.go+++ b/internal/browsers/cloak/doctor_test.go@@ -138,6 +138,34 @@ func TestCDPReachableAllowsColdStart(t *testing.T) {}}+func TestCDPReachableUsesDiscoveryWithoutABinaryOverride(t *testing.T) {+ if runtime.GOOS == "windows" {+ t.Skip("discovery fixture uses a shell script")+ }+ dir := t.TempDir()+ binary := filepath.Join(dir, BinaryNames()[0])+ if err := os.WriteFile(binary, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {+ t.Fatal(err)+ }+ t.Setenv("PATH", dir)++ original := launchAndProbe+ var launched string+ launchAndProbe = func(_ context.Context, path string, _ []string, _ time.Duration) (chrome.CDPProbeResult, error) {+ launched = path+ return chrome.CDPProbeResult{Port: 9222}, nil+ }+ t.Cleanup(func() { launchAndProbe = original })++ result := cdpReachableCheck(context.Background(), &browsers.DoctorEnv{})+ if result.Status != browsers.DoctorPass {+ t.Fatalf("status = %v, want pass: %s", result.Status, result.Detail)+ }+ if launched != binary {+ t.Fatalf("launched %q, want discovered binary %q", launched, binary)+ }+}+func TestFingerprintFlagsAllowColdStart(t *testing.T) {original := launchAndProbelaunchAndProbe = func(_ context.Context, _ string, _ []string, timeout time.Duration) (chrome.CDPProbeResult, error) {diff --git a/internal/browsers/config.go b/internal/browsers/config.goindex b7b24157..246f2e8a 100644--- a/internal/browsers/config.go+++ b/internal/browsers/config.go@@ -107,9 +107,10 @@ type DoctorCheckResult struct {}type DoctorCheck struct {- ID string- Description string- Fn func(ctx context.Context, cfg interface{}) DoctorCheckResult+ ID string+ Description string+ Fn func(ctx context.Context, cfg interface{}) DoctorCheckResult+ LaunchesBrowser bool}// DoctorEnv avoids browser sub-packages importing the config package.diff --git a/internal/browsers/doctor_binary.go b/internal/browsers/doctor_binary.gonew file mode 100644index 00000000..f835ee78--- /dev/null+++ b/internal/browsers/doctor_binary.go@@ -0,0 +1,33 @@+package browsers++import (+ "strings"++ "github.com/pinchtab/pinchtab/internal/browserprobe"+)++// DoctorBinary is the browser a doctor check will exercise: the configured+// override when set, otherwise what discovery finds. Every check resolves the+// same way, so none of them can skip on a default install that discovery serves.+type DoctorBinary struct {+ Path string+ Overridden bool+ Probed []string+}++func ResolveDoctorBinary(cfg interface{}, names, paths []string) DoctorBinary {+ if env, ok := cfg.(*DoctorEnv); ok && env != nil {+ if override := strings.TrimSpace(env.Binary); override != "" {+ return DoctorBinary{Path: override, Overridden: true}+ }+ }+ d := browserprobe.DiscoverBinary(names, paths)+ return DoctorBinary{Path: d.Found, Probed: d.Probed}+}++func DoctorSandboxArgs(cfg interface{}) []string {+ if env, ok := cfg.(*DoctorEnv); ok && env != nil && env.NoSandbox {+ return []string{"--no-sandbox"}+ }+ return nil+}diff --git a/internal/browsers/ghostchrome/ghostchrome.go b/internal/browsers/ghostchrome/ghostchrome.goindex 30bec1c7..57f2f098 100644--- a/internal/browsers/ghostchrome/ghostchrome.go+++ b/internal/browsers/ghostchrome/ghostchrome.go@@ -80,13 +80,13 @@ func (b Browser) DoctorChecks(cfg browsers.TargetConfig) []browsers.DoctorCheck// ghost-chrome escalates to Chrome for any rendered/visual/interactive work,// so a missing Chrome binary must be diagnosed up front. Reuse Chrome's own// chrome_present check rather than duplicating its discovery/version logic.+ var borrowed []browsers.DoctorCheckfor _, c := range b.chrome.DoctorChecks(cfg) {- if c.ID == "chrome_present" {- checks = append([]browsers.DoctorCheck{c}, checks...)- break+ if c.ID == "chrome_present" || c.ID == "cdp_reachable" {+ borrowed = append(borrowed, c)}}- return checks+ return append(borrowed, checks...)}func (b Browser) BuildLaunchArgs(cfg browsers.LaunchConfig) ([]string, []string, error) {diff --git a/internal/browsers/ghostchrome/ghostchrome_test.go b/internal/browsers/ghostchrome/ghostchrome_test.goindex 209a034f..6072b148 100644--- a/internal/browsers/ghostchrome/ghostchrome_test.go+++ b/internal/browsers/ghostchrome/ghostchrome_test.go@@ -127,6 +127,16 @@ func TestGhostChromeChromePresentCheck(t *testing.T) {}}+func TestGhostChromeBorrowsChromeCDPCheck(t *testing.T) {+ checks := (&Browser{}).DoctorChecks(browsers.TargetConfig{})+ for _, check := range checks {+ if check.ID == "cdp_reachable" && check.LaunchesBrowser {+ return+ }+ }+ t.Fatal("ghost-chrome did not borrow Chrome's browser-launching cdp_reachable check")+}+func TestGhostChromeHandleDecisionsCheck(t *testing.T) {b := &Browser{}checks := b.DoctorChecks(browsers.TargetConfig{})diff --git a/internal/doctor/checks_cdp.go b/internal/doctor/checks_cdp.godeleted file mode 100644index e1abc4f5..00000000--- a/internal/doctor/checks_cdp.go+++ /dev/null@@ -1,14 +0,0 @@-package doctor--import (- "context"- "time"-- "github.com/pinchtab/pinchtab/internal/browsers/chrome"-)--type ProbeResult = chrome.CDPProbeResult--func LaunchAndProbe(ctx context.Context, binary string, extraArgs []string, timeout time.Duration) (ProbeResult, error) {- return chrome.LaunchAndProbe(ctx, binary, extraArgs, timeout)-}diff --git a/internal/doctor/format.go b/internal/doctor/format.goindex 218d8fd3..0058d202 100644--- a/internal/doctor/format.go+++ b/internal/doctor/format.go@@ -12,9 +12,12 @@ type jsonReport struct {Target string `json:"target,omitempty"`Results []CheckResult `json:"results"`Summary Summary `json:"summary"`+ Verdict string `json:"verdict"`+ Scope string `json:"scope"`+ Runtime string `json:"runtime,omitempty"`}-func WriteText(w io.Writer, browser, target string, results []CheckResult) {+func WriteText(w io.Writer, browser, target string, results []CheckResult, runtime string) {header := fmt.Sprintf("pinchtab doctor (browser=%s", browser)if target != "" {header += ", target=" + target@@ -29,8 +32,12 @@ func WriteText(w io.Writer, browser, target string, results []CheckResult) {s := Summarize(results)_, _ = fmt.Fprintln(w)- _, _ = fmt.Fprintf(w, "%d passed, %d failed, %d skipped, %d warnings.\n",- s.Passed, s.Failed, s.Skipped, s.Warnings)+ _, _ = fmt.Fprintf(w, "%d passed, %d failed, %d skipped, %d warnings. %s\n",+ s.Passed, s.Failed, s.Skipped, s.Warnings, Verdict(s))+ _, _ = fmt.Fprintln(w, ScopeStatement)+ if runtime != "" {+ _, _ = fmt.Fprintln(w, runtime)+ }}func formatResultLine(r CheckResult) string {@@ -70,18 +77,22 @@ func shortDuration(d time.Duration) string {return fmt.Sprintf("%.1fs", d.Seconds())}-func WriteJSON(w io.Writer, browser, target string, results []CheckResult) error {+func WriteJSON(w io.Writer, browser, target string, results []CheckResult, runtime string) error {// Populate ErrMsg for JSON consumers in case a check forgot to copy from Err.for i := range results {if results[i].Err != nil && results[i].ErrMsg == "" {results[i].ErrMsg = results[i].Err.Error()}}+ summary := Summarize(results)report := jsonReport{Browser: browser,Target: target,Results: results,- Summary: Summarize(results),+ Summary: summary,+ Verdict: Verdict(summary),+ Scope: ScopeStatement,+ Runtime: runtime,}enc := json.NewEncoder(w)enc.SetIndent("", " ")diff --git a/internal/doctor/runner.go b/internal/doctor/runner.goindex f08be99e..41c0d00b 100644--- a/internal/doctor/runner.go+++ b/internal/doctor/runner.go@@ -3,6 +3,7 @@ package doctorimport ("context"+ "fmt""os""runtime""strings"@@ -32,25 +33,47 @@ type CheckResult struct {// a raw time.Duration would marshal nanoseconds under a "Ms" key.Duration time.Duration `json:"-"`DurationMS int64 `json:"durationMs"`+ // LaunchesBrowser marks a check that starts a browsing session; the summary+ // counts how many of those actually ran, which is what separates a clean run+ // from one whose passes never left the binary.+ LaunchesBrowser bool `json:"launchesBrowser"`}type CheckFunc func(ctx context.Context, cfg *config.RuntimeConfig) CheckResulttype CheckEntry struct {- Name string- Fn CheckFunc+ Name string+ Fn CheckFunc+ LaunchesBrowser bool}type Summary struct {- Passed int `json:"passed"`- Failed int `json:"failed"`- Warnings int `json:"warnings"`- Skipped int `json:"skipped"`+ Passed int `json:"passed"`+ Failed int `json:"failed"`+ Warnings int `json:"warnings"`+ Skipped int `json:"skipped"`+ BrowserLaunched int `json:"browserLaunched"`+}++// Verdict is the sentence the counts alone could not say: passes that never+// launched a browser are not a clean bill of health.+func Verdict(s Summary) string {+ switch {+ case s.Failed > 0:+ return fmt.Sprintf("%d check(s) failed.", s.Failed)+ case s.BrowserLaunched == 0:+ return "No check launched a browser: the passes above only inspected the installation, so this is not a clean bill of health."+ default:+ return fmt.Sprintf("Clean: %d check(s) launched a browser and passed.", s.BrowserLaunched)+ }}func Summarize(results []CheckResult) Summary {var s Summaryfor _, r := range results {+ if r.LaunchesBrowser && r.Status != StatusSkip {+ s.BrowserLaunched+++ }switch r.Status {case StatusPass:s.Passed++@@ -87,7 +110,8 @@ func Registry(cfg *config.RuntimeConfig) []CheckEntry {for _, dc := range b.DoctorChecks(browsers.TargetConfig{Provider: browserID}) {dc := dcentries = append(entries, CheckEntry{- Name: dc.ID,+ Name: dc.ID,+ LaunchesBrowser: dc.LaunchesBrowser,Fn: func(ctx context.Context, _ *config.RuntimeConfig) CheckResult {return browserCheckResult(ctx, dc, env)},@@ -169,6 +193,7 @@ func Run(ctx context.Context, cfg *config.RuntimeConfig, checkFilter string) []Cstart := time.Now()r := e.Fn(ctx, cfg)r.Name = e.Name+ r.LaunchesBrowser = e.LaunchesBrowserif r.Duration == 0 {r.Duration = time.Since(start)}diff --git a/internal/doctor/runner_test.go b/internal/doctor/runner_test.goindex 7ddc112e..82720347 100644--- a/internal/doctor/runner_test.go+++ b/internal/doctor/runner_test.go@@ -56,6 +56,7 @@ func TestRun_RegistryOrdering_Chrome(t *testing.T) {wantOrder := []string{"config_file","chrome_present",+ "cdp_reachable","handle_decisions","binary_exists","binary_executable",@@ -114,8 +115,8 @@ func TestKnownCheck(t *testing.T) {if !KnownCheck(cfg, "binary_exists") {t.Error("binary_exists should be known for chrome provider")}- if KnownCheck(cfg, "cdp_reachable") {- t.Error("cdp_reachable should not be known for chrome provider")+ if !KnownCheck(cfg, "cdp_reachable") {+ t.Error("cdp_reachable should be known for chrome provider")}if KnownCheck(cfg, "nonsense") {t.Error("unknown check name should report false")@@ -232,7 +233,7 @@ func TestWriteText_FormatsResults(t *testing.T) {{Name: "linux_fonts_present", Status: StatusSkip, Detail: "not linux", Duration: time.Microsecond},}var buf bytes.Buffer- WriteText(&buf, "cloak", "", results)+ WriteText(&buf, "cloak", "", results, "")out := buf.String()if !strings.Contains(out, "pinchtab doctor (browser=cloak)") {t.Errorf("missing header in output:\n%s", out)@@ -243,6 +244,9 @@ func TestWriteText_FormatsResults(t *testing.T) {if !strings.Contains(out, "1 passed, 1 failed, 1 skipped, 0 warnings.") {t.Errorf("missing or wrong summary:\n%s", out)}+ if !strings.Contains(out, ScopeStatement) {+ t.Errorf("missing doctor scope statement:\n%s", out)+ }}func TestWriteJSON_Structure(t *testing.T) {@@ -251,7 +255,7 @@ func TestWriteJSON_Structure(t *testing.T) {{Name: "binary_starts", Status: StatusFail, Detail: "broken", Err: errors.New("broken")},}var buf bytes.Buffer- if err := WriteJSON(&buf, "cloak", "default", results); err != nil {+ if err := WriteJSON(&buf, "cloak", "default", results, ""); err != nil {t.Fatal(err)}var report jsonReport@@ -270,6 +274,19 @@ func TestWriteJSON_Structure(t *testing.T) {if report.Summary.Passed != 1 || report.Summary.Failed != 1 {t.Errorf("summary wrong: %+v", report.Summary)}+ if report.Scope != ScopeStatement || report.Verdict == "" {+ t.Errorf("scope/verdict missing from JSON report: %+v", report)+ }+}++func TestVerdictDoesNotCallSkippedBrowserChecksClean(t *testing.T) {+ got := Verdict(Summary{Passed: 3, Skipped: 3})+ if strings.HasPrefix(got, "Clean:") {+ t.Fatalf("Verdict() = %q, must not call an installation-only run clean", got)+ }+ if !strings.Contains(got, "No check launched a browser") {+ t.Fatalf("Verdict() = %q, want skipped-browser explanation", got)+ }}// M7 regression: durationMs must marshal milliseconds, not raw nanoseconds.diff --git a/internal/doctor/runtime_hint.go b/internal/doctor/runtime_hint.gonew file mode 100644index 00000000..0adbd1cb--- /dev/null+++ b/internal/doctor/runtime_hint.go@@ -0,0 +1,45 @@+package doctor++import (+ "context"+ "fmt"+ "net"+ "net/http"+ "strings"+ "time"++ "github.com/pinchtab/pinchtab/internal/config"+)++// ScopeStatement is printed with every run: doctor inspects the installation on+// disk and never the running system, which is what lets it work when the browser+// will not start and there is no server to ask.+const ScopeStatement = "Scope: the installation on disk, not any running PinchTab server or browser. " ++ "Runtime state lives at GET /health (crashes, security), `pinchtab security` and GET /instances/{id}/metrics."++const runtimeProbeTimeout = time.Second++// ProbeRuntime names a server answering at the configured address, best-effort.+// It gates nothing and changes no result: an empty answer is the normal case.+func ProbeRuntime(ctx context.Context, cfg *config.RuntimeConfig) string {+ if cfg == nil || strings.TrimSpace(cfg.Port) == "" {+ return ""+ }+ host := strings.TrimSpace(cfg.Bind)+ if host == "" || host == "0.0.0.0" || host == "::" {+ host = "127.0.0.1"+ }+ base := "http://" + net.JoinHostPort(host, strings.TrimSpace(cfg.Port))+ ctx, cancel := context.WithTimeout(ctx, runtimeProbeTimeout)+ defer cancel()+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, base+"/health", nil)+ if err != nil {+ return ""+ }+ resp, err := http.DefaultClient.Do(req)+ if err != nil {+ return ""+ }+ _ = resp.Body.Close()+ return fmt.Sprintf("A PinchTab server is answering at %s: read %s/health for the running browser's crashes and security posture.", base, base)+}diff --git a/internal/doctor/runtime_hint_test.go b/internal/doctor/runtime_hint_test.gonew file mode 100644index 00000000..2f5f3222--- /dev/null+++ b/internal/doctor/runtime_hint_test.go@@ -0,0 +1,40 @@+package doctor++import (+ "context"+ "net"+ "net/http"+ "net/http/httptest"+ "net/url"+ "strings"+ "testing"++ "github.com/pinchtab/pinchtab/internal/config"+)++func TestProbeRuntimeIsBestEffort(t *testing.T) {+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if r.URL.Path != "/health" {+ t.Fatalf("path = %q, want /health", r.URL.Path)+ }+ w.WriteHeader(http.StatusOK)+ }))+ defer srv.Close()++ u, err := url.Parse(srv.URL)+ if err != nil {+ t.Fatal(err)+ }+ host, port, err := net.SplitHostPort(u.Host)+ if err != nil {+ t.Fatal(err)+ }+ hint := ProbeRuntime(context.Background(), &config.RuntimeConfig{Bind: host, Port: port})+ if !strings.Contains(hint, srv.URL) || !strings.Contains(hint, "/health") {+ t.Fatalf("ProbeRuntime() = %q, want runtime health guidance", hint)+ }++ if got := ProbeRuntime(context.Background(), &config.RuntimeConfig{}); got != "" {+ t.Fatalf("ProbeRuntime() without a server address = %q, want empty best-effort result", got)+ }+}