Files
learningcircuit--local-deep…/tests/config/test_thread_settings_child_keys.py
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

194 lines
6.6 KiB
Python

"""
Tests for get_setting_from_snapshot() child key search logic
in config/thread_settings.py.
Tests cover:
- Exact key match (full and simplified format)
- Child key aggregation (prefix.suffix → {suffix: value})
- Multiple child keys
- NoSettingsContextError when no default and no match
- Default returned when key missing
"""
import pytest
class TestGetSettingFromSnapshotExactMatch:
"""Tests for exact key matching in get_setting_from_snapshot()."""
def test_exact_key_full_format(self):
"""Exact key match with full format dict extracts typed value."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
snapshot = {"search.engine": {"value": "google", "ui_element": "text"}}
result = get_setting_from_snapshot(
"search.engine", settings_snapshot=snapshot
)
assert result == "google"
def test_exact_key_simplified_format(self):
"""Exact key match with simplified value returns value directly."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
snapshot = {"search.engine": "google"}
result = get_setting_from_snapshot(
"search.engine", settings_snapshot=snapshot
)
assert result == "google"
def test_exact_key_integer_value(self):
"""Exact key with integer value works."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
snapshot = {"max_results": 50}
result = get_setting_from_snapshot(
"max_results", settings_snapshot=snapshot
)
assert result == 50
def test_exact_key_boolean_value(self):
"""Exact key with boolean value works."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
snapshot = {"enabled": True}
result = get_setting_from_snapshot(
"enabled", settings_snapshot=snapshot
)
assert result is True
class TestGetSettingFromSnapshotChildKeys:
"""Tests for child key aggregation logic."""
def test_single_child_key(self):
"""Single child key builds a dict with just that suffix."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
snapshot = {"search.engine": "google"}
result = get_setting_from_snapshot("search", settings_snapshot=snapshot)
assert isinstance(result, dict)
assert result["engine"] == "google"
def test_multiple_child_keys(self):
"""Multiple child keys are aggregated into one dict."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
snapshot = {
"search.engine": "google",
"search.timeout": 30,
"search.retries": 3,
}
result = get_setting_from_snapshot("search", settings_snapshot=snapshot)
assert result == {"engine": "google", "timeout": 30, "retries": 3}
def test_child_keys_full_format(self):
"""Child keys with full format dicts extract values."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
snapshot = {
"search.engine": {"value": "bing", "ui_element": "text"},
}
result = get_setting_from_snapshot("search", settings_snapshot=snapshot)
assert isinstance(result, dict)
assert result["engine"] == "bing"
def test_no_child_keys_match(self):
"""No child keys match → falls through to default/error."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
snapshot = {"other.key": "value"}
result = get_setting_from_snapshot(
"search", default="fallback", settings_snapshot=snapshot
)
assert result == "fallback"
def test_child_keys_not_confused_with_partial_prefix(self):
"""Key 'search_extra.foo' should NOT match prefix 'search.'."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
snapshot = {
"search_extra.engine": "nope",
"search.engine": "yes",
}
result = get_setting_from_snapshot("search", settings_snapshot=snapshot)
assert result == {"engine": "yes"}
class TestGetSettingFromSnapshotDefaults:
"""Tests for default values and error raising."""
def test_default_returned_when_key_missing(self):
"""When key not in snapshot and default given, return default."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
result = get_setting_from_snapshot(
"nonexistent", default=42, settings_snapshot={"other": "val"}
)
assert result == 42
def test_no_settings_context_error_no_default(self):
"""No snapshot match, no context, no default → NoSettingsContextError."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
NoSettingsContextError,
)
with pytest.raises(NoSettingsContextError):
get_setting_from_snapshot(
"missing_key", settings_snapshot={"other": "val"}
)
def test_none_default_still_raises(self):
"""default=None (the default) still raises NoSettingsContextError."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
NoSettingsContextError,
)
with pytest.raises(NoSettingsContextError):
get_setting_from_snapshot(
"missing_key", default=None, settings_snapshot={"other": "val"}
)
def test_empty_snapshot_with_default(self):
"""Empty snapshot with default returns the default."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
result = get_setting_from_snapshot(
"key", default="default_val", settings_snapshot={}
)
assert result == "default_val"
def test_none_snapshot_with_default(self):
"""None snapshot with default returns the default."""
from local_deep_research.config.thread_settings import (
get_setting_from_snapshot,
)
result = get_setting_from_snapshot(
"key", default="fallback", settings_snapshot=None
)
assert result == "fallback"