~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
tests: add edge case tests for type conversion functions (#2315)
LearningCircuitac3c91d35a81
diff --git a/tests/settings/test_manager_behavior.py b/tests/settings/test_manager_behavior.pyindex 1bc3661a39..bf283025d4 100644--- a/tests/settings/test_manager_behavior.py+++ b/tests/settings/test_manager_behavior.py@@ -454,3 +454,266 @@ class TestUIElementToSettingType:)assert UI_ELEMENT_TO_SETTING_TYPE["text"] is str+++class TestParseNumberEdgeCases:+ """Edge cases for _parse_number that affect real settings."""++ def test_inf_string_returns_float_inf(self):+ """'inf' parses to float — callers must validate range themselves."""+ from local_deep_research.settings.manager import _parse_number++ result = _parse_number("inf")+ assert result == float("inf")+ assert isinstance(result, float)++ def test_negative_inf_string(self):+ """'-inf' parses to negative infinity."""+ from local_deep_research.settings.manager import _parse_number++ result = _parse_number("-inf")+ assert result == float("-inf")++ def test_nan_string_returns_float_nan(self):+ """'nan' parses to float NaN."""+ import math++ from local_deep_research.settings.manager import _parse_number++ result = _parse_number("nan")+ assert math.isnan(result)++ def test_int_input_passthrough(self):+ """Direct int input is preserved as int (not round-tripped through float)."""+ from local_deep_research.settings.manager import _parse_number++ result = _parse_number(42)+ assert result == 42+ assert isinstance(result, int)++ def test_float_input_whole_becomes_int(self):+ """Float 5.0 becomes int 5 (is_integer() check)."""+ from local_deep_research.settings.manager import _parse_number++ result = _parse_number(5.0)+ assert result == 5+ assert isinstance(result, int)++ def test_scientific_notation(self):+ """Scientific notation string parses correctly."""+ from local_deep_research.settings.manager import _parse_number++ result = _parse_number("1e3")+ assert result == 1000+ assert isinstance(result, int)++ def test_very_large_number(self):+ """Large number beyond typical int range still works."""+ from local_deep_research.settings.manager import _parse_number++ result = _parse_number("99999999999999")+ assert result == 99999999999999+ assert isinstance(result, int)+++class TestParseMultiselectEdgeCases:+ """Edge cases for _parse_multiselect with non-standard inputs."""++ def test_dict_input_returned_as_is(self):+ """Dict passes through unchanged (not list, not string)."""+ from local_deep_research.settings.manager import _parse_multiselect++ d = {"key": "value"}+ assert _parse_multiselect(d) is d++ def test_int_input_returned_as_is(self):+ """Integer passes through unchanged."""+ from local_deep_research.settings.manager import _parse_multiselect++ assert _parse_multiselect(42) == 42++ def test_none_input_returned_as_is(self):+ """None passes through unchanged."""+ from local_deep_research.settings.manager import _parse_multiselect++ assert _parse_multiselect(None) is None++ def test_json_array_of_non_list_falls_back_to_csv(self):+ """JSON string that parses to non-list falls through to CSV split."""+ from local_deep_research.settings.manager import _parse_multiselect++ # Starts with '[' but json.loads returns... actually this is a list+ # Use a case where JSON parse succeeds but isn't a list: impossible+ # with '[' prefix. Test that invalid JSON starting with '[' falls to CSV.+ result = _parse_multiselect("[not valid json")+ assert result == ["[not valid json"]++ def test_empty_string_returns_empty_list(self):+ """Empty string returns empty list after CSV split filtering."""+ from local_deep_research.settings.manager import _parse_multiselect++ assert _parse_multiselect("") == []++ def test_whitespace_only_items_filtered(self):+ """Comma-separated with blank items filters them out."""+ from local_deep_research.settings.manager import _parse_multiselect++ result = _parse_multiselect("a, , b, ,c")+ assert result == ["a", "b", "c"]+++class TestParseJsonValueEdgeCases:+ """Edge cases for _parse_json_value with tricky inputs."""++ def test_json_number_string_parses_to_number(self):+ """A plain number string is valid JSON — parses to int."""+ from local_deep_research.settings.manager import _parse_json_value++ result = _parse_json_value("42")+ assert result == 42++ def test_json_boolean_string_parses_to_bool(self):+ """'true' is valid JSON — parses to Python True."""+ from local_deep_research.settings.manager import _parse_json_value++ assert _parse_json_value("true") is True+ assert _parse_json_value("false") is False++ def test_json_null_string_parses_to_none(self):+ """'null' is valid JSON — parses to None."""+ from local_deep_research.settings.manager import _parse_json_value++ assert _parse_json_value("null") is None++ def test_nested_json_object(self):+ """Nested JSON objects parse correctly."""+ from local_deep_research.settings.manager import _parse_json_value++ raw = '{"outer": {"inner": [1, 2]}}'+ result = _parse_json_value(raw)+ assert result == {"outer": {"inner": [1, 2]}}++ def test_int_input_passthrough(self):+ """Non-string types pass through unchanged."""+ from local_deep_research.settings.manager import _parse_json_value++ assert _parse_json_value(42) == 42++ def test_bool_input_passthrough(self):+ """Boolean passes through unchanged."""+ from local_deep_research.settings.manager import _parse_json_value++ assert _parse_json_value(True) is True++ def test_json_with_leading_whitespace(self):+ """JSON string with leading whitespace is stripped before parsing."""+ from local_deep_research.settings.manager import _parse_json_value++ result = _parse_json_value(' {"key": "value"} ')+ assert result == {"key": "value"}+++class TestGetTypedSettingValueEnvFallback:+ """Tests for env var → DB fallback path in get_typed_setting_value."""++ def test_invalid_env_var_falls_back_to_db_value(self):+ """When env var has invalid value for the type, DB value is used."""+ from local_deep_research.settings.manager import get_typed_setting_value++ with patch.dict(os.environ, {"LDR_TEST_ITERATIONS": "not_a_number"}):+ result = get_typed_setting_value(+ "test.iterations", 5, "number", default=0, check_env=True+ )+ # Should fall back to DB value 5, not env "not_a_number"+ assert result == 5++ def test_valid_env_var_overrides_db_value(self):+ """When env var is valid, it takes priority over DB value."""+ from local_deep_research.settings.manager import get_typed_setting_value++ with patch.dict(os.environ, {"LDR_TEST_ITERATIONS": "10"}):+ result = get_typed_setting_value(+ "test.iterations", 5, "number", default=0, check_env=True+ )+ assert result == 10++ def test_env_var_skipped_when_check_env_false(self):+ """check_env=False ignores environment variables entirely."""+ from local_deep_research.settings.manager import get_typed_setting_value++ with patch.dict(os.environ, {"LDR_TEST_ITERATIONS": "99"}):+ result = get_typed_setting_value(+ "test.iterations", 5, "number", default=0, check_env=False+ )+ assert result == 5++ def test_env_var_type_error_on_number_does_not_crash(self):+ """TypeError during env var conversion falls through to DB value.++ Note: the env path only catches ValueError (line 206), so a TypeError+ would propagate. This documents the current behavior — _parse_number+ with a string always raises ValueError, never TypeError.+ """+ from local_deep_research.settings.manager import get_typed_setting_value++ # _parse_number("") raises ValueError, not TypeError+ with patch.dict(os.environ, {"LDR_TEST_NUM": ""}):+ result = get_typed_setting_value(+ "test.num", 42, "number", default=0, check_env=True+ )+ assert result == 42++ def test_db_value_type_error_returns_default(self):+ """TypeError during DB value conversion returns default.++ This path (line 220) catches both ValueError and TypeError, unlike+ the env path which only catches ValueError.+ """+ from local_deep_research.settings.manager import get_typed_setting_value++ # Passing a type that causes TypeError in float() — e.g. a list+ result = get_typed_setting_value(+ "test.key", [1, 2, 3], "number", default=0, check_env=False+ )+ assert result == 0++ def test_textarea_preserves_multiline_string(self):+ """Textarea ui_element preserves newlines (uses str converter)."""+ from local_deep_research.settings.manager import get_typed_setting_value++ multiline = "line1\nline2\nline3"+ result = get_typed_setting_value(+ "test.key", multiline, "textarea", check_env=False+ )+ assert result == multiline++ def test_number_with_bool_input_converts_to_int(self):+ """Bool passed to number field: float(True)=1.0, is_integer()→int 1.++ This is a real scenario when frontend sends JSON true for a number field.+ """+ from local_deep_research.settings.manager import get_typed_setting_value++ result = get_typed_setting_value(+ "test.key", True, "number", check_env=False+ )+ assert result == 1+ assert isinstance(result, int)++ def test_checkbox_with_int_zero(self):+ """Integer 0 sent for a checkbox field returns False."""+ from local_deep_research.settings.manager import get_typed_setting_value++ result = get_typed_setting_value(+ "test.key", 0, "checkbox", check_env=False+ )+ assert result is False++ def test_checkbox_with_int_one(self):+ """Integer 1 sent for a checkbox field returns True."""+ from local_deep_research.settings.manager import get_typed_setting_value++ result = get_typed_setting_value(+ "test.key", 1, "checkbox", check_env=False+ )+ assert result is True