refactor(settings): invert sync logic from whitelist to blacklist

Replace _SYNC_KEYS (37 keys) with _NO_SYNC_KEYS (5 keys) in SettingsHandler.
New settings automatically sync to frontend unless explicitly excluded.

Changes:
- SettingsHandler now syncs all settings except those in _NO_SYNC_KEYS
- Added keys() method to SettingsManager for iteration
- Updated tests to use new behavior

Benefits:
- No more missing keys when adding new settings
- Reduced maintenance burden
- Explicit exclusions for sensitive/internal settings only

Fixes: #86
This commit is contained in:
Will Miao
2026-02-20 12:14:50 +08:00
parent 1725558fbc
commit 879588e252
5 changed files with 42 additions and 46 deletions

View File

@@ -26,6 +26,7 @@
'settings': dict({
'civitai_api_key': 'test-key',
'language': 'en',
'theme': 'dark',
}),
'success': True,
})

View File

@@ -45,6 +45,9 @@ class DummySettings:
def set(self, key, value):
self.data[key] = value
def keys(self):
return self.data.keys()
async def noop_async(*_args, **_kwargs):
"""No-op async function."""

View File

@@ -44,6 +44,9 @@ class DummySettings:
def delete(self, key):
self.data.pop(key, None)
def keys(self):
return self.data.keys()
class DummyDownloader:
def __init__(self):
@@ -62,8 +65,14 @@ async def dummy_downloader_factory():
@pytest.mark.asyncio
async def test_get_settings_filters_sync_keys():
settings_service = DummySettings({"civitai_api_key": "abc", "extraneous": "value"})
async def test_get_settings_excludes_no_sync_keys():
"""Verify that settings in _NO_SYNC_KEYS are not synced, but others are."""
settings_service = DummySettings({
"civitai_api_key": "abc",
"hash_chunk_size_mb": 10,
"folder_paths": {"/some/path"},
"regular_setting": "value",
})
handler = SettingsHandler(
settings_service=settings_service,
metadata_provider_updater=noop_async,
@@ -74,7 +83,12 @@ async def test_get_settings_filters_sync_keys():
payload = json.loads(response.text)
assert payload["success"] is True
assert payload["settings"] == {"civitai_api_key": "abc"}
# Regular settings should be synced
assert payload["settings"]["civitai_api_key"] == "abc"
assert payload["settings"]["regular_setting"] == "value"
# _NO_SYNC_KEYS should not be synced
assert "hash_chunk_size_mb" not in payload["settings"]
assert "folder_paths" not in payload["settings"]
@pytest.mark.asyncio