High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: nav hint pushes a session command that errors out when agent sessions are disabled PIN-016
Luigi Agostifbfceea6c448
diff --git a/cmd/pinchtab/cmd_session.go b/cmd/pinchtab/cmd_session.goindex 59043739..7682fa8c 100644--- a/cmd/pinchtab/cmd_session.go+++ b/cmd/pinchtab/cmd_session.go@@ -5,6 +5,7 @@ import ("fmt""os"+ "github.com/pinchtab/pinchtab/internal/cli""github.com/pinchtab/pinchtab/internal/cli/apiclient""github.com/pinchtab/pinchtab/internal/cli/output""github.com/spf13/cobra"@@ -24,7 +25,7 @@ func init() {sessionToken := os.Getenv("PINCHTAB_SESSION")if sessionToken == "" {fmt.Fprintln(os.Stderr, "Error: no session set")- output.Hint("create one: export PINCHTAB_SESSION=$(pinchtab session create --agent-id <id>)")+ output.Hint(cli.NoSessionHint)os.Exit(1)}runCLI(func(rt cliRuntime) {diff --git a/internal/cli/actions/actions_navigate.go b/internal/cli/actions/actions_navigate.goindex 6d49e808..76f47347 100644--- a/internal/cli/actions/actions_navigate.go+++ b/internal/cli/actions/actions_navigate.go@@ -6,6 +6,7 @@ import ("os""strings"+ "github.com/pinchtab/pinchtab/internal/cli""github.com/pinchtab/pinchtab/internal/cli/apiclient""github.com/pinchtab/pinchtab/internal/cli/output""github.com/spf13/cobra"@@ -123,7 +124,7 @@ func Navigate(client *http.Client, base, token string, url string, cmd *cobra.Co}if !isIdentifiedCaller() {- output.Hint("no session set — this tab is shared. Create one with: export PINCHTAB_SESSION=$(pinchtab session create --agent-id <id>)")+ output.Hint(cli.NoSessionHint)}snap, _ := cmd.Flags().GetBool("snap")diff --git a/internal/cli/actions/actions_navigate_test.go b/internal/cli/actions/actions_navigate_test.goindex c80a264b..f0886e27 100644--- a/internal/cli/actions/actions_navigate_test.go+++ b/internal/cli/actions/actions_navigate_test.go@@ -6,6 +6,7 @@ import ("strings""testing"+ "github.com/pinchtab/pinchtab/internal/cli""github.com/spf13/cobra")@@ -240,3 +241,54 @@ func TestNavigatePrintTabID(t *testing.T) {t.Errorf("expected stdout to be exactly 'ABC123', got %q", got)}}++func TestNavigateNoSessionHintNamesPrerequisiteAndCommand(t *testing.T) {+ t.Setenv("PINCHTAB_SESSION", "")+ t.Setenv("PINCHTAB_AGENT_ID", "")++ m := newMockServer()+ m.response = `{"tabId":"ABC123","status":"ok"}`+ defer m.close()++ stderr := captureStderr(t, func() {+ captureStdout(t, func() {+ Navigate(m.server.Client(), m.base(), "", "https://pinchtab.com", newNavigateCmd())+ })+ })++ if !strings.Contains(stderr, cli.NoSessionHint) {+ t.Fatalf("hint = %q, want the shared cli.NoSessionHint", stderr)+ }+ // Following the hint top to bottom must not dead-end in "agent sessions are+ // not enabled on this server", so it has to carry the server-side+ // prerequisite as well as the command.+ if !strings.Contains(cli.NoSessionHint, "sessions.agent.enabled = true") {+ t.Errorf("hint does not name the server-side prerequisite: %q", cli.NoSessionHint)+ }+ if !strings.Contains(cli.NoSessionHint, cli.SessionCreateCommand) {+ t.Errorf("hint does not carry the create command: %q", cli.NoSessionHint)+ }++ // The hint decision reads nothing from the server: navigate stays one request.+ if len(m.requests) != 1 || m.requests[0].Path != "/navigate" {+ t.Fatalf("requests = %+v, want exactly the navigate call", m.requests)+ }+}++func TestNavigateIdentifiedCallerPrintsNoSessionHint(t *testing.T) {+ t.Setenv("PINCHTAB_SESSION", "ses_something")++ m := newMockServer()+ m.response = `{"tabId":"ABC123","status":"ok"}`+ defer m.close()++ stderr := captureStderr(t, func() {+ captureStdout(t, func() {+ Navigate(m.server.Client(), m.base(), "", "https://pinchtab.com", newNavigateCmd())+ })+ })++ if strings.Contains(stderr, cli.SessionCreateCommand) {+ t.Fatalf("stderr = %q, want no session hint for an identified caller", stderr)+ }+}diff --git a/internal/cli/hints.go b/internal/cli/hints.goindex e83a1375..cad7d668 100644--- a/internal/cli/hints.go+++ b/internal/cli/hints.go@@ -32,10 +32,21 @@ func WriteCommandHints(out io.Writer, heading string, hints []CommandHint, width}}+// SessionCreateCommand is the one spelling of the create-a-session command, so+// every place that recommends it stays in lockstep.+const SessionCreateCommand = "export PINCHTAB_SESSION=$(pinchtab session create --agent-id <id>)"++// NoSessionHint is the single wording for "this caller has no agent session".+// It names the server-side prerequisite before the command, because the command+// exits 1 with "agent sessions are not enabled on this server" on default+// config — so a user following the hint top to bottom cannot dead-end.+const NoSessionHint = "this tab is shared — no agent session is set. Agent sessions must be enabled on the server " ++ "(sessions.agent.enabled = true in config.json, then restart); once they are, create one with: " + SessionCreateCommand+// NextStepsRunningHints is the "Next steps" group shown when the server is up;// shared by the root banner and `pinchtab health` so the two stay in lockstep.var NextStepsRunningHints = []CommandHint{- {"export PINCHTAB_SESSION=$(pinchtab session create --agent-id <id>)", "# start a dedicated session"},+ {SessionCreateCommand, "# start a dedicated session"},{"pinchtab nav <url>", "# navigate the current tab (headless by default)"},{"pinchtab snap", "# inspect interactive elements"},}