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

158 lines
4.7 KiB
Python

"""High-value tests for settings/env_definitions/bootstrap.py.
Tests the BOOTSTRAP_SETTINGS list: SecretSetting, StringSetting,
BooleanSetting, PathSetting instances, their keys, defaults, and types.
"""
import pytest
from local_deep_research.settings.env_definitions.bootstrap import (
BOOTSTRAP_SETTINGS,
)
from local_deep_research.settings.env_settings import (
BooleanSetting,
StringSetting,
PathSetting,
SecretSetting,
SettingsRegistry,
)
def _find(key: str):
"""Return the setting object with the given key."""
for s in BOOTSTRAP_SETTINGS:
if s.key == key:
return s
raise KeyError(f"Setting {key!r} not found in BOOTSTRAP_SETTINGS")
class TestBootstrapRegistry:
"""Tests for BOOTSTRAP_SETTINGS structure."""
def test_setting_count(self):
"""BOOTSTRAP_SETTINGS has the expected number of entries."""
assert len(BOOTSTRAP_SETTINGS) == 8
def test_all_keys_start_with_bootstrap(self):
"""Every key uses the 'bootstrap.' prefix."""
for s in BOOTSTRAP_SETTINGS:
assert s.key.startswith("bootstrap."), f"{s.key} missing prefix"
def test_register_all_settings(self):
"""All settings can be registered under the bootstrap category."""
registry = SettingsRegistry()
registry.register_category("bootstrap", BOOTSTRAP_SETTINGS)
for s in BOOTSTRAP_SETTINGS:
assert registry.is_env_only(s.key)
class TestEncryptionKey:
"""Tests for bootstrap.encryption_key."""
def test_is_secret_setting(self):
s = _find("bootstrap.encryption_key")
assert isinstance(s, SecretSetting)
def test_not_required(self):
"""encryption_key is not required (allow_unencrypted may be True)."""
s = _find("bootstrap.encryption_key")
assert s.required is False
class TestSecretKey:
"""Tests for bootstrap.secret_key."""
def test_is_secret_setting(self):
s = _find("bootstrap.secret_key")
assert isinstance(s, SecretSetting)
class TestDatabaseUrl:
"""Tests for bootstrap.database_url."""
def test_is_string_setting(self):
s = _find("bootstrap.database_url")
assert isinstance(s, StringSetting)
class TestAllowUnencrypted:
"""Tests for bootstrap.allow_unencrypted."""
def test_is_boolean_setting(self):
s = _find("bootstrap.allow_unencrypted")
assert isinstance(s, BooleanSetting)
def test_default_is_false(self, monkeypatch):
"""Default value is False (require encryption)."""
s = _find("bootstrap.allow_unencrypted")
monkeypatch.delenv(s.env_var, raising=False)
if s.deprecated_env_var:
monkeypatch.delenv(s.deprecated_env_var, raising=False)
assert s.get_value() is False
def test_deprecated_alias(self):
"""Has deprecated env var LDR_ALLOW_UNENCRYPTED."""
s = _find("bootstrap.allow_unencrypted")
assert s.deprecated_env_var == "LDR_ALLOW_UNENCRYPTED"
def test_set_to_true(self, monkeypatch):
"""Can be set to True via env var."""
s = _find("bootstrap.allow_unencrypted")
monkeypatch.setenv(s.env_var, "true")
assert s.get_value() is True
def test_set_to_false(self, monkeypatch):
"""Can be set to False via env var."""
s = _find("bootstrap.allow_unencrypted")
monkeypatch.setenv(s.env_var, "false")
assert s.get_value() is False
class TestPathSettings:
"""Tests for bootstrap path settings."""
@pytest.mark.parametrize(
"key",
[
"bootstrap.data_dir",
"bootstrap.config_dir",
"bootstrap.log_dir",
],
)
def test_is_path_setting(self, key):
s = _find(key)
assert isinstance(s, PathSetting)
@pytest.mark.parametrize(
"key",
[
"bootstrap.data_dir",
"bootstrap.config_dir",
"bootstrap.log_dir",
],
)
def test_create_if_missing_is_true(self, key):
"""Path settings should create directories if missing."""
s = _find(key)
assert s.create_if_missing is True
class TestEnableFileLogging:
"""Tests for bootstrap.enable_file_logging."""
def test_is_boolean_setting(self):
s = _find("bootstrap.enable_file_logging")
assert isinstance(s, BooleanSetting)
def test_default_is_false(self, monkeypatch):
"""Default value is False."""
s = _find("bootstrap.enable_file_logging")
monkeypatch.delenv(s.env_var, raising=False)
assert s.get_value() is False
def test_set_to_true(self, monkeypatch):
"""Can be enabled via env var."""
s = _find("bootstrap.enable_file_logging")
monkeypatch.setenv(s.env_var, "true")
assert s.get_value() is True