From 06450fe69ade2928deb9274bb67b7ba60d394b4f Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Thu, 6 Aug 2026 18:19:27 +0000 Subject: Remove the feature toggle system (dead code) Audited it (couldn't query the live DB directly -- auto-mode classifier blocks direct production reads without prior approval -- so this is a code-only audit): GetFeatureToggles/SetFeatureEnabled/IsFeatureEnabled/ CreateFeatureToggle/DeleteFeatureToggle had exactly one caller each, all inside their own CRUD handlers. Nothing anywhere else in the codebase read a toggle's Enabled state to gate any actual behavior -- confirmed by grepping every remaining .Enabled/IsFeatureEnabled reference back to either this dead code or its own tests. It was pure UI-managed CRUD with no consumer, unlike Trusted Agents (wired into agent.go/websocket.go) or Data Sources (wired into the sync pipeline) which stayed. Removes the Settings page section, the three /settings/features* routes and handlers, the five Store methods, the FeatureToggle model, and adds 028_drop_feature_toggles.sql (next free migration number, per this repo's convention of never renumbering -- see 021_drop_tasks.sql for the same drop-table-forward pattern) to drop the now-unused table. Also removed the now-dead tests for all of the above. go build ./... and go test ./... both clean. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01EZ7ikw2ukGJFTHE3bJS7zL --- internal/handlers/buckets_web_test.go | 1 - internal/handlers/handlers_test.go | 110 ---------------------------------- internal/handlers/settings.go | 54 ----------------- 3 files changed, 165 deletions(-) (limited to 'internal/handlers') diff --git a/internal/handlers/buckets_web_test.go b/internal/handlers/buckets_web_test.go index 9e09ca0..befdc01 100644 --- a/internal/handlers/buckets_web_test.go +++ b/internal/handlers/buckets_web_test.go @@ -169,7 +169,6 @@ func TestHandleSettingsPage_IncludesBucketsProjectsLabels(t *testing.T) { data, ok := lastCall.Data.(struct { Configs map[string][]models.SourceConfig Sources []string - Toggles []models.FeatureToggle SyncLog []store.SyncLogEntry Agents []models.Agent Buckets []models.BucketSummary diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 9d92faa..4c776b0 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -1121,116 +1121,6 @@ func TestHandleUnifiedAdd_MissingContent(t *testing.T) { } } -// ============================================================================= -// Settings Handler Tests -// ============================================================================= - -func TestHandleToggleFeature(t *testing.T) { - db, cleanup := setupTestDB(t) - defer cleanup() - - h := &Handler{ - store: db, - renderer: newTestRenderer(), - config: &config.Config{}, - } - - // Create a feature toggle - _ = db.CreateFeatureToggle("test_feature", "Test feature", false) - - req := httptest.NewRequest("POST", "/settings/feature/toggle", nil) - req.Form = map[string][]string{ - "name": {"test_feature"}, - "enabled": {"true"}, - } - w := httptest.NewRecorder() - - h.HandleToggleFeature(w, req) - - if w.Code != http.StatusOK { - t.Errorf("Expected status 200, got %d", w.Code) - } - - // Verify feature was enabled - if !db.IsFeatureEnabled("test_feature") { - t.Error("Feature should be enabled after toggle") - } -} - -func TestHandleCreateFeature(t *testing.T) { - db, cleanup := setupTestDB(t) - defer cleanup() - - h := &Handler{ - store: db, - renderer: newTestRenderer(), - config: &config.Config{}, - } - - req := httptest.NewRequest("POST", "/settings/feature/create", nil) - req.Form = map[string][]string{ - "name": {"new_feature"}, - "description": {"A new feature"}, - } - w := httptest.NewRecorder() - - h.HandleCreateFeature(w, req) - - if w.Code != http.StatusOK { - t.Errorf("Expected status 200, got %d", w.Code) - } - - // Verify feature was created - toggles, _ := db.GetFeatureToggles() - found := false - for _, t := range toggles { - if t.Name == "new_feature" { - found = true - break - } - } - if !found { - t.Error("Feature should be created") - } -} - -func TestHandleDeleteFeature(t *testing.T) { - db, cleanup := setupTestDB(t) - defer cleanup() - - h := &Handler{ - store: db, - renderer: newTestRenderer(), - config: &config.Config{}, - } - - // Create a feature to delete - _ = db.CreateFeatureToggle("delete_me", "To be deleted", false) - - req := httptest.NewRequest("DELETE", "/settings/feature/delete_me", nil) - - // Add chi URL params - rctx := chi.NewRouteContext() - rctx.URLParams.Add("name", "delete_me") - req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx)) - - w := httptest.NewRecorder() - - h.HandleDeleteFeature(w, req) - - if w.Code != http.StatusOK { - t.Errorf("Expected status 200, got %d", w.Code) - } - - // Verify feature was deleted - toggles, _ := db.GetFeatureToggles() - for _, toggle := range toggles { - if toggle.Name == "delete_me" { - t.Error("Feature should be deleted") - } - } -} - // ============================================================================= // Response Helper Tests // ============================================================================= diff --git a/internal/handlers/settings.go b/internal/handlers/settings.go index 43fce20..5ba3724 100644 --- a/internal/handlers/settings.go +++ b/internal/handlers/settings.go @@ -4,8 +4,6 @@ import ( "encoding/json" "net/http" - "github.com/go-chi/chi/v5" - "task-dashboard/internal/auth" "task-dashboard/internal/models" "task-dashboard/internal/store" @@ -14,7 +12,6 @@ import ( // HandleSettingsPage renders the settings page func (h *Handler) HandleSettingsPage(w http.ResponseWriter, r *http.Request) { configs, _ := h.store.GetSourceConfigs() - toggles, _ := h.store.GetFeatureToggles() syncLog, _ := h.store.GetRecentSyncLog(20) agents, _ := h.store.GetAllAgents() buckets, _ := BuildBucketSummaries(h.store) @@ -30,7 +27,6 @@ func (h *Handler) HandleSettingsPage(w http.ResponseWriter, r *http.Request) { data := struct { Configs map[string][]models.SourceConfig Sources []string - Toggles []models.FeatureToggle SyncLog []store.SyncLogEntry Agents []models.Agent Buckets []models.BucketSummary @@ -41,7 +37,6 @@ func (h *Handler) HandleSettingsPage(w http.ResponseWriter, r *http.Request) { }{ Configs: bySource, Sources: []string{"trello", "gcal", "gtasks"}, - Toggles: toggles, SyncLog: syncLog, Agents: agents, Buckets: buckets, @@ -163,52 +158,3 @@ func (h *Handler) HandleToggleSourceConfig(w http.ResponseWriter, r *http.Reques json.NewEncoder(w).Encode(map[string]bool{"enabled": enabled}) } -// HandleToggleFeature toggles a feature flag -func (h *Handler) HandleToggleFeature(w http.ResponseWriter, r *http.Request) { - name, ok := requireFormValue(w, r, "name") - if !ok { - return - } - enabled := r.FormValue("enabled") == "true" - - if err := h.store.SetFeatureEnabled(name, enabled); err != nil { - JSONError(w, http.StatusInternalServerError, "Failed to update feature", err) - return - } - - w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(map[string]bool{"enabled": enabled}) -} - -// HandleCreateFeature creates a new feature toggle -func (h *Handler) HandleCreateFeature(w http.ResponseWriter, r *http.Request) { - name, ok := requireFormValue(w, r, "name") - if !ok { - return - } - description := r.FormValue("description") - - if err := h.store.CreateFeatureToggle(name, description, false); err != nil { - JSONError(w, http.StatusInternalServerError, "Failed to create feature", err) - return - } - - // Return updated toggles list - h.HandleSettingsPage(w, r) -} - -// HandleDeleteFeature removes a feature toggle -func (h *Handler) HandleDeleteFeature(w http.ResponseWriter, r *http.Request) { - name := chi.URLParam(r, "name") - if name == "" { - JSONError(w, http.StatusBadRequest, "Feature name required", nil) - return - } - - if err := h.store.DeleteFeatureToggle(name); err != nil { - JSONError(w, http.StatusInternalServerError, "Failed to delete feature", err) - return - } - - w.WriteHeader(http.StatusOK) -} -- cgit v1.2.3