Files
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

135 lines
4.0 KiB
Python

"""Tests for environment variable priority over database values.
This module tests that environment variables are always checked first,
even when the database value is None (e.g., on first launch).
Regression test for issue #870: LDR_WEB_PORT not respected on first launch.
"""
import os
import pytest
from local_deep_research.settings.manager import get_typed_setting_value
class TestEnvVarPriorityOverNoneDb:
"""Test that env vars are checked even when db value is None."""
@pytest.fixture(autouse=True)
def clean_env(self):
"""Clean environment before each test."""
original_env = {
k: v for k, v in os.environ.items() if k.startswith("LDR_")
}
for key in list(os.environ.keys()):
if key.startswith("LDR_"):
os.environ.pop(key, None)
yield
for key in list(os.environ.keys()):
if key.startswith("LDR_"):
os.environ.pop(key, None)
for key, value in original_env.items():
os.environ[key] = value
def test_env_var_used_when_db_value_is_none_number(self):
"""Test that number env var is used when database value is None.
This is the specific bug from #870 - LDR_WEB_PORT was not
respected on first launch because the code returned the default
immediately when the database value was None.
"""
os.environ["LDR_WEB_PORT"] = "8080"
result = get_typed_setting_value(
key="web.port",
value=None, # Simulates first launch, no value in DB
ui_element="number",
default=5000,
check_env=True,
)
assert result == 8080
def test_env_var_used_when_db_value_is_none_text(self):
"""Test that text env var is used when database value is None."""
os.environ["LDR_WEB_HOST"] = "127.0.0.1"
result = get_typed_setting_value(
key="web.host",
value=None,
ui_element="text",
default="0.0.0.0",
check_env=True,
)
assert result == "127.0.0.1"
def test_env_var_used_when_db_value_is_none_checkbox(self):
"""Test that boolean env var is used when database value is None."""
os.environ["LDR_APP_DEBUG"] = "true"
result = get_typed_setting_value(
key="app.debug",
value=None,
ui_element="checkbox",
default=False,
check_env=True,
)
assert result is True
def test_default_used_when_no_env_and_no_db(self):
"""Test that default is used when neither env nor db has value."""
result = get_typed_setting_value(
key="web.port",
value=None,
ui_element="number",
default=5000,
check_env=True,
)
assert result == 5000
def test_env_var_overrides_db_value(self):
"""Test that env var takes priority over database value."""
os.environ["LDR_WEB_PORT"] = "9000"
result = get_typed_setting_value(
key="web.port",
value=8080, # Value from database
ui_element="number",
default=5000,
check_env=True,
)
assert result == 9000
def test_db_value_used_when_check_env_false(self):
"""Test that db value is used when check_env is False."""
os.environ["LDR_WEB_PORT"] = "9000"
result = get_typed_setting_value(
key="web.port",
value=8080,
ui_element="number",
default=5000,
check_env=False,
)
assert result == 8080
def test_default_used_when_check_env_false_and_db_none(self):
"""Test that default is used when check_env=False and db value is None."""
os.environ["LDR_WEB_PORT"] = "9000"
result = get_typed_setting_value(
key="web.port",
value=None,
ui_element="number",
default=5000,
check_env=False,
)
assert result == 5000