7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
178 lines
5.5 KiB
Python
178 lines
5.5 KiB
Python
"""Extra coverage tests for config/thread_settings.py — untested branches."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from local_deep_research.config.thread_settings import (
|
|
NoSettingsContextError,
|
|
get_bool_setting_from_snapshot,
|
|
get_setting_from_snapshot,
|
|
)
|
|
|
|
MODULE = "local_deep_research.config.thread_settings"
|
|
|
|
|
|
class TestGetSettingFromSnapshotChildKeys:
|
|
def test_child_keys_built_into_dict(self):
|
|
"""When snapshot has 'parent.child' keys, they're assembled into a dict."""
|
|
snapshot = {
|
|
"search.engine.web.searxng.url": "http://localhost:8888",
|
|
"search.engine.web.searxng.enabled": True,
|
|
}
|
|
result = get_setting_from_snapshot(
|
|
"search.engine.web.searxng",
|
|
settings_snapshot=snapshot,
|
|
)
|
|
assert isinstance(result, dict)
|
|
assert result["url"] == "http://localhost:8888"
|
|
assert result["enabled"] is True
|
|
|
|
def test_child_keys_with_value_dict_format(self):
|
|
"""Child keys in {'value': x, 'ui_element': y} format are extracted."""
|
|
snapshot = {
|
|
"llm.provider.model": {"value": "gpt-4", "ui_element": "text"},
|
|
}
|
|
result = get_setting_from_snapshot(
|
|
"llm.provider",
|
|
settings_snapshot=snapshot,
|
|
)
|
|
assert isinstance(result, dict)
|
|
assert result["model"] == "gpt-4"
|
|
|
|
def test_child_keys_with_simplified_format(self):
|
|
"""Child keys as raw values (not dicts) pass through directly."""
|
|
snapshot = {
|
|
"app.settings.theme": "dark",
|
|
"app.settings.lang": "en",
|
|
}
|
|
result = get_setting_from_snapshot(
|
|
"app.settings",
|
|
settings_snapshot=snapshot,
|
|
)
|
|
assert result == {"theme": "dark", "lang": "en"}
|
|
|
|
def test_direct_key_takes_priority(self):
|
|
"""Direct key match is returned before child key search."""
|
|
snapshot = {
|
|
"key": "direct_value",
|
|
"key.child": "child_value",
|
|
}
|
|
result = get_setting_from_snapshot("key", settings_snapshot=snapshot)
|
|
assert result == "direct_value"
|
|
|
|
|
|
class TestGetSettingFromSnapshotValueExtraction:
|
|
def test_dict_with_value_key_extracted(self):
|
|
snapshot = {"my.setting": {"value": 42, "ui_element": "number"}}
|
|
result = get_setting_from_snapshot(
|
|
"my.setting", settings_snapshot=snapshot
|
|
)
|
|
assert result == 42
|
|
|
|
def test_dict_without_value_key_returned_as_is(self):
|
|
snapshot = {"my.setting": {"custom_field": "data"}}
|
|
result = get_setting_from_snapshot(
|
|
"my.setting", settings_snapshot=snapshot
|
|
)
|
|
assert result == {"custom_field": "data"}
|
|
|
|
def test_plain_value_returned_directly(self):
|
|
snapshot = {"my.setting": "plain_string"}
|
|
result = get_setting_from_snapshot(
|
|
"my.setting", settings_snapshot=snapshot
|
|
)
|
|
assert result == "plain_string"
|
|
|
|
|
|
class TestGetSettingFromSnapshotFallbacks:
|
|
def test_settings_context_fallback(self):
|
|
"""When snapshot doesn't have key, thread context is checked."""
|
|
mock_ctx = type(
|
|
"Ctx", (), {"get_setting": lambda s, k, d: "from_ctx"}
|
|
)()
|
|
|
|
with patch(f"{MODULE}._thread_local") as mock_tl:
|
|
mock_tl.settings_context = mock_ctx
|
|
result = get_setting_from_snapshot("missing.key")
|
|
|
|
assert result == "from_ctx"
|
|
|
|
def test_default_returned_when_nothing_found(self):
|
|
result = get_setting_from_snapshot(
|
|
"nonexistent.key",
|
|
default="fallback",
|
|
settings_snapshot={},
|
|
)
|
|
assert result == "fallback"
|
|
|
|
def test_raises_when_no_default_and_nothing_found(self):
|
|
with pytest.raises(NoSettingsContextError):
|
|
get_setting_from_snapshot(
|
|
"nonexistent.key",
|
|
settings_snapshot={},
|
|
)
|
|
|
|
|
|
class TestGetBoolSettingFromSnapshot:
|
|
def test_true_string(self):
|
|
snapshot = {"feature.enabled": "true"}
|
|
assert (
|
|
get_bool_setting_from_snapshot(
|
|
"feature.enabled", settings_snapshot=snapshot
|
|
)
|
|
is True
|
|
)
|
|
|
|
def test_false_string(self):
|
|
snapshot = {"feature.enabled": "false"}
|
|
assert (
|
|
get_bool_setting_from_snapshot(
|
|
"feature.enabled", settings_snapshot=snapshot
|
|
)
|
|
is False
|
|
)
|
|
|
|
def test_default_when_missing(self):
|
|
assert (
|
|
get_bool_setting_from_snapshot(
|
|
"missing.key", default=True, settings_snapshot={}
|
|
)
|
|
is True
|
|
)
|
|
|
|
def test_integer_one(self):
|
|
snapshot = {"flag": 1}
|
|
assert (
|
|
get_bool_setting_from_snapshot("flag", settings_snapshot=snapshot)
|
|
is True
|
|
)
|
|
|
|
def test_integer_zero(self):
|
|
snapshot = {"flag": 0}
|
|
assert (
|
|
get_bool_setting_from_snapshot("flag", settings_snapshot=snapshot)
|
|
is False
|
|
)
|
|
|
|
def test_bool_passthrough(self):
|
|
snapshot = {"flag": True}
|
|
assert (
|
|
get_bool_setting_from_snapshot("flag", settings_snapshot=snapshot)
|
|
is True
|
|
)
|
|
|
|
def test_yes_string(self):
|
|
snapshot = {"flag": "yes"}
|
|
assert (
|
|
get_bool_setting_from_snapshot("flag", settings_snapshot=snapshot)
|
|
is True
|
|
)
|
|
|
|
def test_on_string(self):
|
|
snapshot = {"flag": "on"}
|
|
assert (
|
|
get_bool_setting_from_snapshot("flag", settings_snapshot=snapshot)
|
|
is True
|
|
)
|