package settings import ( "io" "log" "os" "path/filepath" "testing" ) // R-1199 reopened (2026-10-22): a household that unticks every mail must see an empty list after a restart — the hub // mails by that empty list. Before: omitempty dropped the [] and the getter turned the missing list into the defaults. // Both shapes: a fresh save, and the file Tester 1 and demo-hp actually hold (`{"cooldown_hours": 6}` only). // RED-PROOF: with the getter's nil → DefaultEnabledEvents restored, both assertions fail — seen failing 2026-10-22. func TestR1199Reopened_AnEmptySavedListStaysEmpty(t *testing.T) { p := filepath.Join(t.TempDir(), "s.json") s, _ := Load(p, log.New(io.Discard, "", 0)) if err := s.SetNotificationPrefs(&NotificationPrefs{EnabledEvents: []string{}}); err != nil { t.Fatal(err) } s2, _ := Load(p, log.New(io.Discard, "", 0)) if got := s2.GetNotificationPrefs().EnabledEvents; len(got) != 0 { t.Fatalf("a saved empty list came back as %v", got) } q := filepath.Join(t.TempDir(), "old.json") os.WriteFile(q, []byte(`{"notifications":{"cooldown_hours":6}}`), 0o600) s3, _ := Load(q, log.New(io.Discard, "", 0)) if got := s3.GetNotificationPrefs().EnabledEvents; len(got) != 0 || !s3.NotificationPrefsSaved() { t.Fatalf("the live boxes' file shape reads as %v (saved=%t), want an empty saved list", got, s3.NotificationPrefsSaved()) } // A box with nothing saved still shows the defaults. s4, _ := Load(filepath.Join(t.TempDir(), "n.json"), log.New(io.Discard, "", 0)) if got := s4.GetNotificationPrefs().EnabledEvents; len(got) != len(DefaultEnabledEvents) { t.Fatalf("an unsaved box must show the defaults, got %d", len(got)) } }