High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
refactor: add ProfileService and OrchestratorService interfaces
Mario1bd561b42efb
diff --git a/TODO.md b/TODO.mdindex 8206dcbf..cb5caf94 100644--- a/TODO.md+++ b/TODO.md@@ -37,7 +37,7 @@ P2 (K11 file path, blockImages on CreateTab) — all resolved.### Code Quality- [ ] **Extract TabManager from Bridge** — Bridge is a semi-god object. Split tabs + snapshots management into its own `TabManager` struct.- [ ] **installStableBinary streaming** — Use `io.Copy` with file streams instead of reading entire binary into memory.-- [ ] **Interfaces for ProfileManager/Orchestrator** — Add interfaces for unit testability (like `BridgeAPI`).+- [x] **Interfaces for ProfileManager/Orchestrator** — `ProfileService` and `OrchestratorService` interfaces with compile-time checks.- [ ] **proxy_ws.go proper HTTP** — Replace raw `backend.Write` of HTTP headers with proper request construction.- [x] **Dashboard SSE keepalive** — 30s keepalive comments on SSE connections.diff --git a/cmd_dashboard.go b/cmd_dashboard.goindex c21af632..16539978 100644--- a/cmd_dashboard.go+++ b/cmd_dashboard.go@@ -65,7 +65,7 @@ func runDashboard() {profileObserver := func(evt AgentEvent) {if evt.Profile != "" {- profMgr.tracker.Record(evt.Profile, ActionRecord{+ profMgr.RecordAction(evt.Profile, ActionRecord{Timestamp: evt.Timestamp,Method: strings.SplitN(evt.Action, " ", 2)[0],Endpoint: strings.SplitN(evt.Action, " ", 2)[1],diff --git a/interfaces.go b/interfaces.goindex 667699d0..053c8a14 100644--- a/interfaces.go+++ b/interfaces.go@@ -2,10 +2,18 @@ package mainimport ("context"+ "net/http""github.com/chromedp/cdproto/target")+// Compile-time interface satisfaction checks.+var (+ _ ProfileService = (*ProfileManager)(nil)+ _ OrchestratorService = (*Orchestrator)(nil)+)++// BridgeAPI abstracts browser tab operations for handler testing.type BridgeAPI interface {TabContext(tabID string) (ctx context.Context, resolvedID string, err error)ListTargets() ([]*target.Info, error)@@ -17,9 +25,38 @@ type BridgeAPI interface {DeleteRefCache(tabID string)}+// TabInfo describes a browser tab.type TabInfo struct {ID string `json:"id"`URL string `json:"url"`Title string `json:"title"`Type string `json:"type"`}++// ProfileService abstracts profile management operations.+type ProfileService interface {+ RegisterHandlers(mux *http.ServeMux)+ List() ([]ProfileInfo, error)+ Create(name string) error+ Import(name, sourcePath string) error+ Reset(name string) error+ Delete(name string) error+ Logs(name string, limit int) []ActionRecord+ Analytics(name string) AnalyticsReport+ RecordAction(profile string, record ActionRecord)+}++// OrchestratorService abstracts instance orchestration operations.+type OrchestratorService interface {+ RegisterHandlers(mux *http.ServeMux)+ Launch(name, port string, headless bool) (*Instance, error)+ Stop(id string) error+ StopProfile(name string) error+ List() []Instance+ Logs(id string) (string, error)+ FirstRunningURL() string+ AllTabs() []instanceTab+ ScreencastURL(instanceID, tabID string) string+ Shutdown()+ ForceShutdown()+}diff --git a/main.go b/main.goindex d0e00f39..d306bdef 100644--- a/main.go+++ b/main.go@@ -129,7 +129,7 @@ func main() {profileObserver := func(evt AgentEvent) {if evt.Profile != "" {- profMgr.tracker.Record(evt.Profile, ActionRecord{+ profMgr.RecordAction(evt.Profile, ActionRecord{Timestamp: evt.Timestamp,Method: strings.SplitN(evt.Action, " ", 2)[0],Endpoint: strings.SplitN(evt.Action, " ", 2)[1],@@ -328,7 +328,7 @@ func applyTimezone(browserCtx context.Context) {}// registerRoutes wires all HTTP handlers to the mux.-func registerRoutes(mux *http.ServeMux, b *Bridge, profMgr *ProfileManager, dashboard *Dashboard, orchestrator *Orchestrator) {+func registerRoutes(mux *http.ServeMux, b *Bridge, profMgr ProfileService, dashboard *Dashboard, orchestrator OrchestratorService) {mux.HandleFunc("GET /health", b.handleHealth)mux.HandleFunc("GET /tabs", b.handleTabs)mux.HandleFunc("GET /snapshot", b.handleSnapshot)diff --git a/profiles_manager.go b/profiles_manager.goindex 8c1681a3..a0391957 100644--- a/profiles_manager.go+++ b/profiles_manager.go@@ -187,6 +187,11 @@ func (pm *ProfileManager) Delete(name string) error {return os.RemoveAll(dir)}+// RecordAction records an action for a profile (implements ProfileService).+func (pm *ProfileManager) RecordAction(profile string, record ActionRecord) {+ pm.tracker.Record(profile, record)+}+func (pm *ProfileManager) Logs(name string, limit int) []ActionRecord {return pm.tracker.GetLogs(name, limit)}