diff --git a/tests/test_settings.py b/tests/test_settings.py index a3c93de..d99fcb4 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -48,4 +48,20 @@ def test_switching_categories_retains_dirty_settings(tmp_path, monkeypatch): app._update_dirty_setting("theme", "light") app.selected_category = "Data" assert "theme" in app.dirty_settings - assert app.dirty_settings["theme"] == "light" \ No newline at end of file + assert app.dirty_settings["theme"] == "light" + + +def test_dirty_settings_seeded_from_loaded_settings(tmp_path, monkeypatch): + # Regression: __init__ used to overwrite `dirty_settings` with an empty + # dict immediately after seeding it from `self.settings`, which silently + # discarded any persisted values before the UI rendered. + monkeypatch.setattr(Path, "home", lambda: tmp_path) + app = SettingsApp() + assert app.dirty_settings == app.settings + assert app.dirty_settings == { + "theme": "dark", + "prompt_symbol": "➜", + "show_git_status": True, + "auto_complete": True, + "csv_max_rows": 50, + } diff --git a/trushell/commands/settings.py b/trushell/commands/settings.py index b7243eb..2057ad0 100644 --- a/trushell/commands/settings.py +++ b/trushell/commands/settings.py @@ -74,10 +74,9 @@ def __init__(self, **kwargs) -> None: super().__init__(**kwargs) self.manager = SettingsManager() self.settings = self.manager.load() + # Track changes to settings without losing data when switching categories self.dirty_settings = dict(self.settings) self.selected_category = "General" - # Track changes to settings without losing data when switching categories - self.dirty_settings: dict = {} def compose(self) -> ComposeResult: yield Header(show_clock=False)