Skip to content

Commit 4ccb83d

Browse files
authored
fix: stop overwriting dirty_settings with an empty dict on init (#65)
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
1 parent 8d52a5f commit 4ccb83d

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

tests/test_settings.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ def test_switching_categories_retains_dirty_settings(tmp_path, monkeypatch):
4848
app._update_dirty_setting("theme", "light")
4949
app.selected_category = "Data"
5050
assert "theme" in app.dirty_settings
51-
assert app.dirty_settings["theme"] == "light"
51+
assert app.dirty_settings["theme"] == "light"
52+
53+
54+
def test_dirty_settings_seeded_from_loaded_settings(tmp_path, monkeypatch):
55+
# Regression: __init__ used to overwrite `dirty_settings` with an empty
56+
# dict immediately after seeding it from `self.settings`, which silently
57+
# discarded any persisted values before the UI rendered.
58+
monkeypatch.setattr(Path, "home", lambda: tmp_path)
59+
app = SettingsApp()
60+
assert app.dirty_settings == app.settings
61+
assert app.dirty_settings == {
62+
"theme": "dark",
63+
"prompt_symbol": "➜",
64+
"show_git_status": True,
65+
"auto_complete": True,
66+
"csv_max_rows": 50,
67+
}

trushell/commands/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ def __init__(self, **kwargs) -> None:
7474
super().__init__(**kwargs)
7575
self.manager = SettingsManager()
7676
self.settings = self.manager.load()
77+
# Track changes to settings without losing data when switching categories
7778
self.dirty_settings = dict(self.settings)
7879
self.selected_category = "General"
79-
# Track changes to settings without losing data when switching categories
80-
self.dirty_settings: dict = {}
8180

8281
def compose(self) -> ComposeResult:
8382
yield Header(show_clock=False)

0 commit comments

Comments
 (0)