High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat: surface quarantined profiles and their total size where operators already look PIN-041
Luigi Agosti0e614352debb
diff --git a/dashboard/src/generated/types.ts b/dashboard/src/generated/types.tsindex 795927df..febb96b3 100644--- a/dashboard/src/generated/types.ts+++ b/dashboard/src/generated/types.ts@@ -21,6 +21,7 @@ export interface Profile {sizeMB?: number /* float64 */;running: boolean;temporary?: boolean;+ quarantined?: boolean;source?: string;chromeProfileName?: string;accountEmail?: string;diff --git a/internal/api/types/types.go b/internal/api/types/types.goindex bd536a6d..14ac8155 100644--- a/internal/api/types/types.go+++ b/internal/api/types/types.go@@ -18,6 +18,7 @@ type Profile struct {SizeMB float64 `json:"sizeMB,omitempty"`Running bool `json:"running"`Temporary bool `json:"temporary,omitempty"`+ Quarantined bool `json:"quarantined,omitempty"`Source string `json:"source,omitempty"`ChromeProfileName string `json:"chromeProfileName,omitempty"`AccountEmail string `json:"accountEmail,omitempty"`diff --git a/internal/bridge/api.go b/internal/bridge/api.goindex 6691d3b2..c08d5f8c 100644--- a/internal/bridge/api.go+++ b/internal/bridge/api.go@@ -256,7 +256,8 @@ type ProfileInfo struct {LastUsed time.Time `json:"lastUsed"`DiskUsage int64 `json:"diskUsage"`Running bool `json:"running"`- Temporary bool `json:"temporary,omitempty"` // ephemeral instance profiles (auto-generated)+ Temporary bool `json:"temporary,omitempty"` // ephemeral instance profiles (auto-generated)+ Quarantined bool `json:"quarantined,omitempty"` // corrupted profiles renamed aside by quarantineSource string `json:"source,omitempty"`ChromeProfileName string `json:"chromeProfileName,omitempty"`AccountEmail string `json:"accountEmail,omitempty"`diff --git a/internal/bridge/profile_lock.go b/internal/bridge/profile_lock.goindex a3cb8c1c..b8439de1 100644--- a/internal/bridge/profile_lock.go+++ b/internal/bridge/profile_lock.go@@ -125,6 +125,17 @@ func clearStaleProfileLocks(profileDir, errMsg string) (bool, error) {// to release the profile before renaming. Var so tests can shrink it.var quarantineExitWait = 5 * time.Second+const quarantineSuffix = ".quarantine-"++var quarantineDirName = regexp.MustCompile(regexp.QuoteMeta(quarantineSuffix) + `\d+$`)++// IsQuarantinedProfileDir reports whether a directory name is one quarantine+// produced. Only the "<name>.quarantine-<unix>" suffix decides, so a profile a+// user named after the word stays an ordinary profile.+func IsQuarantinedProfileDir(dirName string) bool {+ return quarantineDirName.MatchString(dirName)+}+// quarantineCorruptedProfile renames profileDir to "<profileDir>.quarantine-<ts>"// and recreates an empty directory at the original path. Used to recover// from silent CDP attach failures where CloakBrowser refuses to ingest@@ -147,7 +158,7 @@ func quarantineCorruptedProfile(profileDir string) (string, error) {if !waitForChromeExit(profileDir, quarantineExitWait) {slog.Warn("quarantining profile while a browser process may still hold it", "profile", profileDir)}- quarantinePath := fmt.Sprintf("%s.quarantine-%d", profileDir, time.Now().Unix())+ quarantinePath := fmt.Sprintf("%s%s%d", profileDir, quarantineSuffix, time.Now().Unix())if err := os.Rename(profileDir, quarantinePath); err != nil {return "", fmt.Errorf("rename profile dir: %w", err)}diff --git a/internal/bridge/profile_lock_test.go b/internal/bridge/profile_lock_test.goindex ae900c15..870133bc 100644--- a/internal/bridge/profile_lock_test.go+++ b/internal/bridge/profile_lock_test.go@@ -441,3 +441,39 @@ func TestQuarantineWithoutMetadataStillSucceeds(t *testing.T) {t.Fatalf("quarantined directory incomplete: %v", err)}}++func TestIsQuarantinedProfileDirMatchesOnlyTheSuffix(t *testing.T) {+ tests := map[string]bool{+ "default.quarantine-1785343990": true,+ "work.quarantine-0": true,+ "quarantine-notes": false,+ "my-quarantine": false,+ "default.quarantine-": false,+ "default.quarantine-abc": false,+ "default.quarantine-123.backup": false,+ "default": false,+ }+ for name, want := range tests {+ if got := IsQuarantinedProfileDir(name); got != want {+ t.Errorf("IsQuarantinedProfileDir(%q) = %v, want %v", name, got, want)+ }+ }+}++func TestQuarantineCorruptedProfileProducesAFlaggedName(t *testing.T) {+ profileDir := filepath.Join(t.TempDir(), "default")+ if err := os.MkdirAll(profileDir, 0o755); err != nil {+ t.Fatal(err)+ }++ quarantinePath, err := quarantineCorruptedProfile(profileDir)+ if err != nil {+ t.Fatalf("quarantineCorruptedProfile: %v", err)+ }+ if !IsQuarantinedProfileDir(filepath.Base(quarantinePath)) {+ t.Fatalf("quarantine produced %q, which the listing would not flag", quarantinePath)+ }+ if IsQuarantinedProfileDir(filepath.Base(profileDir)) {+ t.Fatalf("the recreated profile dir %q must not be flagged", profileDir)+ }+}diff --git a/internal/cli/actions/actions_system.go b/internal/cli/actions/actions_system.goindex e060eee5..47b05a6e 100644--- a/internal/cli/actions/actions_system.go+++ b/internal/cli/actions/actions_system.go@@ -7,6 +7,7 @@ import ("log""net/http""os"+ "strings""github.com/pinchtab/pinchtab/internal/cli""github.com/pinchtab/pinchtab/internal/cli/apiclient"@@ -107,16 +108,51 @@ func Profiles(client *http.Client, base, token string, cmd *cobra.Command) {os.Exit(1)}+ fmt.Print(formatProfileList(profiles))+}++// formatProfileList lists user profiles first, then the quarantined+// directories under a heading carrying their count and combined size, so an+// operator sees what quarantine is holding without inferring it from names.+func formatProfileList(profiles []map[string]any) string {if len(profiles) == 0 {- fmt.Println("No profiles available")- return+ return "No profiles available\n"}+ var live, quarantined strings.Builder+ quarantinedCount := 0+ quarantinedBytes := int64(0)for _, prof := range profiles {id, _ := prof["id"].(string)name, _ := prof["name"].(string)- fmt.Printf("%s\t%s\n", id, name)+ size, _ := prof["diskUsage"].(float64)+ if isQuarantined, _ := prof["quarantined"].(bool); isQuarantined {+ quarantinedCount+++ quarantinedBytes += int64(size)+ fmt.Fprintf(&quarantined, "%s\t%s\t%s\n", id, name, formatBytes(int64(size)))+ continue+ }+ fmt.Fprintf(&live, "%s\t%s\n", id, name)+ }++ out := live.String()+ if quarantinedCount > 0 {+ out += fmt.Sprintf("\nQuarantined (%d, %s total):\n%s", quarantinedCount, formatBytes(quarantinedBytes), quarantined.String())+ }+ return out+}++func formatBytes(n int64) string {+ const unit = 1024+ if n < unit {+ return fmt.Sprintf("%d B", n)+ }+ div, exp := int64(unit), 0+ for rest := n / unit; rest >= unit; rest /= unit {+ div *= unit+ exp++}+ return fmt.Sprintf("%.1f %cB", float64(n)/float64(div), "KMGTPE"[exp])}func decodeProfilesResponse(body []byte) ([]map[string]any, error) {diff --git a/internal/cli/actions/actions_system_test.go b/internal/cli/actions/actions_system_test.goindex 9bd3854f..53ea0192 100644--- a/internal/cli/actions/actions_system_test.go+++ b/internal/cli/actions/actions_system_test.go@@ -77,3 +77,34 @@ func TestGetInstances_EnvelopeResponseRejected(t *testing.T) {t.Fatalf("instances = %#v, want nil for legacy envelope response", instances)}}++func TestFormatProfileListSeparatesQuarantinedAndTotalsTheirSize(t *testing.T) {+ out := formatProfileList([]map[string]any{+ {"id": "p1", "name": "work", "diskUsage": float64(500 << 20)},+ {"id": "p2", "name": "quarantine-notes", "diskUsage": float64(1 << 20)},+ {"id": "p3", "name": "work.quarantine-1785343990", "diskUsage": float64(1 << 30), "quarantined": true},+ {"id": "p4", "name": "personal.quarantine-1785343991", "diskUsage": float64(1 << 29), "quarantined": true},+ })++ want := "p1\twork\n" ++ "p2\tquarantine-notes\n" ++ "\nQuarantined (2, 1.5 GB total):\n" ++ "p3\twork.quarantine-1785343990\t1.0 GB\n" ++ "p4\tpersonal.quarantine-1785343991\t512.0 MB\n"+ if out != want {+ t.Fatalf("formatProfileList() =\n%q\nwant\n%q", out, want)+ }+}++func TestFormatProfileListWithoutQuarantineHasNoSection(t *testing.T) {+ out := formatProfileList([]map[string]any{{"id": "p1", "name": "work", "diskUsage": float64(1 << 20)}})+ if out != "p1\twork\n" {+ t.Fatalf("formatProfileList() = %q, want a plain listing", out)+ }+}++func TestFormatProfileListEmpty(t *testing.T) {+ if out := formatProfileList(nil); out != "No profiles available\n" {+ t.Fatalf("formatProfileList(nil) = %q", out)+ }+}diff --git a/internal/dashboard/config_api_test.go b/internal/dashboard/config_api_test.goindex 5086af36..b866d503 100644--- a/internal/dashboard/config_api_test.go+++ b/internal/dashboard/config_api_test.go@@ -17,6 +17,7 @@ import (_ "github.com/pinchtab/pinchtab/internal/browsers/all""github.com/pinchtab/pinchtab/internal/authn"+ "github.com/pinchtab/pinchtab/internal/bridge""github.com/pinchtab/pinchtab/internal/browsersession""github.com/pinchtab/pinchtab/internal/config")@@ -719,3 +720,38 @@ func isZeroValue(v reflect.Value) bool {}return v.IsZero()}++type stubProfileLister struct {+ profiles []bridge.ProfileInfo+}++func (s stubProfileLister) List() ([]bridge.ProfileInfo, error) { return s.profiles, nil }++func TestHandleHealthCountsQuarantinedProfilesSeparately(t *testing.T) {+ fc := config.DefaultFileConfig()+ api := newConfigAPITestAPI(t, fc)+ api.profiles = stubProfileLister{profiles: []bridge.ProfileInfo{+ {Name: "work"},+ {Name: "quarantine-notes"},+ {Name: "work.quarantine-1785343990", Quarantined: true},+ {Name: "personal.quarantine-1785343991", Quarantined: true},+ }}++ req := httptest.NewRequest(http.MethodGet, "/health", nil)+ w := httptest.NewRecorder()+ api.HandleHealth(w, req)++ if w.Code != http.StatusOK {+ t.Fatalf("HandleHealth() status = %d, want %d", w.Code, http.StatusOK)+ }+ var health healthEnvelope+ if err := json.NewDecoder(w.Body).Decode(&health); err != nil {+ t.Fatalf("Decode() error = %v", err)+ }+ if health.Profiles != 2 {+ t.Errorf("health profiles = %d, want 2 live profiles", health.Profiles)+ }+ if health.QuarantinedProfiles != 2 {+ t.Errorf("health quarantinedProfiles = %d, want 2", health.QuarantinedProfiles)+ }+}diff --git a/internal/dashboard/config_health.go b/internal/dashboard/config_health.goindex 5cdae4e4..d16d1dfa 100644--- a/internal/dashboard/config_health.go+++ b/internal/dashboard/config_health.go@@ -25,18 +25,19 @@ type healthSecurityInfo struct {}type healthEnvelope struct {- Status string `json:"status"`- Mode string `json:"mode"`- Version string `json:"version"`- Uptime int64 `json:"uptime"`- AuthRequired bool `json:"authRequired"`- Profiles int `json:"profiles"`- Instances int `json:"instances"`- DefaultInstance *healthInstanceInfo `json:"defaultInstance,omitempty"`- Agents int `json:"agents"`- RestartRequired bool `json:"restartRequired"`- RestartReasons []string `json:"restartReasons,omitempty"`- Security *healthSecurityInfo `json:"security,omitempty"`+ Status string `json:"status"`+ Mode string `json:"mode"`+ Version string `json:"version"`+ Uptime int64 `json:"uptime"`+ AuthRequired bool `json:"authRequired"`+ Profiles int `json:"profiles"`+ QuarantinedProfiles int `json:"quarantinedProfiles"`+ Instances int `json:"instances"`+ DefaultInstance *healthInstanceInfo `json:"defaultInstance,omitempty"`+ Agents int `json:"agents"`+ RestartRequired bool `json:"restartRequired"`+ RestartReasons []string `json:"restartReasons,omitempty"`+ Security *healthSecurityInfo `json:"security,omitempty"`}func (c *ConfigAPI) healthInfo(includeSecurity bool) (healthEnvelope, error) {@@ -45,11 +46,17 @@ func (c *ConfigAPI) healthInfo(includeSecurity bool) (healthEnvelope, error) {return healthEnvelope{}, err}- profileCount := 0+ profileCount, quarantinedCount := 0, 0if c.profiles != nil {profiles, err := c.profiles.List()if err == nil {- profileCount = len(profiles)+ for _, p := range profiles {+ if p.Quarantined {+ quarantinedCount+++ continue+ }+ profileCount+++ }}}@@ -70,17 +77,18 @@ func (c *ConfigAPI) healthInfo(includeSecurity bool) (healthEnvelope, error) {agentCount = c.agents.AgentCount()}out := healthEnvelope{- Status: "ok",- Mode: "dashboard",- Version: c.version,- Uptime: int64(time.Since(c.startedAt).Milliseconds()),- AuthRequired: strings.TrimSpace(c.runtime.Token) != "",- Profiles: profileCount,- Instances: instanceCount,- DefaultInstance: defaultInst,- Agents: agentCount,- RestartRequired: len(restartReasons) > 0,- RestartReasons: restartReasons,+ Status: "ok",+ Mode: "dashboard",+ Version: c.version,+ Uptime: int64(time.Since(c.startedAt).Milliseconds()),+ AuthRequired: strings.TrimSpace(c.runtime.Token) != "",+ Profiles: profileCount,+ QuarantinedProfiles: quarantinedCount,+ Instances: instanceCount,+ DefaultInstance: defaultInst,+ Agents: agentCount,+ RestartRequired: len(restartReasons) > 0,+ RestartReasons: restartReasons,}if includeSecurity {security := runtimeSecurityInfo(c.runtime)diff --git a/internal/profiles/handlers.go b/internal/profiles/handlers.goindex af172bda..7e83e6f3 100644--- a/internal/profiles/handlers.go+++ b/internal/profiles/handlers.go@@ -22,6 +22,7 @@ type profileResponse struct {DiskUsage int64 `json:"diskUsage"`SizeMB float64 `json:"sizeMB"`Running bool `json:"running"`+ Quarantined bool `json:"quarantined"`Source string `json:"source"`ChromeProfileName string `json:"chromeProfileName"`AccountEmail string `json:"accountEmail"`@@ -42,6 +43,7 @@ func newProfileResponse(p bridge.ProfileInfo) profileResponse {DiskUsage: p.DiskUsage,SizeMB: float64(p.DiskUsage) / (1024 * 1024),Running: p.Running,+ Quarantined: p.Quarantined,Source: p.Source,ChromeProfileName: p.ChromeProfileName,AccountEmail: p.AccountEmail,diff --git a/internal/profiles/profiles.go b/internal/profiles/profiles.goindex 72f8caba..c09d7a86 100644--- a/internal/profiles/profiles.go+++ b/internal/profiles/profiles.go@@ -122,8 +122,6 @@ func (pm *ProfileManager) List() ([]bridge.ProfileInfo, error) {continue}- isTemporary := strings.HasPrefix(info.Name, "instance-")-pathExists := trueif _, err := os.Stat(info.Path); err != nil {pathExists = false@@ -135,7 +133,8 @@ func (pm *ProfileManager) List() ([]bridge.ProfileInfo, error) {Path: info.Path,PathExists: pathExists,Created: info.CreatedAt,- Temporary: isTemporary,+ Temporary: strings.HasPrefix(info.Name, "instance-"),+ Quarantined: bridge.IsQuarantinedProfileDir(entry.Name()),DiskUsage: int64(info.SizeMB * 1024 * 1024),Source: info.Source,ChromeProfileName: info.ChromeProfileName,diff --git a/internal/profiles/profiles_test.go b/internal/profiles/profiles_test.goindex 4b21ad0c..b028daa7 100644--- a/internal/profiles/profiles_test.go+++ b/internal/profiles/profiles_test.go@@ -1250,3 +1250,100 @@ func TestProfileRenameRollsBackMetadataWhenTheDirectoryRenameFails(t *testing.T)t.Fatalf("listing after a failed rename: name=%q id=%q", got.Name, got.ID)}}++func TestProfileManagerListFlagsQuarantinedDirectories(t *testing.T) {+ dir := t.TempDir()+ pm := NewProfileManager(dir)++ if err := pm.Create("work"); err != nil {+ t.Fatal(err)+ }+ if err := os.MkdirAll(filepath.Join(dir, "quarantine-notes", "Default"), 0o755); err != nil {+ t.Fatal(err)+ }++ quarantineSizes := map[string]int{+ profileID("work") + ".quarantine-1785343990": 1 << 20,+ "quarantine-notes.quarantine-1785343991": 2 << 20,+ }+ for name, size := range quarantineSizes {+ defaultDir := filepath.Join(dir, name, "Default")+ if err := os.MkdirAll(defaultDir, 0o755); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(filepath.Join(defaultDir, "History"), make([]byte, size), 0o644); err != nil {+ t.Fatal(err)+ }+ }++ profiles, err := pm.List()+ if err != nil {+ t.Fatal(err)+ }+ if len(profiles) != 4 {+ t.Fatalf("expected 4 entries (2 live + 2 quarantined), got %d", len(profiles))+ }++ live, quarantined := 0, 0+ var quarantinedTotal int64+ for _, p := range profiles {+ if !p.Quarantined {+ live+++ continue+ }+ quarantined+++ quarantinedTotal += p.DiskUsage+ if _, ok := quarantineSizes[filepath.Base(p.Path)]; !ok {+ t.Errorf("flagged %q as quarantined, but it is not a quarantine directory", p.Path)+ }+ }+ if live != 2 || quarantined != 2 {+ t.Fatalf("expected 2 live and 2 quarantined, got %d and %d", live, quarantined)+ }+ if quarantinedTotal < 3<<20 {+ t.Errorf("quarantined disk usage totals %d bytes, want at least %d", quarantinedTotal, 3<<20)+ }+ for _, p := range profiles {+ if p.Name == "quarantine-notes" && p.Quarantined {+ t.Errorf("a profile merely named %q must not be flagged as quarantined", p.Name)+ }+ }+}++func TestHandleListMarksQuarantinedEntries(t *testing.T) {+ dir := t.TempDir()+ pm := NewProfileManager(dir)++ if err := pm.Create("quarantine-notes"); err != nil {+ t.Fatal(err)+ }+ quarantineDir := filepath.Join(dir, profileID("quarantine-notes")+".quarantine-1785343990", "Default")+ if err := os.MkdirAll(quarantineDir, 0o755); err != nil {+ t.Fatal(err)+ }++ mux := http.NewServeMux()+ pm.RegisterHandlers(mux)+ w := httptest.NewRecorder()+ mux.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "/profiles", nil))++ if w.Code != http.StatusOK {+ t.Fatalf("GET /profiles = %d", w.Code)+ }+ var listed []struct {+ Name string `json:"name"`+ Quarantined bool `json:"quarantined"`+ }+ if err := json.Unmarshal(w.Body.Bytes(), &listed); err != nil {+ t.Fatalf("decode /profiles: %v (%s)", err, w.Body.String())+ }+ if len(listed) != 2 {+ t.Fatalf("expected 2 entries, got %d: %s", len(listed), w.Body.String())+ }+ for _, entry := range listed {+ want := strings.HasSuffix(entry.Name, ".quarantine-1785343990")+ if entry.Quarantined != want {+ t.Errorf("entry %q quarantined = %v, want %v", entry.Name, entry.Quarantined, want)+ }+ }+}