High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(cli): let a suppressed advisory keep its hands off the run's silencer, and isolate the state dir for the whole actions suite (PIN-297)
Luigi Agosti6835047aea09
diff --git a/internal/bridge/quarantine_reclaim_test.go b/internal/bridge/quarantine_reclaim_test.goindex 997d555b..f109c2ba 100644--- a/internal/bridge/quarantine_reclaim_test.go+++ b/internal/bridge/quarantine_reclaim_test.go@@ -335,6 +335,13 @@ var directoryRemovers = []directoryRemover{route: "test harness only",why: "removes a t.TempDir-rooted browser profile built for one test",},+ {+ path: "internal/cli/output/advisory.go",+ funcs: []string{"ResetAdvisories"},+ underProfilesBase: false,+ route: "ResetAdvisories only — no ordinary command reaches it; it is the deliberate 'let me hear the advice again' path and the tests' fresh-install helper",+ why: "removes the advisories marker directory under the CLI state dir, never a browser profile, so the quarantine predicate does not apply. The join cannot widen: clistate.Dir() answers a non-empty path in every branch (XDG_STATE_HOME, the home fallback, os.TempDir), so the removal is always .../pinchtab/advisories and never the state dir itself or the filesystem root",+ },{path: "tests/tools/runner/internal/e2e/provider.go",funcs: []string{"cleanup", "prepareCloakOverrides", "prepareGhostChromeOverrides"},diff --git a/internal/cli/actions/advisory_hint_test.go b/internal/cli/actions/advisory_hint_test.goindex 30c9f0f1..9271b671 100644--- a/internal/cli/actions/advisory_hint_test.go+++ b/internal/cli/actions/advisory_hint_test.go@@ -1,7 +1,9 @@package actionsimport (+ "fmt""net/http"+ "os""strings""testing"@@ -9,6 +11,30 @@ import ("github.com/pinchtab/pinchtab/internal/cli/output")+// TestMain moves the CLI state directory for the WHOLE package, because an advisory+// marker is written by the production code under test rather than by a helper: any+// test in this package that reaches Navigate writes one, and a per-test Setenv only+// protects the tests that remember it. Unprotected, the suite silences the very+// advisory this package asserts on for the operator who ran it, and every later+// assertion here depends on whether the suite has run on that machine before.+//+// It is os.Setenv rather than t.Setenv because TestMain has no *testing.T, and the+// exit path restores nothing on purpose: the process is about to end.+func TestMain(m *testing.M) {+ dir, err := os.MkdirTemp("", "pinchtab-cli-state")+ if err != nil {+ fmt.Fprintf(os.Stderr, "cannot isolate the CLI state directory: %v\n", err)+ os.Exit(1)+ }+ if err := os.Setenv("XDG_STATE_HOME", dir); err != nil {+ fmt.Fprintf(os.Stderr, "cannot isolate the CLI state directory: %v\n", err)+ os.Exit(1)+ }+ code := m.Run()+ _ = os.RemoveAll(dir)+ os.Exit(code)+}+// staleTabCmd drives the fallback that reports a dead tab — an occurrence hint,// which must print on every occurrence — alongside the no-session advisory.func navigateOverAStaleTab(t *testing.T, m *mockServer) func() {diff --git a/internal/cli/output/advisory.go b/internal/cli/output/advisory.goindex 36179e44..491865dc 100644--- a/internal/cli/output/advisory.go+++ b/internal/cli/output/advisory.go@@ -44,7 +44,14 @@ var (// A hint that reports what just happened is not advisory: it belongs on Hint,// which prints every time it fires, because the second occurrence is news too.func Advisory(text string) {- if AdvisoriesSilenced() {+ // Both suppression checks come FIRST, because a suppressed advisory must change+ // no state. Taking the silencer decision before consulting the marker spent the+ // run's one silencer line on an advisory that then printed nothing, so the next+ // advisory — the one the caller is seeing for the first time — arrived with no+ // opt-out beside it. Two different advisories reach one process on the ordinary+ // path (the redundant --server notice and the no-session hint), so that is a+ // real caller's first sight of the switch, not a test-only shape.+ if AdvisoriesSilenced() || advisoryAlreadyShown(text) {return}@@ -55,7 +62,7 @@ func Advisory(text string) {silencerShown = silencerShown || firstadvisoryMu.Unlock()- if !first || advisoryAlreadyShown(text) {+ if !first {return}if withSilencer {diff --git a/internal/cli/output/advisory_test.go b/internal/cli/output/advisory_test.goindex c5252081..f06a1005 100644--- a/internal/cli/output/advisory_test.go+++ b/internal/cli/output/advisory_test.go@@ -144,6 +144,36 @@ func TestASecondAdvisoryIsNotSuppressedByTheFirst(t *testing.T) {}}+// The run where the two suppression states MEET, which is the ordinary path once a+// caller has run any command that emits its own advisory: an already-shown one is+// suppressed and a brand-new one prints in the same process. The new advisory is+// the caller's first sight of this class, so it must carry the switch — an+// advisory that prints nothing must not consume the run's silencer on its way out.+func TestASuppressedAdvisoryDoesNotConsumeTheSilencerOfANewOne(t *testing.T) {+ isolatedInstall(t)++ const other = "a different steady state: export PINCHTAB_SOMETHING=1"+ if first := captureStderr(t, func() { Advisory(testAdvisory) }); !strings.Contains(first, SilenceAdvisoryHint) {+ t.Fatalf("the first run printed no silencer (%q), so this test never reached the state it is about", first)+ }++ nextInvocation()+ out := captureStderr(t, func() {+ Advisory(testAdvisory)+ Advisory(other)+ })++ if strings.Contains(out, testAdvisory) {+ t.Errorf("the already-shown advisory printed again: %q", out)+ }+ if !strings.Contains(out, other) {+ t.Errorf("the new advisory was suppressed by an unrelated one: %q", out)+ }+ if !strings.Contains(out, SilenceAdvisoryHint) {+ t.Errorf("the new advisory arrived with no way to learn about the switch: %q", out)+ }+}+// ResetAdvisories has to reach the marker too, or a test asking for a fresh run// gets a machine that has already heard everything.func TestResetAdvisoriesClearsThePersistedMarker(t *testing.T) {