Skip to content

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

fix: the server discards all logs unless --verbose (PIN-072)

Luigi Agostif9b5cffab7f7
diff --git a/docs/commands.md b/docs/commands.md
index 2aef13d2..b5cd1be2 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -28,6 +28,11 @@ is set: `--log-level debug|info|warn|error`, then `server.logLevel` in the confi
file, then `-v`, then the default `info`. `-v` always adds the full startup banner,
and it raises the level to debug only when neither of the other two is set.
+The access log is what an open dashboard costs: its errors and console panels each poll
+on a 3s interval, so a dashboard left open writes roughly 40 lines a minute. That is the
+deliberate trade for a run that explains itself afterwards, and `--log-level warn` is the
+escape hatch when you want the record without the polling.
+
A daemon-installed server and the server a bare `pinchtab nav` auto-starts both run
`pinchtab server` with no flags, so `server.logLevel` is the only way to set their
threshold (`pinchtab config set server.logLevel warn`).
diff --git a/internal/safelog/handler.go b/internal/safelog/handler.go
index 0e8403a1..8d4c2cb2 100644
--- a/internal/safelog/handler.go
+++ b/internal/safelog/handler.go
@@ -13,7 +13,6 @@ import (
"github.com/pinchtab/pinchtab/internal/sanitize"
)
-// DefaultLevel is what a run records with no level set.
const DefaultLevel = slog.LevelInfo
// LevelName renders a level the way the config file and --log-level spell it, so a
diff --git a/internal/safelog/handler_test.go b/internal/safelog/handler_test.go
index 69703d5a..dc64975e 100644
--- a/internal/safelog/handler_test.go
+++ b/internal/safelog/handler_test.go
@@ -2,9 +2,16 @@ package safelog
import (
"bytes"
+ "io/fs"
"log/slog"
+ "os"
+ "path"
+ "path/filepath"
+ "reflect"
"strings"
"testing"
+
+ "github.com/pinchtab/pinchtab/internal/srccensus"
)
func TestHandlerRedactsAndSanitizesStringAttrs(t *testing.T) {
@@ -114,3 +121,97 @@ func TestParseLevel(t *testing.T) {
}
}
}
+
+// InstallDefault owns the process default logger, and a second owner — the server
+// installing a discard handler — is what silenced every default run. RunDashboard starts
+// a server, so no unit test reaches that line: the invariant is only checkable
+// structurally, and it belongs to the package that holds the rule.
+//
+// The scope is derived: every package directory under cmd/, internal/ and pkg/, so a new
+// installer anywhere in this repo's own source reddens it. tests/, tools/, scripts/,
+// plugin/ and docs/examples/ are deliberately out of scope — a harness or example binary
+// installing its own logger is legitimate, and walking them means walking node_modules.
+func TestOnlySafelogInstallsTheProcessLogger(t *testing.T) {
+ installers := []string{}
+ scanned := 0
+ for _, dir := range sourcePackageDirs(t) {
+ pkg := srccensus.Load(t, filepath.Join("..", "..", dir), 1)
+ scanned += len(pkg.Files())
+ for _, site := range pkg.CallsAllowingNone("slog.SetDefault") {
+ installers = append(installers, path.Join(dir, site.File))
+ }
+ }
+ if scanned < minRepoSourceFiles {
+ t.Fatalf("censused %d non-test files under cmd/, internal/ and pkg/, want at least %d; the scan lost most of the repo and would pass vacuously", scanned, minRepoSourceFiles)
+ }
+
+ want := []string{"internal/safelog/handler.go"}
+ if !reflect.DeepEqual(installers, want) {
+ t.Errorf("slog.SetDefault callers = %v, want only %v; two writers to the process default logger is what silenced the server — route the new caller through InstallDefault, or if ownership genuinely moved, re-point this census at the new owner rather than deleting it", installers, want)
+ }
+}
+
+// The discard handler lived in internal/server, and a package-local test there could not
+// state why it must never come back: recording a run is safelog's job, not the server's.
+func TestTheServerNeverDiscardsLogOutput(t *testing.T) {
+ paths, err := filepath.Glob(filepath.Join("..", "server", "*.go"))
+ if err != nil {
+ t.Fatalf("cannot enumerate internal/server, so this guard would check nothing: %v", err)
+ }
+
+ scanned := 0
+ for _, sourcePath := range paths {
+ if strings.HasSuffix(sourcePath, "_test.go") {
+ continue
+ }
+ raw, err := os.ReadFile(sourcePath)
+ if err != nil {
+ t.Fatalf("cannot read %s, so this guard would skip it silently: %v", sourcePath, err)
+ }
+ scanned++
+ for i, line := range strings.Split(string(raw), "\n") {
+ if strings.HasPrefix(strings.TrimSpace(line), "//") {
+ continue
+ }
+ if strings.Contains(line, "io."+"Discard") {
+ t.Errorf("internal/server/%s:%d discards log output; a run must record its requests and errors without a flag, and the level belongs in safelog", filepath.Base(sourcePath), i+1)
+ }
+ }
+ }
+ if scanned < minServerSourceFiles {
+ t.Fatalf("scanned %d non-test files in internal/server, want at least %d; the guard matched almost nothing and would pass vacuously", scanned, minServerSourceFiles)
+ }
+}
+
+const (
+ minRepoSourceFiles = 500
+ minServerSourceFiles = 5
+)
+
+func sourcePackageDirs(t *testing.T) []string {
+ t.Helper()
+
+ dirs := []string{}
+ for _, root := range []string{"cmd", "internal", "pkg"} {
+ err := filepath.WalkDir(filepath.Join("..", "..", root), func(sourcePath string, entry fs.DirEntry, err error) error {
+ if err != nil {
+ return err
+ }
+ if entry.IsDir() || !strings.HasSuffix(sourcePath, ".go") || strings.HasSuffix(sourcePath, "_test.go") {
+ return nil
+ }
+ dir := path.Clean(filepath.ToSlash(strings.TrimPrefix(filepath.Dir(sourcePath), filepath.Join("..", "..")+string(filepath.Separator))))
+ if len(dirs) == 0 || dirs[len(dirs)-1] != dir {
+ dirs = append(dirs, dir)
+ }
+ return nil
+ })
+ if err != nil {
+ t.Fatalf("cannot enumerate %s, so this census would silently skip it: %v", root, err)
+ }
+ }
+ if len(dirs) == 0 {
+ t.Fatal("no package directory found under cmd/, internal/ or pkg/; this census is checking nothing")
+ }
+ return dirs
+}
diff --git a/internal/server/server_test.go b/internal/server/server_test.go
index a302b35e..98d6090a 100644
--- a/internal/server/server_test.go
+++ b/internal/server/server_test.go
@@ -2,13 +2,9 @@ package server
import (
"bytes"
- "io/fs"
"log/slog"
"net/http"
"net/http/httptest"
- "os"
- "path/filepath"
- "reflect"
"strings"
"testing"
@@ -62,62 +58,3 @@ func TestDefaultRunRecordsErrorsAndWarnings(t *testing.T) {
t.Errorf("a default run dropped an error:\n%s", out)
}
}
-
-// RunDashboard starts a server, so no unit test calls it; the second-owner
-// regression is only reachable as a structural guard.
-func TestOnlySafelogInstallsTheProcessLogger(t *testing.T) {
- root, err := filepath.Abs("../..")
- if err != nil {
- t.Fatal(err)
- }
-
- installers := []string{}
- scanned := 0
- walkErr := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
- if err != nil {
- return err
- }
- if d.IsDir() || !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
- return nil
- }
- raw, err := os.ReadFile(path)
- if err != nil {
- return err
- }
- scanned++
- rel := filepath.ToSlash(mustRel(t, root, path))
- for _, line := range strings.Split(string(raw), "\n") {
- trimmed := strings.TrimSpace(line)
- if strings.HasPrefix(trimmed, "//") {
- continue
- }
- if strings.Contains(trimmed, "slog.SetDefault(") {
- installers = append(installers, rel)
- }
- }
- if strings.HasPrefix(rel, "internal/server/") && strings.Contains(string(raw), "io."+"Discard") {
- t.Errorf("%s discards log output; a run must record its requests and errors without a flag", rel)
- }
- return nil
- })
- if walkErr != nil {
- t.Fatal(walkErr)
- }
- if scanned == 0 {
- t.Fatal("no Go file scanned — this guard is checking nothing")
- }
-
- want := []string{"internal/safelog/handler.go"}
- if !reflect.DeepEqual(installers, want) {
- t.Errorf("slog.SetDefault callers = %v, want only %v; two writers to the process default logger is what silenced the server", installers, want)
- }
-}
-
-func mustRel(t *testing.T, root, path string) string {
- t.Helper()
- rel, err := filepath.Rel(root, path)
- if err != nil {
- t.Fatal(err)
- }
- return rel
-}
diff --git a/skills/pinchtab/references/commands.md b/skills/pinchtab/references/commands.md
index 14bcf720..ef56139a 100644
--- a/skills/pinchtab/references/commands.md
+++ b/skills/pinchtab/references/commands.md
@@ -19,6 +19,8 @@ pinchtab server -e ./ext # load browser extension
|------|-------|-------------|
| `--headed` | `-H` | Start browser in headed (visible) mode |
| `--extension <path>` | `-e` | Load browser extension (repeatable) |
+| `--log-level <level>` | | Log threshold: `debug`, `info` (default), `warn` or `error` |
+| `--verbose` | `-v` | Show the full startup banner and log at debug level |
> **Note:** Use `--headed` only when you need visual feedback (debugging, watching automation). Headless mode is more resource-efficient.