learningcircuit--local-deep-research
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
84 行
2.9 KiB
Python
84 行
2.9 KiB
Python
"""Coverage for _validate_subscription_policy (PR #4300 review).
|
|
|
|
News subscriptions persist a fixed engine + LLM provider that run on a
|
|
schedule. This validator rejects a forbidden config at create/update time
|
|
(the factory PEP is only the execution-time backstop). Returns a
|
|
human-readable reason string on rejection, or None when allowed / when the
|
|
settings backend is unavailable (best-effort).
|
|
|
|
Source: src/local_deep_research/news/api.py
|
|
"""
|
|
|
|
from unittest.mock import Mock, patch
|
|
|
|
from local_deep_research.news.api import _validate_subscription_policy
|
|
|
|
|
|
def _mgr(snapshot, primary="arxiv"):
|
|
m = Mock()
|
|
m.get_settings_snapshot.return_value = snapshot
|
|
m.get_setting.side_effect = lambda key, default=None: (
|
|
primary if key == "search.tool" else default
|
|
)
|
|
return m
|
|
|
|
|
|
def _patch_mgr(manager):
|
|
return patch(
|
|
"local_deep_research.utilities.db_utils.get_settings_manager",
|
|
return_value=manager,
|
|
)
|
|
|
|
|
|
class TestValidateSubscriptionPolicy:
|
|
def test_allowed_engine_returns_none(self):
|
|
with _patch_mgr(_mgr({"policy.egress_scope": "public_only"})):
|
|
assert (
|
|
_validate_subscription_policy(Mock(), "u", "arxiv", None)
|
|
is None
|
|
)
|
|
|
|
def test_forbidden_engine_returns_reason(self):
|
|
# PUBLIC_ONLY + local engine (library) => rejected.
|
|
with _patch_mgr(_mgr({"policy.egress_scope": "public_only"})):
|
|
reason = _validate_subscription_policy(Mock(), "u", "library", None)
|
|
assert reason is not None
|
|
assert "not permitted" in reason
|
|
|
|
def test_corrupt_scope_returns_reason(self):
|
|
with _patch_mgr(_mgr({"policy.egress_scope": "garbage"})):
|
|
reason = _validate_subscription_policy(Mock(), "u", "arxiv", None)
|
|
assert reason is not None
|
|
assert "egress policy refused" in reason
|
|
|
|
def test_cloud_llm_provider_denied_under_require_local(self):
|
|
# require_local_llm + a cloud provider => provider rejected.
|
|
snap = {
|
|
"policy.egress_scope": "both",
|
|
"llm.require_local_endpoint": True,
|
|
}
|
|
with _patch_mgr(_mgr(snap)):
|
|
reason = _validate_subscription_policy(Mock(), "u", None, "openai")
|
|
assert reason is not None
|
|
assert "provider" in reason.lower()
|
|
|
|
def test_non_dict_snapshot_skips(self):
|
|
# Settings backend unavailable => best-effort skip (None).
|
|
with _patch_mgr(_mgr(None)):
|
|
assert (
|
|
_validate_subscription_policy(Mock(), "u", "library", None)
|
|
is None
|
|
)
|
|
|
|
def test_local_llm_provider_allowed_under_require_local(self):
|
|
snap = {
|
|
"policy.egress_scope": "both",
|
|
"llm.require_local_endpoint": True,
|
|
}
|
|
with _patch_mgr(_mgr(snap)):
|
|
# ollama is a localhost-default provider => allowed.
|
|
assert (
|
|
_validate_subscription_policy(Mock(), "u", None, "ollama")
|
|
is None
|
|
)
|