High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(bridge): keep an ended session's tab once any other scope has used it, as the docs promise (PIN-368)
Luigi Agostif4be46b3feca
diff --git a/internal/bridge/bridge_types.go b/internal/bridge/bridge_types.goindex 646bf172..f1b6f612 100644--- a/internal/bridge/bridge_types.go+++ b/internal/bridge/bridge_types.go@@ -23,7 +23,7 @@ type TabEntry struct {Watching boolConsoleCaptureEnabled boolCreatorScope string- LastScope string+ UsedByOtherScope bool// Lifecycle auto-close timer. autoCloseGen is bumped on every (re)schedule// so a fire that races with a reset/cancel can detect itself and bail.diff --git a/internal/bridge/tab_scope.go b/internal/bridge/tab_scope.goindex 94b8f421..1f14ebb8 100644--- a/internal/bridge/tab_scope.go+++ b/internal/bridge/tab_scope.go@@ -15,7 +15,9 @@ func (tm *TabManager) RecordTabScope(tabID, scope string, created bool) {if created && entry.CreatorScope == "" {entry.CreatorScope = scope}- entry.LastScope = scope+ if entry.CreatorScope != "" && scope != entry.CreatorScope {+ entry.UsedByOtherScope = true+ }}func (tm *TabManager) TabsOnlyUsedByCreator(scope string) []string {@@ -26,7 +28,7 @@ func (tm *TabManager) TabsOnlyUsedByCreator(scope string) []string {defer tm.mu.RUnlock()var ids []stringfor id, entry := range tm.tabs {- if entry.CreatorScope == scope && entry.LastScope == scope {+ if entry.CreatorScope == scope && !entry.UsedByOtherScope {ids = append(ids, id)}}diff --git a/internal/bridge/tab_scope_test.go b/internal/bridge/tab_scope_test.goindex 67422c0f..a11d5e45 100644--- a/internal/bridge/tab_scope_test.go+++ b/internal/bridge/tab_scope_test.go@@ -13,19 +13,22 @@ func scopedTabManager(ids ...string) *TabManager {return tm}-func TestATabKeepsItsFirstCreatorAndTracksItsLastUser(t *testing.T) {- tm := scopedTabManager("own", "shared", "adopted")+func TestATabKeepsItsFirstCreatorAndStaysSharedOnceAnotherScopeUsesIt(t *testing.T) {+ tm := scopedTabManager("own", "shared", "returned", "recreated")tm.RecordTabScope("own", "session:s", true)+ tm.RecordTabScope("own", "session:s", false)tm.RecordTabScope("shared", "session:s", true)tm.RecordTabScope("shared", "session:t", false)- tm.RecordTabScope("adopted", "session:s", true)- tm.RecordTabScope("adopted", "session:t", true)- tm.RecordTabScope("adopted", "session:s", false)+ tm.RecordTabScope("returned", "session:s", true)+ tm.RecordTabScope("returned", "session:t", false)+ tm.RecordTabScope("returned", "session:s", false)+ tm.RecordTabScope("recreated", "session:s", true)+ tm.RecordTabScope("recreated", "session:t", true)tm.RecordTabScope("missing", "session:s", true)got := tm.TabsOnlyUsedByCreator("session:s")- if len(got) != 2 || got[0] != "adopted" || got[1] != "own" {- t.Fatalf("TabsOnlyUsedByCreator(session:s) = %v, want [adopted own]", got)+ if len(got) != 1 || got[0] != "own" {+ t.Fatalf("TabsOnlyUsedByCreator(session:s) = %v, want [own]: a tab another scope has used stays open even after its creator returns to it", got)}if got := tm.TabsOnlyUsedByCreator("session:t"); len(got) != 0 {t.Fatalf("TabsOnlyUsedByCreator(session:t) = %v, want none: t never created a tab", got)diff --git a/internal/handlers/activity_helpers.go b/internal/handlers/activity_helpers.goindex 130010bc..8416bff6 100644--- a/internal/handlers/activity_helpers.go+++ b/internal/handlers/activity_helpers.go@@ -85,6 +85,8 @@ type tabScopeTracker interface {TabsOnlyUsedByCreator(scope string) []string}+var _ tabScopeTracker = (*bridge.Bridge)(nil)+func (h *Handlers) tabScopes() (tabScopeTracker, bool) {if h == nil {return nil, false