Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

settings: mechanical cleanups from #5597 (#5730) (#6687)

Momoru1932c2ff4327cf
diff --git a/src/local_deep_research/api/settings_utils.py b/src/local_deep_research/api/settings_utils.py
index 58041e1b38..25ae9b8a78 100644
--- a/src/local_deep_research/api/settings_utils.py
+++ b/src/local_deep_research/api/settings_utils.py
@@ -14,7 +14,7 @@ from ..settings import SettingsManager
from ..settings.base import ISettingsManager
from ..settings.manager import (
UI_ELEMENT_TO_SETTING_TYPE,
- _validate_imported_setting_value,
+ validate_imported_setting_value,
check_env_setting,
)
from ..utilities.type_utils import to_bool, unwrap_setting
@@ -232,13 +232,10 @@ class InMemorySettingsManager(ISettingsManager):
preserve_environment_locked: bool = False,
) -> None:
"""Import settings from a dictionary."""
- # Schema-aware import (#5589): validate values that come from the
- # imported file against the CURRENT defaults schema, so a
- # pre-upgrade export cannot resurrect values that are invalid under
- # the current options/constraints. Values retained from existing
- # in-memory state (the `overwrite=False` path and environment-locked
- # values under `preserve_environment_locked`) are trusted, not
- # untrusted file input, and are deliberately not validated.
+ # Schema-aware import (#5589) — validates untrusted file values
+ # against the current schema; see validate_imported_setting_value's
+ # docstring for the trusted-vs-untrusted rationale (values retained
+ # from existing in-memory state are trusted here, not validated).
defaults_for_import = self._base_manager.default_settings
# Under `delete_extra=True`, entries cleared below must still be
# restorable for keys whose imported value is rejected by
@@ -284,7 +281,7 @@ class InMemorySettingsManager(ISettingsManager):
if (
default_meta is not None
and not preserve_value
- and _validate_imported_setting_value(
+ and validate_imported_setting_value(
key, value["value"], default_meta
)
is not None
diff --git a/src/local_deep_research/settings/manager.py b/src/local_deep_research/settings/manager.py
index b4d565e729..3ee5528b03 100644
--- a/src/local_deep_research/settings/manager.py
+++ b/src/local_deep_research/settings/manager.py
@@ -164,7 +164,9 @@ def _filter_setting_columns(data: dict) -> dict:
DYNAMIC_SETTINGS = ["llm.provider", "llm.model", "search.tool"]
-def _validate_imported_setting_value(
+# Re-exported by `api/settings_utils.py` (single source of truth) and
+# imported by tests that assert identity across import orders.
+def validate_imported_setting_value(
key: str, value: Any, default_meta: Dict[str, Any]
) -> Optional[str]:
"""Validate a file-supplied setting value against the current-defaults
@@ -1674,15 +1676,9 @@ class SettingsManager(ISettingsManager):
logger.debug(f"Importing {len(settings_data)} settings")
changed_keys: list[str] = []
retained_keys: set[str] = set()
- # Schema-aware import (#5589): validate values that come from the
- # imported file against the CURRENT defaults schema, so a
- # pre-upgrade export cannot resurrect values that are invalid under
- # the current options/constraints. Values retained from the database
- # (the `overwrite=False` version-bump reconciliation path, and
- # environment-locked values under `preserve_environment_locked`)
- # are deliberately NOT validated: they are trusted stored state,
- # not untrusted file input, and rejecting them would break the
- # reconciliation contract ("refresh schema, keep value").
+ # Schema-aware import (#5589) — see validate_imported_setting_value's
+ # docstring for the trusted-vs-untrusted rationale (values retained
+ # from the database are trusted here, not validated).
defaults_for_import = self.default_settings
try:
# `overwrite=False` is the version-bump reconciliation point:
@@ -1723,20 +1719,12 @@ class SettingsManager(ISettingsManager):
value_replaced_from_db = True
if not value_replaced_from_db:
- # Schema-aware import (#5589): a value that comes from
- # the imported file is untrusted input. Validate it
- # against the CURRENT defaults schema so a pre-upgrade
- # export cannot resurrect values that are invalid under
- # the current options/constraints. Values retained from
- # the database (the `overwrite=False` version-bump
- # reconciliation path, and environment-locked values
- # under `preserve_environment_locked`) are deliberately
- # NOT validated: they are trusted stored state, and
- # rejecting them would break the reconciliation
- # contract ("refresh schema, keep value").
+ # Schema-aware import (#5589): untrusted file value —
+ # see validate_imported_setting_value's docstring for
+ # the trusted-vs-untrusted rationale.
default_meta = defaults_for_import.get(key)
if default_meta is not None:
- invalid_reason = _validate_imported_setting_value(
+ invalid_reason = validate_imported_setting_value(
key,
setting_values.get("value"),
default_meta,
diff --git a/tests/security/test_settings_egress_and_secrets_fastapi.py b/tests/security/test_settings_egress_and_secrets_fastapi.py
index 9df97b543a..0747b2a585 100644
--- a/tests/security/test_settings_egress_and_secrets_fastapi.py
+++ b/tests/security/test_settings_egress_and_secrets_fastapi.py
@@ -2304,7 +2304,7 @@ class TestBulkSecretWriteBackAndEcho:
tripped it and only the leak assertion failed.
Skipping the converter at a fourth call site would have been
- whack-a-mole: ``_validate_imported_setting_value`` reaches it too,
+ whack-a-mole: ``validate_imported_setting_value`` reaches it too,
and so does any future reader. The fix is that
``get_typed_setting_value`` no longer logs a setting VALUE at all
-- a settings value is, by this PR's own premise, a plausible
diff --git a/tests/settings/test_import_settings_validation.py b/tests/settings/test_import_settings_validation.py
index 69ad634920..2ef8d819e3 100644
--- a/tests/settings/test_import_settings_validation.py
+++ b/tests/settings/test_import_settings_validation.py
@@ -397,11 +397,25 @@ class TestDynamicSettingsSingleSource:
)
+class TestValidateImportedSettingValueSingleSource:
+ """validate_imported_setting_value identity across import orders stays
+ intact (#5664) — mirrors TestDynamicSettingsSingleSource above."""
+
+ def test_api_settings_utils_is_source_of_truth(self):
+ from local_deep_research.api import settings_utils
+ from local_deep_research.settings import manager as manager_module
+
+ assert (
+ settings_utils.validate_imported_setting_value
+ is manager_module.validate_imported_setting_value
+ )
+
+
class TestUnknownUiElementImport:
"""#5674: an unknown ``ui_element`` must not log a default-substitution
warning on a value the import accepts and stores verbatim.
- ``_validate_imported_setting_value`` reads ``ui_element`` from the
+ ``validate_imported_setting_value`` reads ``ui_element`` from the
current-defaults metadata and uses ``get_typed_setting_value`` only as a
validity probe, discarding its return. That helper's "returning default
value" message is therefore false on this path.
@@ -435,11 +449,11 @@ class TestUnknownUiElementImport:
):
"""The helper under repair, driven directly."""
from local_deep_research.settings.manager import (
- _validate_imported_setting_value,
+ validate_imported_setting_value,
)
with loguru_caplog.at_level("WARNING"):
- reason = _validate_imported_setting_value(
+ reason = validate_imported_setting_value(
self.UNKNOWN_KEY, "user_choice", dict(self.UNKNOWN_META)
)
diff --git a/tests/settings/test_settings_defaults_runtime_validation.py b/tests/settings/test_settings_defaults_runtime_validation.py
index c0594c9bed..d36d954d73 100644
--- a/tests/settings/test_settings_defaults_runtime_validation.py
+++ b/tests/settings/test_settings_defaults_runtime_validation.py
@@ -7,7 +7,7 @@ no longer exists"): ``app.theme`` shipped as ``"dark"`` while
the theme registry, and the generated registry list had no ``dark`` entry.
The shipped default named a value that was not among its own runtime
options. This stayed invisible because seeding a fresh install goes through
-``manager.py``'s ``_validate_imported_setting_value``, which has a guard
+``manager.py``'s ``validate_imported_setting_value``, which has a guard
that vouches for a value *because* it equals the shipped default — so an
invalid default seeds successfully. The only path that ever actually
validated the stored value against its live constraints was the
diff --git a/tests/settings/test_shipped_defaults_contracts.py b/tests/settings/test_shipped_defaults_contracts.py
index 4cc3298711..72c952ef59 100644
--- a/tests/settings/test_shipped_defaults_contracts.py
+++ b/tests/settings/test_shipped_defaults_contracts.py
@@ -796,7 +796,7 @@ class TestEveryDefaultIsLoadable:
)
# `slider` is the specific latent gap. Three call sites --
- # settings/manager.py's _validate_imported_setting_value,
+ # settings/manager.py's validate_imported_setting_value,
# web/routers/settings.py's validate_setting, and
# web/services/settings_service.py -- branch on
# ("number", "slider", "range") as if all three were numeric, but
@@ -954,7 +954,7 @@ class TestEveryDefaultIsLoadable:
"list offers only markdown/latex/quarto -- 'ris' is a value "
"the UI cannot render or round-trip. It survives because "
"validate_setting (web/routers/settings.py) and "
- "_validate_imported_setting_value (settings/manager.py) have "
+ "validate_imported_setting_value (settings/manager.py) have "
"no 'multiselect' branch at all: multiselect values are never "
"checked against their options on any path. Fix by adding "
"'ris' to the options list (or dropping it from the value) "