From 75d7c92fb1ac2215a0cee34153d38d19211f767b Mon Sep 17 00:00:00 2001 From: saya-7 Date: Wed, 10 Jun 2026 06:08:43 +0000 Subject: [PATCH] fix: stop overwriting dirty_settings with an empty dict on init SettingsApp.__init__ seeded `self.dirty_settings` from the loaded settings and then immediately re-bound it to an empty dict, which silently discarded any persisted values before the UI rendered. Drop the second assignment so dirty state starts equal to the loaded settings, as the surrounding comment intended. Closes #64 --- tests/test_settings.py | 18 +++++++++++++++++- trushell/commands/settings.py | 3 +-- 2 files changed, 18 insertions(+), 3 deletions(-) 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)