High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: PINCHTAB_PORT is advertised by the CLI but read nowhere, and server has no --port flag PIN-018
Luigi Agosti5b81bf5eb27a
diff --git a/cmd/pinchtab/cmd_server.go b/cmd/pinchtab/cmd_server.goindex 97840dfa..07d3316a 100644--- a/cmd/pinchtab/cmd_server.go+++ b/cmd/pinchtab/cmd_server.go@@ -3,6 +3,7 @@ package mainimport ("fmt""os"+ "strings""github.com/pinchtab/pinchtab/internal/cli""github.com/pinchtab/pinchtab/internal/config"@@ -21,6 +22,10 @@ var serverCmd = &cobra.Command{backgroundMarker, _ := cmd.Flags().GetString("background-child")cfg.BackgroundMarker = backgroundMarker+ bind, _ := cmd.Flags().GetString("bind")+ port, _ := cmd.Flags().GetString("port")+ applyServerAddressFlags(cfg, bind, port)+yolo, _ := cmd.Flags().GetBool("yolo")if yolo {fc, _, err := config.LoadFileConfig()@@ -65,6 +70,8 @@ var serverCmd = &cobra.Command{Verbose: verbose,Extensions: append([]string(nil), exts...),Browser: browserName,+ Bind: bind,+ Port: port,}); err != nil {fmt.Fprintln(os.Stderr, cli.StyleStderr(cli.ErrorStyle, err.Error()))os.Exit(1)@@ -75,8 +82,22 @@ var serverCmd = &cobra.Command{},}+// applyServerAddressFlags applies the --bind/--port overrides, mirroring the+// bridge's precedence: a non-empty flag wins over config, an omitted one leaves+// the configured value in place.+func applyServerAddressFlags(cfg *config.RuntimeConfig, bind, port string) {+ if v := strings.TrimSpace(bind); v != "" {+ cfg.Bind = v+ }+ if v := strings.TrimSpace(port); v != "" {+ cfg.Port = v+ }+}+func init() {serverCmd.GroupID = "primary"+ serverCmd.Flags().String("bind", "", "Bind address for the HTTP server (overrides config server.bind)")+ serverCmd.Flags().String("port", "", "Port for the HTTP server (overrides config server.port)")serverCmd.Flags().StringArrayP("extension", "e", nil, "Load browser extension (repeatable)")serverCmd.Flags().BoolP("headed", "H", false, "Start default instance in headed mode")serverCmd.Flags().BoolP("yolo", "y", false, "Apply guards down preset (enables evaluate, macro, download, cookies)")diff --git a/cmd/pinchtab/cmd_server_background.go b/cmd/pinchtab/cmd_server_background.goindex cea7fa7e..00155441 100644--- a/cmd/pinchtab/cmd_server_background.go+++ b/cmd/pinchtab/cmd_server_background.go@@ -40,6 +40,8 @@ type serverBackgroundOptions struct {Verbose boolExtensions []stringBrowser string+ Bind string+ Port string}var readProcessCommand = defaultReadProcessCommand@@ -213,6 +215,14 @@ func backgroundServerArgs(marker string, opts serverBackgroundOptions) []stringif opts.Browser != "" {args = append(args, "--browser", opts.Browser)}+ // The parent already applied these to cfg and waits on the resulting URL, so+ // the detached child must bind the same address, not the config default.+ if opts.Bind != "" {+ args = append(args, "--bind", opts.Bind)+ }+ if opts.Port != "" {+ args = append(args, "--port", opts.Port)+ }return args}diff --git a/cmd/pinchtab/cmd_server_test.go b/cmd/pinchtab/cmd_server_test.gonew file mode 100644index 00000000..c18b3b7f--- /dev/null+++ b/cmd/pinchtab/cmd_server_test.go@@ -0,0 +1,77 @@+package main++import (+ "reflect"+ "testing"++ "github.com/pinchtab/pinchtab/internal/config"+)++func TestApplyServerAddressFlagsPrecedence(t *testing.T) {+ tests := []struct {+ name string+ bind string+ port string+ wantBind string+ wantPort string+ }{+ {name: "no flags leaves config", wantBind: "127.0.0.1", wantPort: "9867"},+ {name: "port flag wins", port: "9880", wantBind: "127.0.0.1", wantPort: "9880"},+ {name: "bind flag wins", bind: "0.0.0.0", wantBind: "0.0.0.0", wantPort: "9867"},+ {name: "both flags win", bind: "0.0.0.0", port: "9880", wantBind: "0.0.0.0", wantPort: "9880"},+ {name: "blank flags leave config", bind: " ", port: " ", wantBind: "127.0.0.1", wantPort: "9867"},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ cfg := &config.RuntimeConfig{Bind: "127.0.0.1", Port: "9867"}+ applyServerAddressFlags(cfg, tt.bind, tt.port)+ if cfg.Bind != tt.wantBind {+ t.Errorf("Bind = %q, want %q", cfg.Bind, tt.wantBind)+ }+ if cfg.Port != tt.wantPort {+ t.Errorf("Port = %q, want %q", cfg.Port, tt.wantPort)+ }+ })+ }+}++// The server command must accept the same address overrides as `pinchtab+// bridge`, or the two server modes disagree about how to move off the config+// port — which is what the not-running guidance now tells users to do.+func TestServerCmdAddressFlagsMatchBridge(t *testing.T) {+ for _, name := range []string{"bind", "port"} {+ serverFlag := serverCmd.Flags().Lookup(name)+ if serverFlag == nil {+ t.Fatalf("server has no --%s flag", name)+ }+ bridgeFlag := bridgeCmd.Flags().Lookup(name)+ if bridgeFlag == nil {+ t.Fatalf("bridge has no --%s flag", name)+ }+ if serverFlag.Value.Type() != bridgeFlag.Value.Type() {+ t.Errorf("--%s type = %q, want bridge's %q", name, serverFlag.Value.Type(), bridgeFlag.Value.Type())+ }+ if serverFlag.DefValue != "" {+ t.Errorf("--%s default = %q, want empty so config keeps winning", name, serverFlag.DefValue)+ }+ }+}++// The detached child re-parses its own flags, so an address override applied in+// the parent has to travel with it; otherwise the parent waits on a URL the+// child never binds.+func TestBackgroundServerArgsForwardsAddressFlags(t *testing.T) {+ got := backgroundServerArgs("marker-123", serverBackgroundOptions{+ Bind: "0.0.0.0",+ Port: "9880",+ })+ want := []string{+ "server", "--background-child", "marker-123",+ "--bind", "0.0.0.0",+ "--port", "9880",+ }+ if !reflect.DeepEqual(got, want) {+ t.Fatalf("backgroundServerArgs() = %#v, want %#v", got, want)+ }+}diff --git a/internal/cli/apiclient/diagnostics.go b/internal/cli/apiclient/diagnostics.goindex ef145068..65893888 100644--- a/internal/cli/apiclient/diagnostics.go+++ b/internal/cli/apiclient/diagnostics.go@@ -23,7 +23,7 @@ func CheckServerAndGuide(client *http.Client, base, token string) bool {fmt.Fprintln(os.Stderr, "To start the server")fmt.Fprintln(os.Stderr, " pinchtab # Run in foreground (recommended for beginners)")fmt.Fprintln(os.Stderr, " pinchtab & # Run in background")- fmt.Fprintln(os.Stderr, " PINCHTAB_PORT=9868 pinchtab # Use different port")+ fmt.Fprintln(os.Stderr, " pinchtab server --port 9868 # Use different port")fmt.Fprintln(os.Stderr)fmt.Fprintln(os.Stderr, "Then try your command again")fmt.Fprintf(os.Stderr, " %s\n", strings.Join(os.Args, " "))diff --git a/internal/cli/apiclient/diagnostics_test.go b/internal/cli/apiclient/diagnostics_test.gonew file mode 100644index 00000000..28893da7--- /dev/null+++ b/internal/cli/apiclient/diagnostics_test.go@@ -0,0 +1,59 @@+package apiclient++import (+ "bytes"+ "io"+ "net/http"+ "os"+ "strings"+ "testing"+)++func captureStderr(t *testing.T, fn func()) string {+ t.Helper()++ oldStderr := os.Stderr+ reader, writer, err := os.Pipe()+ if err != nil {+ t.Fatalf("os.Pipe: %v", err)+ }+ os.Stderr = writer++ var buf bytes.Buffer+ done := make(chan error, 1)+ go func() {+ _, copyErr := io.Copy(&buf, reader)+ _ = reader.Close()+ done <- copyErr+ }()++ defer func() { os.Stderr = oldStderr }()++ fn()++ _ = writer.Close()+ if err := <-done; err != nil {+ t.Fatalf("io.Copy: %v", err)+ }+ return buf.String()+}++// The not-running guidance may only name mechanisms that exist: PINCHTAB_PORT+// is written into launched instances and read by nothing, so following it left+// the server on the config port.+func TestCheckServerAndGuideNamesTheWorkingPortOverride(t *testing.T) {+ var running bool+ output := captureStderr(t, func() {+ running = CheckServerAndGuide(&http.Client{}, "http://127.0.0.1:1", "")+ })++ if running {+ t.Fatal("CheckServerAndGuide() = true against a closed port")+ }+ if strings.Contains(output, "PINCHTAB_PORT") {+ t.Errorf("guidance still advertises PINCHTAB_PORT, which nothing reads:\n%s", output)+ }+ if !strings.Contains(output, "pinchtab server --port") {+ t.Errorf("guidance does not name the --port flag:\n%s", output)+ }+}