package settings import ( "io" "log" "os" "path/filepath" "testing" ) // v0.264.0 — the one-time, ADD-ONLY seed of the two update event types into a household's stored prefs. // // COMPANION RED-PROOF (REPORT.md): drop the seedAppUpdateEvents call from Load — the first assertion fails. func TestSeedAppUpdateEvents_AddOnlyOnce(t *testing.T) { p := filepath.Join(t.TempDir(), "settings.json") if err := os.WriteFile(p, []byte(`{"notifications":{"email":"h@example.hu","enabled_events":["backup_failed"]}}`), 0o600); err != nil { t.Fatal(err) } lg := log.New(io.Discard, "", 0) s, err := Load(p, lg) if err != nil { t.Fatal(err) } ev := s.Notifications.EnabledEvents has := func(list []string, x string) bool { for _, e := range list { if e == x { return true } } return false } if !has(ev, "backup_failed") || !has(ev, "app_update_undone") || !has(ev, "app_update_held") { t.Fatalf("the household's choice must be kept and both types added, got %v", ev) } // The household opts out of one; a restart must NOT add it back. s.Notifications.EnabledEvents = []string{"backup_failed", "app_update_held"} if err := s.save(); err != nil { t.Fatal(err) } s2, err := Load(p, lg) if err != nil { t.Fatal(err) } if has(s2.Notifications.EnabledEvents, "app_update_undone") { t.Errorf("a later opt-out must stick — the seed runs once, got %v", s2.Notifications.EnabledEvents) } }