Stabilize settings persistence tests

This commit is contained in:
Joe Julian
2026-04-01 18:01:42 -07:00
parent ea1cf43cbf
commit 6cfb5ea567
+50 -28
View File
@@ -3524,13 +3524,15 @@ func TestUIGroupToolsDisclosureStatePersists(t *testing.T) {
configPath := filepath.Join(t.TempDir(), "ui-prefs.json") configPath := filepath.Join(t.TempDir(), "ui-prefs.json")
first := newUIWithSession("desktop", &session.Manager{}) first := newUIWithSession("desktop", &session.Manager{}, statePaths{
first.uiPreferencesPath = configPath UIPreferencesPath: configPath,
})
first.groupControlsHidden = true first.groupControlsHidden = true
first.saveUIPreferences() first.saveUIPreferences()
second := newUIWithSession("desktop", &session.Manager{}) second := newUIWithSession("desktop", &session.Manager{}, statePaths{
second.uiPreferencesPath = configPath UIPreferencesPath: configPath,
})
second.groupControlsHidden = false second.groupControlsHidden = false
second.loadUIPreferences() second.loadUIPreferences()
@@ -3544,13 +3546,15 @@ func TestUIDenseLayoutPreferencePersists(t *testing.T) {
configPath := filepath.Join(t.TempDir(), "ui-prefs.json") configPath := filepath.Join(t.TempDir(), "ui-prefs.json")
first := newUIWithSession("desktop", &session.Manager{}) first := newUIWithSession("desktop", &session.Manager{}, statePaths{
first.uiPreferencesPath = configPath UIPreferencesPath: configPath,
})
first.denseLayout = true first.denseLayout = true
first.saveUIPreferences() first.saveUIPreferences()
second := newUIWithSession("desktop", &session.Manager{}) second := newUIWithSession("desktop", &session.Manager{}, statePaths{
second.uiPreferencesPath = configPath UIPreferencesPath: configPath,
})
second.denseLayout = false second.denseLayout = false
second.loadUIPreferences() second.loadUIPreferences()
@@ -3564,14 +3568,16 @@ func TestUISyncDefaultsPersistInSettings(t *testing.T) {
configPath := filepath.Join(t.TempDir(), "settings.json") configPath := filepath.Join(t.TempDir(), "settings.json")
first := newUIWithSession("desktop", &session.Manager{}) first := newUIWithSession("desktop", &session.Manager{}, statePaths{
first.settingsPath = configPath SettingsPath: configPath,
})
first.syncDefaultSourceMode = syncSourceRemote first.syncDefaultSourceMode = syncSourceRemote
first.syncDefaultDirection = syncDirectionPush first.syncDefaultDirection = syncDirectionPush
first.saveSettings() first.saveSettings()
second := newUIWithSession("desktop", &session.Manager{}) second := newUIWithSession("desktop", &session.Manager{}, statePaths{
second.settingsPath = configPath SettingsPath: configPath,
})
second.syncDefaultSourceMode = syncSourceLocal second.syncDefaultSourceMode = syncSourceLocal
second.syncDefaultDirection = syncDirectionPull second.syncDefaultDirection = syncDirectionPull
second.loadSettings() second.loadSettings()
@@ -3600,9 +3606,10 @@ func TestUILoadSettingsFallsBackToLegacySyncDefaultsInUIPreferences(t *testing.T
t.Fatalf("os.WriteFile() error = %v", err) t.Fatalf("os.WriteFile() error = %v", err)
} }
reloaded := newUIWithSession("desktop", &session.Manager{}) reloaded := newUIWithSession("desktop", &session.Manager{}, statePaths{
reloaded.uiPreferencesPath = legacyPath SettingsPath: filepath.Join(dir, "settings.json"),
reloaded.settingsPath = filepath.Join(dir, "settings.json") UIPreferencesPath: legacyPath,
})
reloaded.syncDefaultSourceMode = syncSourceLocal reloaded.syncDefaultSourceMode = syncSourceLocal
reloaded.syncDefaultDirection = syncDirectionPull reloaded.syncDefaultDirection = syncDirectionPull
reloaded.loadSettings() reloaded.loadSettings()
@@ -3642,7 +3649,12 @@ func TestUISaveSecuritySettingsPersistsSyncDefaults(t *testing.T) {
t.Parallel() t.Parallel()
manager := &session.Manager{} manager := &session.Manager{}
u := newUIWithSession("desktop", manager) dir := t.TempDir()
u := newUIWithSession("desktop", manager, statePaths{
DefaultSaveAsPath: filepath.Join(dir, "vault.kdbx"),
SettingsPath: filepath.Join(dir, "settings.json"),
UIPreferencesPath: filepath.Join(dir, "ui-prefs.json"),
})
u.masterPassword.SetText("correct horse battery staple") u.masterPassword.SetText("correct horse battery staple")
if err := u.createVaultAction(); err != nil { if err := u.createVaultAction(); err != nil {
t.Fatalf("createVaultAction() error = %v", err) t.Fatalf("createVaultAction() error = %v", err)
@@ -3652,15 +3664,14 @@ func TestUISaveSecuritySettingsPersistsSyncDefaults(t *testing.T) {
u.loadSettingsDraft() u.loadSettingsDraft()
u.settingsDraft.Sync.SourceDefault = syncSourceRemote u.settingsDraft.Sync.SourceDefault = syncSourceRemote
u.settingsDraft.Sync.DirectionDefault = syncDirectionPush u.settingsDraft.Sync.DirectionDefault = syncDirectionPush
u.settingsPath = filepath.Join(t.TempDir(), "settings.json")
u.uiPreferencesPath = filepath.Join(t.TempDir(), "ui-prefs.json")
if err := u.saveSecuritySettingsAction(); err != nil { if err := u.saveSecuritySettingsAction(); err != nil {
t.Fatalf("saveSecuritySettingsAction() error = %v", err) t.Fatalf("saveSecuritySettingsAction() error = %v", err)
} }
reloaded := newUIWithSession("desktop", &session.Manager{}) reloaded := newUIWithSession("desktop", &session.Manager{}, statePaths{
reloaded.settingsPath = u.settingsPath SettingsPath: u.settingsPath,
})
reloaded.loadSettings() reloaded.loadSettings()
if got := reloaded.syncDefaultSourceMode; got != syncSourceRemote { if got := reloaded.syncDefaultSourceMode; got != syncSourceRemote {
@@ -3676,8 +3687,9 @@ func TestUIAccessibilityPreferencesPersist(t *testing.T) {
configPath := filepath.Join(t.TempDir(), "ui-prefs.json") configPath := filepath.Join(t.TempDir(), "ui-prefs.json")
first := newUIWithSession("desktop", &session.Manager{}) first := newUIWithSession("desktop", &session.Manager{}, statePaths{
first.uiPreferencesPath = configPath UIPreferencesPath: configPath,
})
first.applyAccessibilityPreferences(accessibilityPreferences{ first.applyAccessibilityPreferences(accessibilityPreferences{
DisplayDensity: displayDensityComfortable, DisplayDensity: displayDensityComfortable,
Contrast: contrastHigh, Contrast: contrastHigh,
@@ -3686,8 +3698,9 @@ func TestUIAccessibilityPreferencesPersist(t *testing.T) {
}) })
first.saveUIPreferences() first.saveUIPreferences()
second := newUIWithSession("desktop", &session.Manager{}) second := newUIWithSession("desktop", &session.Manager{}, statePaths{
second.uiPreferencesPath = configPath UIPreferencesPath: configPath,
})
second.loadUIPreferences() second.loadUIPreferences()
if second.denseLayout { if second.denseLayout {
@@ -3750,14 +3763,16 @@ func TestUINotificationPreferencesPersist(t *testing.T) {
configPath := filepath.Join(t.TempDir(), "ui-prefs.json") configPath := filepath.Join(t.TempDir(), "ui-prefs.json")
first := newUIWithSession("desktop", &session.Manager{}) first := newUIWithSession("desktop", &session.Manager{}, statePaths{
first.uiPreferencesPath = configPath UIPreferencesPath: configPath,
})
first.statusBannerTTL = statusBannerLong first.statusBannerTTL = statusBannerLong
first.autofillNoticePreference = autofillNoticeApprovals first.autofillNoticePreference = autofillNoticeApprovals
first.saveUIPreferences() first.saveUIPreferences()
second := newUIWithSession("desktop", &session.Manager{}) second := newUIWithSession("desktop", &session.Manager{}, statePaths{
second.uiPreferencesPath = configPath UIPreferencesPath: configPath,
})
second.statusBannerTTL = statusBannerDuration second.statusBannerTTL = statusBannerDuration
second.autofillNoticePreference = autofillNoticeAll second.autofillNoticePreference = autofillNoticeAll
second.loadUIPreferences() second.loadUIPreferences()
@@ -4184,6 +4199,9 @@ func TestDefaultStatePathsUsesProvidedStateDir(t *testing.T) {
if got := paths.RecentRemotesPath; got != filepath.Join(base, "recent-remotes.json") { if got := paths.RecentRemotesPath; got != filepath.Join(base, "recent-remotes.json") {
t.Fatalf("RecentRemotesPath = %q, want %q", got, filepath.Join(base, "recent-remotes.json")) t.Fatalf("RecentRemotesPath = %q, want %q", got, filepath.Join(base, "recent-remotes.json"))
} }
if got := paths.SettingsPath; got != filepath.Join(base, "settings.json") {
t.Fatalf("SettingsPath = %q, want %q", got, filepath.Join(base, "settings.json"))
}
if got := paths.UIPreferencesPath; got != filepath.Join(base, "ui-prefs.json") { if got := paths.UIPreferencesPath; got != filepath.Join(base, "ui-prefs.json") {
t.Fatalf("UIPreferencesPath = %q, want %q", got, filepath.Join(base, "ui-prefs.json")) t.Fatalf("UIPreferencesPath = %q, want %q", got, filepath.Join(base, "ui-prefs.json"))
} }
@@ -4207,6 +4225,9 @@ func TestDefaultStatePathsUsesEnvironmentStateDirWhenFlagUnset(t *testing.T) {
if got := paths.RecentRemotesPath; got != filepath.Join(base, "recent-remotes.json") { if got := paths.RecentRemotesPath; got != filepath.Join(base, "recent-remotes.json") {
t.Fatalf("RecentRemotesPath = %q, want %q", got, filepath.Join(base, "recent-remotes.json")) t.Fatalf("RecentRemotesPath = %q, want %q", got, filepath.Join(base, "recent-remotes.json"))
} }
if got := paths.SettingsPath; got != filepath.Join(base, "settings.json") {
t.Fatalf("SettingsPath = %q, want %q", got, filepath.Join(base, "settings.json"))
}
if got := paths.UIPreferencesPath; got != filepath.Join(base, "ui-prefs.json") { if got := paths.UIPreferencesPath; got != filepath.Join(base, "ui-prefs.json") {
t.Fatalf("UIPreferencesPath = %q, want %q", got, filepath.Join(base, "ui-prefs.json")) t.Fatalf("UIPreferencesPath = %q, want %q", got, filepath.Join(base, "ui-prefs.json"))
} }
@@ -4224,6 +4245,7 @@ func TestRunActionSynchronizesAutofillCache(t *testing.T) {
DefaultSaveAsPath: filepath.Join(dir, "vault.kdbx"), DefaultSaveAsPath: filepath.Join(dir, "vault.kdbx"),
RecentVaultsPath: filepath.Join(dir, "recent-vaults.json"), RecentVaultsPath: filepath.Join(dir, "recent-vaults.json"),
RecentRemotesPath: filepath.Join(dir, "recent-remotes.json"), RecentRemotesPath: filepath.Join(dir, "recent-remotes.json"),
SettingsPath: filepath.Join(dir, "settings.json"),
UIPreferencesPath: filepath.Join(dir, "ui-prefs.json"), UIPreferencesPath: filepath.Join(dir, "ui-prefs.json"),
AutofillCachePath: cachePath, AutofillCachePath: cachePath,
}) })