~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
fix: use to_bool for checkbox env var conversion (#1879)
LearningCircuit695d20b2a5f2
diff --git a/src/local_deep_research/utilities/type_utils.py b/src/local_deep_research/utilities/type_utils.pyindex b9fee88f2e..fdf45b266a 100644--- a/src/local_deep_research/utilities/type_utils.py+++ b/src/local_deep_research/utilities/type_utils.py@@ -47,7 +47,9 @@ def to_bool(value: Any, default: bool = False) -> bool:if isinstance(value, bool):return valueif isinstance(value, str):- return value.lower() in ("true", "1", "yes", "on", "enabled")+ # Use strip() to handle whitespace that often appears in env vars+ # e.g., from shell parsing, config files, or copy-paste errors+ return value.strip().lower() in ("true", "1", "yes", "on", "enabled")if value is None:return default# For other types (int, etc.), use Python's bool conversiondiff --git a/tests/unit/test_boolean_settings.py b/tests/unit/test_boolean_settings.pyindex 79c48bbecf..75489132df 100644--- a/tests/unit/test_boolean_settings.py+++ b/tests/unit/test_boolean_settings.py@@ -107,12 +107,12 @@ class TestToBoolUtility:assert to_bool("\t") is Falseassert to_bool("\n") is False- def test_string_with_leading_whitespace_is_false(self):- """Test that strings with leading/trailing whitespace don't match."""- # The current implementation doesn't strip, so these won't match- assert to_bool(" true") is False- assert to_bool("true ") is False- assert to_bool(" yes ") is False+ def test_string_with_leading_whitespace_is_true(self):+ """Test that strings with leading/trailing whitespace still match."""+ # to_bool strips whitespace before matching (handles env var quirks)+ assert to_bool(" true") is True+ assert to_bool("true ") is True+ assert to_bool(" yes ") is True# Numeric valuesdef test_integer_zero_is_false(self):diff --git a/tests/utilities/test_type_utils.py b/tests/utilities/test_type_utils.pyindex 811cedf620..2b8825c1ea 100644--- a/tests/utilities/test_type_utils.py+++ b/tests/utilities/test_type_utils.py@@ -185,3 +185,310 @@ class TestToBool:from local_deep_research.utilities.type_utils import to_boolassert to_bool({"key": "value"}) is True+++class TestToBoolWhitespaceHandling:+ """Tests for whitespace handling in to_bool.++ Environment variables often have trailing whitespace from shell parsing,+ config files, or copy-paste errors. The to_bool function should handle+ these gracefully.+ """++ def test_leading_trailing_spaces(self):+ """Test truthy values with leading/trailing spaces."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool(" true ") is True+ assert to_bool(" yes ") is True+ assert to_bool(" 1 ") is True++ def test_tab_characters(self):+ """Test truthy values with tab characters."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("\ttrue\t") is True+ assert to_bool("\tyes\t") is True++ def test_newline_characters(self):+ """Test truthy values with newline characters (common in env vars)."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("true\n") is True+ assert to_bool("\ntrue") is True+ assert to_bool("\ntrue\n") is True++ def test_mixed_whitespace(self):+ """Test truthy values with mixed whitespace."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool(" \t yes \n ") is True+ assert to_bool("\t\n on \t\n") is True++ def test_whitespace_around_falsy_values(self):+ """Test that whitespace around falsy strings still returns False."""+ from local_deep_research.utilities.type_utils import to_bool++ # These aren't in the truthy set, so should be False+ assert to_bool(" false ") is False+ assert to_bool("\tno\t") is False+ assert to_bool(" off ") is False++ def test_only_whitespace_returns_false(self):+ """Test that whitespace-only strings return False."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool(" ") is False+ assert to_bool("\t\t\t") is False+ assert to_bool("\n\n") is False+ assert to_bool(" \t \n ") is False+++class TestToBoolNumericStringEdgeCases:+ """Tests for numeric string edge cases.++ Important distinction: string "2" should be False (not in truthy set),+ but integer 2 should be True (non-zero integer).+ """++ def test_string_two_returns_false(self):+ """Test string '2' returns False (not in truthy set)."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("2") is False++ def test_string_fortytwo_returns_false(self):+ """Test arbitrary numeric string returns False."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("42") is False++ def test_string_negative_one_returns_false(self):+ """Test string '-1' returns False (not in truthy set)."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("-1") is False++ def test_string_float_returns_false(self):+ """Test float as string returns False."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("3.14") is False+ assert to_bool("0.0") is False+ assert to_bool("1.0") is False++ def test_string_zero_with_leading_zeros(self):+ """Test zero with leading zeros."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("00") is False+ assert to_bool("000") is False++ def test_string_one_with_leading_zeros(self):+ """Test one with leading zeros still returns False (not exact '1')."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("01") is False+ assert to_bool("001") is False++ def test_string_plus_one(self):+ """Test '+1' returns False (not exact '1')."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("+1") is False+++class TestToBoolPartialStringMatches:+ """Tests for partial string matches (security concern).++ These values contain truthy keywords but should NOT match because+ we use exact string comparison, not substring matching.+ """++ def test_enable_without_d(self):+ """Test 'enable' (without 'd') returns False."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("enable") is False++ def test_truthy_with_suffix(self):+ """Test truthy values with suffixes return False."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("enabled_on") is False+ assert to_bool("true_value") is False+ assert to_bool("yes_please") is False++ def test_truthy_with_prefix(self):+ """Test truthy values with prefixes return False."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("x_true") is False+ assert to_bool("is_on") is False+ assert to_bool("say_yes") is False++ def test_contains_on_but_not_word_on(self):+ """Test strings that contain 'on' but aren't the word 'on'."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("honest") is False+ assert to_bool("onset") is False+ assert to_bool("condition") is False+ assert to_bool("python") is False++ def test_contains_yes_but_not_word_yes(self):+ """Test strings that contain 'yes' but aren't the word 'yes'."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("yesterday") is False+ assert to_bool("yes_or_no") is False+++class TestToBoolReturnTypeValidation:+ """Tests to ensure to_bool always returns actual bool type."""++ def test_returns_actual_bool_for_string_true(self):+ """Test that string 'true' returns actual bool, not truthy value."""+ from local_deep_research.utilities.type_utils import to_bool++ result = to_bool("true")+ assert result is True+ assert isinstance(result, bool)+ assert type(result) is bool++ def test_returns_actual_bool_for_string_false(self):+ """Test that string 'false' returns actual bool."""+ from local_deep_research.utilities.type_utils import to_bool++ result = to_bool("false")+ assert result is False+ assert isinstance(result, bool)+ assert type(result) is bool++ def test_returns_actual_bool_for_integer(self):+ """Test that integer returns actual bool."""+ from local_deep_research.utilities.type_utils import to_bool++ result = to_bool(1)+ assert result is True+ assert isinstance(result, bool)++ result = to_bool(0)+ assert result is False+ assert isinstance(result, bool)++ def test_returns_actual_bool_for_none(self):+ """Test that None with default returns actual bool."""+ from local_deep_research.utilities.type_utils import to_bool++ result = to_bool(None, default=True)+ assert result is True+ assert isinstance(result, bool)+++class TestToBoolDefaultParameterEdgeCases:+ """Tests for default parameter behavior."""++ def test_default_only_used_for_none(self):+ """Test that default is only used for None, not empty string."""+ from local_deep_research.utilities.type_utils import to_bool++ # Empty string should return False, NOT the default+ assert to_bool("", default=True) is False++ def test_default_not_used_for_explicit_false(self):+ """Test that default is not used when value is explicit false."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("false", default=True) is False+ assert to_bool("0", default=True) is False++ def test_default_not_used_for_empty_list(self):+ """Test that default is not used for empty collections."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool([], default=True) is False+ assert to_bool({}, default=True) is False++ def test_default_used_only_for_none(self):+ """Test that default is used for None."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool(None, default=True) is True+ assert to_bool(None, default=False) is False+++class TestToBoolSpecialStringValues:+ """Tests for special string values that might appear in config."""++ def test_json_like_values(self):+ """Test JSON-like string values."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("null") is False+ assert to_bool("undefined") is False+ assert to_bool("NaN") is False++ def test_human_like_responses(self):+ """Test human-like response strings."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("absolutely") is False+ assert to_bool("definitely") is False+ assert to_bool("nope") is False+ assert to_bool("maybe") is False++ def test_case_variations_of_truthy(self):+ """Test various case variations of truthy values."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("TRUE") is True+ assert to_bool("True") is True+ assert to_bool("tRuE") is True+ assert to_bool("YES") is True+ assert to_bool("Yes") is True+ assert to_bool("yEs") is True+ assert to_bool("ON") is True+ assert to_bool("On") is True+ assert to_bool("ENABLED") is True+ assert to_bool("Enabled") is True++ def test_case_variations_of_falsy(self):+ """Test various case variations of falsy string values."""+ from local_deep_research.utilities.type_utils import to_bool++ # These aren't in truthy set, so all return False+ assert to_bool("FALSE") is False+ assert to_bool("False") is False+ assert to_bool("NO") is False+ assert to_bool("No") is False+ assert to_bool("OFF") is False+ assert to_bool("Off") is False+ assert to_bool("DISABLED") is False+ assert to_bool("Disabled") is False+++class TestToBoolEnvironmentVariableSimulation:+ """Tests simulating real environment variable scenarios."""++ def test_env_var_with_trailing_newline(self):+ """Test env var value with trailing newline (common from shell)."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("true\n") is True+ assert to_bool("false\n") is False++ def test_env_var_with_carriage_return(self):+ """Test env var value with Windows-style line ending."""+ from local_deep_research.utilities.type_utils import to_bool++ assert to_bool("true\r\n") is True+ assert to_bool("true\r") is True++ def test_env_var_quoted_value(self):+ """Test that quoted values are treated as arbitrary strings."""+ from local_deep_research.utilities.type_utils import to_bool++ # If someone accidentally includes quotes in the env var value+ assert to_bool('"true"') is False+ assert to_bool("'true'") is False