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.

test(db): lock in LDR_TEST_MODE boolean parsing for the KDF floor (#4565)

LearningCircuitb0f5c1f5faad
diff --git a/changelog.d/+kdf-test-mode-coverage.misc.md b/changelog.d/+kdf-test-mode-coverage.misc.md
new file mode 100644
index 0000000000..aa28288e61
--- /dev/null
+++ b/changelog.d/+kdf-test-mode-coverage.misc.md
@@ -0,0 +1 @@
+Tests: lock in the ``LDR_TEST_MODE`` boolean-parsing behaviour for the SQLCipher KDF floor. Adds direct ``_get_min_kdf_iterations()`` unit tests for falsey values (``0``/``false``/``no``/``off`` must NOT relax the floor — the #4564 regression) and the full truthy set (``on``/``enabled`` must relax it, guarding against a narrower parser). Also moves the integration test off the registry's ``min_value`` boundary so it exercises the KDF-floor clamp rather than range validation.
diff --git a/tests/database/test_kdf_iterations.py b/tests/database/test_kdf_iterations.py
index d9f529d016..e4ec4b6d38 100644
--- a/tests/database/test_kdf_iterations.py
+++ b/tests/database/test_kdf_iterations.py
@@ -9,6 +9,8 @@ Tests cover:
- Constants have correct values
"""
+import pytest
+
class TestGetMinKdfIterations:
"""Tests for _get_min_kdf_iterations()."""
@@ -79,6 +81,44 @@ class TestGetMinKdfIterations:
assert _get_min_kdf_iterations() == 100_000
+ @pytest.mark.parametrize(
+ "falsey", ["0", "false", "False", "no", "off", "banana"]
+ )
+ def test_falsey_ldr_test_mode_is_production(self, monkeypatch, falsey):
+ """LDR_TEST_MODE is parsed as a boolean: explicit falsey values (and
+ unrecognised strings like 'banana') must NOT relax the floor. A bare
+ truthiness check would treat any non-empty string as enabled and
+ silently weaken encryption.
+ """
+ # Load-bearing: _get_min_kdf_iterations() also relaxes the floor when
+ # PYTEST_CURRENT_TEST is present (which it always is under pytest), so
+ # we must clear it to isolate the LDR_TEST_MODE behaviour under test.
+ monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
+ monkeypatch.setenv("LDR_TEST_MODE", falsey)
+
+ from local_deep_research.database.sqlcipher_utils import (
+ _get_min_kdf_iterations,
+ )
+
+ assert _get_min_kdf_iterations() == 100_000
+
+ @pytest.mark.parametrize("truthy", ["true", "TRUE", "yes", "on", "enabled"])
+ def test_extended_truthy_ldr_test_mode_relaxes(self, monkeypatch, truthy):
+ """LDR_TEST_MODE accepts the full boolean truthy set (to_bool), not
+ just '1'/'true' — locks that behavior so a narrower parser would be
+ caught.
+ """
+ # Clear PYTEST_CURRENT_TEST so the relaxation we observe is attributable
+ # to LDR_TEST_MODE, not pytest's own presence (see falsey test above).
+ monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
+ monkeypatch.setenv("LDR_TEST_MODE", truthy)
+
+ from local_deep_research.database.sqlcipher_utils import (
+ _get_min_kdf_iterations,
+ )
+
+ assert _get_min_kdf_iterations() == 1
+
class TestKdfConstants:
"""Tests for KDF iteration constants."""
diff --git a/tests/database/test_sqlcipher_utils.py b/tests/database/test_sqlcipher_utils.py
index aab63721c0..f930ef48bd 100644
--- a/tests/database/test_sqlcipher_utils.py
+++ b/tests/database/test_sqlcipher_utils.py
@@ -1237,10 +1237,14 @@ class TestCIAwareKDFMinimum:
DEFAULT_KDF_ITERATIONS,
)
+ # 50000 sits below the production floor (100000) but well above the
+ # registry's own min_value (1000), so this exercises the KDF-floor
+ # clamp rather than the registry's range validation — and stays
+ # robust if that min_value is ever raised.
for falsey in ("0", "false", "no", "off"):
with patch.dict(
os.environ,
- {"LDR_DB_KDF_ITERATIONS": "1000", "LDR_TEST_MODE": falsey},
+ {"LDR_DB_KDF_ITERATIONS": "50000", "LDR_TEST_MODE": falsey},
clear=True,
):
settings = get_sqlcipher_settings()