7a0da7932b
Backwards Compatibility / Verify Encryption Constants (push) Waiting to run
Backwards Compatibility / PyPI Version Compatibility (push) Waiting to run
Backwards Compatibility / Database Migration Tests (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Blocked by required conditions
Docker Tests (Consolidated) / detect-changes (push) Waiting to run
Docker Tests (Consolidated) / Build Test Image (push) Waiting to run
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Blocked by required conditions
Docker Tests (Consolidated) / Accessibility Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Unit Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Example Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / Production Image Smoke Test (push) Blocked by required conditions
Docker Tests (Consolidated) / Infrastructure Tests (push) Blocked by required conditions
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Waiting to run
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
182 lines
6.1 KiB
Python
182 lines
6.1 KiB
Python
"""Tests for server_config.py uncovered branches."""
|
|
|
|
import json
|
|
from unittest.mock import patch
|
|
|
|
from local_deep_research.web.server_config import (
|
|
_DEFAULTS,
|
|
_load_legacy_config,
|
|
has_legacy_customizations,
|
|
load_server_config,
|
|
)
|
|
|
|
|
|
class TestHasLegacyCustomizations:
|
|
def test_no_file_returns_false(self, tmp_path):
|
|
assert has_legacy_customizations(tmp_path / "missing.json") is False
|
|
|
|
def test_invalid_json_returns_false(self, tmp_path):
|
|
p = tmp_path / "bad.json"
|
|
p.write_text("not json{{{", encoding="utf-8")
|
|
assert has_legacy_customizations(p) is False
|
|
|
|
def test_non_dict_json_returns_false(self, tmp_path):
|
|
p = tmp_path / "list.json"
|
|
p.write_text("[1,2,3]", encoding="utf-8")
|
|
assert has_legacy_customizations(p) is False
|
|
|
|
def test_all_defaults_returns_false(self, tmp_path):
|
|
p = tmp_path / "config.json"
|
|
p.write_text(json.dumps(_DEFAULTS), encoding="utf-8")
|
|
assert has_legacy_customizations(p) is False
|
|
|
|
def test_non_default_value_returns_true(self, tmp_path):
|
|
p = tmp_path / "config.json"
|
|
data = {"port": 9999}
|
|
p.write_text(json.dumps(data), encoding="utf-8")
|
|
assert has_legacy_customizations(p) is True
|
|
|
|
def test_unrecognized_key_returns_true(self, tmp_path):
|
|
p = tmp_path / "config.json"
|
|
data = {"unknown_key": "value"}
|
|
p.write_text(json.dumps(data), encoding="utf-8")
|
|
assert has_legacy_customizations(p) is True
|
|
|
|
def test_empty_dict_returns_false(self, tmp_path):
|
|
p = tmp_path / "config.json"
|
|
p.write_text("{}", encoding="utf-8")
|
|
assert has_legacy_customizations(p) is False
|
|
|
|
|
|
class TestLoadLegacyConfig:
|
|
def test_no_file_returns_empty(self, tmp_path):
|
|
with patch(
|
|
"local_deep_research.web.server_config.get_server_config_path",
|
|
return_value=tmp_path / "missing.json",
|
|
):
|
|
assert _load_legacy_config() == {}
|
|
|
|
def test_invalid_json_returns_empty(self, tmp_path):
|
|
p = tmp_path / "bad.json"
|
|
p.write_text("{broken", encoding="utf-8")
|
|
with patch(
|
|
"local_deep_research.web.server_config.get_server_config_path",
|
|
return_value=p,
|
|
):
|
|
assert _load_legacy_config() == {}
|
|
|
|
def test_non_dict_returns_empty(self, tmp_path):
|
|
p = tmp_path / "list.json"
|
|
p.write_text('"just a string"', encoding="utf-8")
|
|
with patch(
|
|
"local_deep_research.web.server_config.get_server_config_path",
|
|
return_value=p,
|
|
):
|
|
assert _load_legacy_config() == {}
|
|
|
|
def test_recognized_keys_extracted(self, tmp_path):
|
|
p = tmp_path / "config.json"
|
|
p.write_text(
|
|
json.dumps({"host": "localhost", "port": 8080}), encoding="utf-8"
|
|
)
|
|
with patch(
|
|
"local_deep_research.web.server_config.get_server_config_path",
|
|
return_value=p,
|
|
):
|
|
result = _load_legacy_config()
|
|
assert result["host"] == "localhost"
|
|
assert result["port"] == 8080
|
|
|
|
def test_unrecognized_keys_ignored(self, tmp_path):
|
|
p = tmp_path / "config.json"
|
|
p.write_text(
|
|
json.dumps({"host": "localhost", "bogus_key": "val"}),
|
|
encoding="utf-8",
|
|
)
|
|
with patch(
|
|
"local_deep_research.web.server_config.get_server_config_path",
|
|
return_value=p,
|
|
):
|
|
result = _load_legacy_config()
|
|
assert "host" in result
|
|
assert "bogus_key" not in result
|
|
|
|
|
|
class TestLoadServerConfig:
|
|
def test_returns_all_expected_keys(self):
|
|
with patch(
|
|
"local_deep_research.web.server_config._load_legacy_config",
|
|
return_value={},
|
|
):
|
|
config = load_server_config()
|
|
for key in _DEFAULTS:
|
|
assert key in config
|
|
|
|
def test_defaults_when_no_legacy_no_env(self):
|
|
with (
|
|
patch(
|
|
"local_deep_research.web.server_config._load_legacy_config",
|
|
return_value={},
|
|
),
|
|
patch.dict("os.environ", {}, clear=False),
|
|
):
|
|
# Remove any LDR_ env vars
|
|
import os
|
|
|
|
env_clean = {
|
|
k: v for k, v in os.environ.items() if not k.startswith("LDR_")
|
|
}
|
|
with patch.dict("os.environ", env_clean, clear=True):
|
|
config = load_server_config()
|
|
assert config["port"] in (5000, _DEFAULTS["port"])
|
|
|
|
def test_unrecognized_allow_registrations_env_defaults_false(self):
|
|
with (
|
|
patch(
|
|
"local_deep_research.web.server_config._load_legacy_config",
|
|
return_value={},
|
|
),
|
|
patch.dict(
|
|
"os.environ",
|
|
{"LDR_APP_ALLOW_REGISTRATIONS": "nein"},
|
|
clear=False,
|
|
),
|
|
):
|
|
config = load_server_config()
|
|
assert config["allow_registrations"] is False
|
|
|
|
def test_recognized_allow_registrations_env_passes(self):
|
|
with (
|
|
patch(
|
|
"local_deep_research.web.server_config._load_legacy_config",
|
|
return_value={},
|
|
),
|
|
patch.dict(
|
|
"os.environ",
|
|
{"LDR_APP_ALLOW_REGISTRATIONS": "true"},
|
|
clear=False,
|
|
),
|
|
):
|
|
config = load_server_config()
|
|
# Should be True (recognized value)
|
|
assert config["allow_registrations"] is True
|
|
|
|
def test_legacy_unrecognized_allow_registrations_string(self):
|
|
with (
|
|
patch(
|
|
"local_deep_research.web.server_config._load_legacy_config",
|
|
return_value={"allow_registrations": "disabled"},
|
|
),
|
|
patch.dict("os.environ", {}, clear=False),
|
|
):
|
|
import os
|
|
|
|
env_clean = {
|
|
k: v
|
|
for k, v in os.environ.items()
|
|
if k != "LDR_APP_ALLOW_REGISTRATIONS"
|
|
}
|
|
with patch.dict("os.environ", env_clean, clear=True):
|
|
config = load_server_config()
|
|
assert config["allow_registrations"] is False
|