High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(health): count profiles in three disjoint buckets so /health's profiles matches what GET /profiles manages, with temporaryProfiles beside quarantinedProfiles (PIN-308)
Luigi Agosti52854b5985df
diff --git a/docs/endpoints.md b/docs/endpoints.mdindex e5734416..e979ecf4 100644--- a/docs/endpoints.md+++ b/docs/endpoints.md@@ -20,6 +20,11 @@ Notes:- in bridge mode, `/health` reports bridge health and tab count- in full server mode, `/health` reports dashboard health, auth state, and instance count+- server-mode `/health` counts profiles in three disjoint buckets: `profiles` is the+ persistent, non-quarantined profiles an operator manages; `temporaryProfiles` the+ `instance-*` profiles minted by instance starts that named none; `quarantinedProfiles`+ the corrupted ones renamed aside. The default `GET /profiles` list is+ `profiles + quarantinedProfiles` (it hides temporaries; `?all=true` shows every bucket)- a browser crash is reported the same way in both modes: `/health` carries a `crashes`block (`total`, `recent`) whenever the browser behind it has crashed. In bridge mode thebridge records its own; in full server mode the front door merges every instance'sdiff --git a/internal/dashboard/config_health.go b/internal/dashboard/config_health.goindex b343bd87..1ab5543c 100644--- a/internal/dashboard/config_health.go+++ b/internal/dashboard/config_health.go@@ -32,6 +32,7 @@ type healthEnvelope struct {Uptime int64 `json:"uptime"`AuthRequired bool `json:"authRequired"`Profiles int `json:"profiles"`+ TemporaryProfiles int `json:"temporaryProfiles"`QuarantinedProfiles int `json:"quarantinedProfiles"`Instances int `json:"instances"`DefaultInstance *healthInstanceInfo `json:"defaultInstance,omitempty"`@@ -52,16 +53,19 @@ func (c *ConfigAPI) healthInfo(includeSecurity bool) (healthEnvelope, error) {return healthEnvelope{}, err}- profileCount, quarantinedCount := 0, 0+ profileCount, temporaryCount, quarantinedCount := 0, 0, 0if c.profiles != nil {profiles, err := c.profiles.List()if err == nil {for _, p := range profiles {- if p.Quarantined {+ switch {+ case p.Quarantined:quarantinedCount++- continue+ case p.Temporary:+ temporaryCount+++ default:+ profileCount++}- profileCount++}}}@@ -90,6 +94,7 @@ func (c *ConfigAPI) healthInfo(includeSecurity bool) (healthEnvelope, error) {Uptime: int64(time.Since(c.startedAt).Milliseconds()),AuthRequired: cfg != nil && strings.TrimSpace(cfg.Token) != "",Profiles: profileCount,+ TemporaryProfiles: temporaryCount,QuarantinedProfiles: quarantinedCount,Instances: instanceCount,DefaultInstance: defaultInst,diff --git a/internal/dashboard/config_health_test.go b/internal/dashboard/config_health_test.gonew file mode 100644index 00000000..76e741a2--- /dev/null+++ b/internal/dashboard/config_health_test.go@@ -0,0 +1,84 @@+package dashboard++import (+ "encoding/json"+ "net/http"+ "net/http/httptest"+ "os"+ "path/filepath"+ "testing"+ "time"++ "github.com/pinchtab/pinchtab/internal/config"+ "github.com/pinchtab/pinchtab/internal/profiles"+)++func profileDir(t *testing.T, baseDir, name string) {+ t.Helper()+ if err := os.MkdirAll(filepath.Join(baseDir, name, "Default"), 0o700); err != nil {+ t.Fatal(err)+ }+}++func defaultProfileListing(t *testing.T, pm *profiles.ProfileManager) []map[string]any {+ t.Helper()+ mux := http.NewServeMux()+ pm.RegisterHandlers(mux)+ rec := httptest.NewRecorder()+ mux.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/profiles", nil))+ if rec.Code != http.StatusOK {+ t.Fatalf("GET /profiles = %d: %s", rec.Code, rec.Body.String())+ }+ var listed []map[string]any+ if err := json.Unmarshal(rec.Body.Bytes(), &listed); err != nil {+ t.Fatalf("decode listing: %v", err)+ }+ return listed+}++// /health used to count every non-quarantined profile, temporaries included, while+// GET /profiles hides temporaries by default — so the two disagreed on one word.+// Each profile now lands in exactly one bucket, and the buckets reconcile with the+// list: the default listing keeps quarantined profiles and hides temporaries.+func TestHealthCountsEachProfileInExactlyOneBucketThatReconcilesWithTheListing(t *testing.T) {+ baseDir := t.TempDir()+ profileDir(t, baseDir, "default")+ profileDir(t, baseDir, "work")+ profileDir(t, baseDir, "instance-9868")+ profileDir(t, baseDir, "instance-9869")+ profileDir(t, baseDir, "instance-9870")+ profileDir(t, baseDir, "default.quarantine-1700000001")+ pm := profiles.NewProfileManager(baseDir)++ api := newConfigAPIForTest(config.Load(), nil, pm, nil, nil, "test", time.Now())+ w := httptest.NewRecorder()+ api.HandleHealth(w, httptest.NewRequest(http.MethodGet, "/health", nil))+ if w.Code != http.StatusOK {+ t.Fatalf("status = %d: %s", w.Code, w.Body.String())+ }+ var health healthEnvelope+ if err := json.NewDecoder(w.Body).Decode(&health); err != nil {+ t.Fatalf("decode: %v", err)+ }++ if health.Profiles != 2 || health.TemporaryProfiles != 3 || health.QuarantinedProfiles != 1 {+ t.Errorf("profiles/temporary/quarantined = %d/%d/%d, want 2/3/1", health.Profiles, health.TemporaryProfiles, health.QuarantinedProfiles)+ }+ all, err := pm.List()+ if err != nil {+ t.Fatal(err)+ }+ if health.Profiles+health.TemporaryProfiles+health.QuarantinedProfiles != len(all) {+ t.Errorf("buckets sum to %d, want every one of the %d profiles counted once", health.Profiles+health.TemporaryProfiles+health.QuarantinedProfiles, len(all))+ }++ listed := defaultProfileListing(t, pm)+ if health.Profiles+health.QuarantinedProfiles != len(listed) {+ t.Errorf("profiles+quarantinedProfiles = %d, want the default GET /profiles length %d", health.Profiles+health.QuarantinedProfiles, len(listed))+ }+ for _, entry := range listed {+ if entry["temporary"] == true {+ t.Errorf("the default listing served a temporary profile, so profiles cannot be reconciled against it: %v", entry)+ }+ }+}