Skip to content

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

fix: -v with a persisted server.logLevel silently does not raise the level, and nothing on screen says why (PIN-104)

Luigi Agostia66c6c0b5e64
diff --git a/cmd/pinchtab/cmd_server.go b/cmd/pinchtab/cmd_server.go
index 21cd1697..08064d22 100644
--- a/cmd/pinchtab/cmd_server.go
+++ b/cmd/pinchtab/cmd_server.go
@@ -117,10 +117,36 @@ func applyServerAddressFlags(cfg *config.RuntimeConfig, bind, port string) {
// starts resolves its own. Give either of them a level flag and it must route
// through here.
func resolveLogLevel(cfg *config.RuntimeConfig, logLevel string, verbose bool) {
+ notice := verboseLevelNotice(logLevel, cfg.LogLevel, verbose)
if v := strings.TrimSpace(logLevel); v != "" {
cfg.LogLevel = v
}
applyLogLevel(cfg, verbose)
+ if notice != "" {
+ fmt.Fprintln(os.Stderr, cli.StyleStderr(cli.WarningStyle, notice))
+ }
+}
+
+// verboseLevelNotice explains the one case where -v looks like a no-op: it always adds
+// the banner, but it only raises the level when neither --log-level nor server.logLevel
+// has set one. It reads both sources BEFORE resolveLogLevel folds the flag into
+// cfg.LogLevel, which is the only point at which they are still distinguishable.
+func verboseLevelNotice(flagLevel, configLevel string, verbose bool) string {
+ if !verbose {
+ return ""
+ }
+ level, source := strings.TrimSpace(flagLevel), "--log-level"
+ if level == "" {
+ level, source = strings.TrimSpace(configLevel), "server.logLevel in the config file"
+ }
+ if level == "" {
+ return ""
+ }
+ parsed, err := safelog.ParseLevel(level)
+ if err != nil || parsed == slog.LevelDebug {
+ return ""
+ }
+ return fmt.Sprintf("-v: log level stays %s, set by %s; pass --log-level debug to raise it", level, source)
}
func applyLogLevel(cfg *config.RuntimeConfig, verbose bool) {
diff --git a/cmd/pinchtab/cmd_server_test.go b/cmd/pinchtab/cmd_server_test.go
index bdb5da21..a24b6e65 100644
--- a/cmd/pinchtab/cmd_server_test.go
+++ b/cmd/pinchtab/cmd_server_test.go
@@ -166,6 +166,121 @@ func TestLogLevelPrecedenceFlagBeatsConfigBeatsDefault(t *testing.T) {
}
}
+// -v always adds the banner but only raises the level when nothing else set one. That
+// is the documented precedence and it stays; the notice is what makes it discoverable
+// instead of a silent no-op. It is a diagnostic for a person who typed -v, so every
+// other shape — the sources agreeing, -v being the thing that sets the level, a run
+// with no -v at all — must stay silent.
+func TestVerboseLevelNoticeNamesTheSourceThatWon(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ flag string
+ configLevel string
+ verbose bool
+ want string
+ }{
+ {
+ name: "config beats verbose",
+ configLevel: "warn",
+ verbose: true,
+ want: "-v: log level stays warn, set by server.logLevel in the config file; pass --log-level debug to raise it",
+ },
+ {
+ name: "flag beats verbose",
+ flag: "error",
+ verbose: true,
+ want: "-v: log level stays error, set by --log-level; pass --log-level debug to raise it",
+ },
+ {
+ name: "flag beats config and is named as the source",
+ flag: "error",
+ configLevel: "warn",
+ verbose: true,
+ want: "-v: log level stays error, set by --log-level; pass --log-level debug to raise it",
+ },
+ {name: "sources agree via the flag", flag: "debug", verbose: true},
+ {name: "sources agree via the config", configLevel: "debug", verbose: true},
+ {name: "sources agree in another case", configLevel: "DEBUG", verbose: true},
+ {name: "verbose is the thing setting the level", verbose: true},
+ {name: "blank flag and blank config", flag: " ", configLevel: " ", verbose: true},
+ {name: "instance-style config without verbose", configLevel: "warn"},
+ {name: "flag without verbose", flag: "error"},
+ {name: "nothing at all"},
+ {name: "an invalid level is applyLogLevel's business", configLevel: "shout", verbose: true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := verboseLevelNotice(tc.flag, tc.configLevel, tc.verbose); got != tc.want {
+ t.Errorf("verboseLevelNotice(%q, %q, %v) = %q, want %q", tc.flag, tc.configLevel, tc.verbose, got, tc.want)
+ }
+ })
+ }
+}
+
+// The notice is only worth anything if resolveLogLevel actually emits it, and it must
+// land on stderr: stdout belongs to commands whose output is a consumed value.
+func TestResolveLogLevelEmitsTheVerboseNoticeOnStderr(t *testing.T) {
+ t.Cleanup(func() { safelog.SetLevel(safelog.DefaultLevel) })
+
+ for _, tc := range []struct {
+ name string
+ configLevel string
+ verbose bool
+ wantNotice bool
+ }{
+ {name: "verbose against a persisted level", configLevel: "warn", verbose: true, wantNotice: true},
+ {name: "instance-style config with no verbose", configLevel: "warn"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ safelog.SetLevel(slog.LevelInfo)
+ cfg := &config.RuntimeConfig{LogLevel: tc.configLevel}
+
+ stdout, stderr := captureStdoutStderr(t, func() { resolveLogLevel(cfg, "", tc.verbose) })
+
+ if got := strings.Contains(stderr, "pass --log-level debug to raise it"); got != tc.wantNotice {
+ t.Errorf("stderr carries the notice = %v, want %v (stderr = %q)", got, tc.wantNotice, stderr)
+ }
+ if stdout != "" {
+ t.Errorf("stdout = %q, want nothing; the notice is a diagnostic", stdout)
+ }
+ if got := safelog.CurrentLevel(); got != slog.LevelWarn {
+ t.Errorf("level = %v, want warn; the notice must not change the precedence", got)
+ }
+ })
+ }
+}
+
+func captureStdoutStderr(t *testing.T, fn func()) (string, string) {
+ t.Helper()
+ outR, outW, err := os.Pipe()
+ if err != nil {
+ t.Fatal(err)
+ }
+ errR, errW, err := os.Pipe()
+ if err != nil {
+ t.Fatal(err)
+ }
+ origOut, origErr := os.Stdout, os.Stderr
+ os.Stdout, os.Stderr = outW, errW
+
+ fn()
+
+ os.Stdout, os.Stderr = origOut, origErr
+ if err := outW.Close(); err != nil {
+ t.Fatal(err)
+ }
+ if err := errW.Close(); err != nil {
+ t.Fatal(err)
+ }
+ var outBuf, errBuf bytes.Buffer
+ if _, err := outBuf.ReadFrom(outR); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := errBuf.ReadFrom(errR); err != nil {
+ t.Fatal(err)
+ }
+ return outBuf.String(), errBuf.String()
+}
+
// The daemon install and the auto-started server both launch `pinchtab server`
// with no flags, so the config file is the only way either can ask for a level.
// This drives the flagless path end to end: file config in, resolved threshold out.