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

131 lines
4.5 KiB
Python

"""Coverage tests for route_registry.py targeting ~4 missing statements.
Uncovered functions/branches:
- get_routes_by_blueprint: blueprint not found returns []
- find_route: pattern matching
- get_all_routes: prefix handling when prefix is None
- ROUTE_REGISTRY constant structure and blueprint metadata
- endpoint format (blueprint.endpoint)
- prefix concatenation correctness
"""
from local_deep_research.web.routes.route_registry import (
ROUTE_REGISTRY,
find_route,
get_all_routes,
get_routes_by_blueprint,
)
MODULE = "local_deep_research.web.routes.route_registry"
class TestGetRoutesByBlueprint:
"""Tests for get_routes_by_blueprint."""
def test_unknown_blueprint_returns_empty(self):
"""Non-existent blueprint returns empty list."""
assert get_routes_by_blueprint("nonexistent_bp") == []
def test_known_blueprint_returns_routes(self):
"""Known blueprint returns non-empty route list."""
routes = get_routes_by_blueprint("research")
assert len(routes) > 0
assert all("method" in r for r in routes)
assert all("path" in r for r in routes)
class TestGetAllRoutes:
"""Tests for get_all_routes."""
def test_returns_routes_from_all_blueprints(self):
"""Returns routes from every registered blueprint."""
routes = get_all_routes()
blueprints = {r["blueprint"] for r in routes}
assert len(blueprints) == len(ROUTE_REGISTRY)
def test_prefix_none_produces_root_paths(self):
"""Blueprints with url_prefix=None produce root-level paths."""
routes = get_all_routes()
research_routes = [r for r in routes if r["blueprint"] == "research"]
assert any(r["path"] == "/" for r in research_routes)
class TestFindRoute:
"""Tests for find_route."""
def test_find_existing_pattern(self):
"""Matching pattern returns results."""
results = find_route("/api/start")
assert len(results) > 0
def test_find_nonexistent_pattern(self):
"""Non-matching pattern returns empty list."""
results = find_route("/zzz_nonexistent_route_zzz")
assert results == []
def test_case_insensitive(self):
"""Search is case-insensitive."""
upper = find_route("/API/HEALTH")
lower = find_route("/api/health")
assert len(upper) == len(lower)
# ---------------------------------------------------------------------------
# Additional deep-coverage tests
# ---------------------------------------------------------------------------
class TestRouteRegistryAllBlueprintsPresent:
"""Verify all expected blueprints appear in the registry."""
EXPECTED = {"research", "api_v1", "history", "settings", "metrics"}
def test_expected_blueprints_all_registered(self):
for bp in self.EXPECTED:
assert bp in ROUTE_REGISTRY, f"Blueprint '{bp}' missing"
def test_each_blueprint_has_nonempty_routes(self):
for bp_name, bp_info in ROUTE_REGISTRY.items():
assert len(bp_info["routes"]) > 0, f"'{bp_name}' has no routes"
class TestGetAllRoutesEndpointFormat:
"""Endpoints returned by get_all_routes() must be blueprint-qualified."""
def test_endpoint_has_dot_separator(self):
for route in get_all_routes():
assert "." in route["endpoint"], (
f"Endpoint '{route['endpoint']}' not in blueprint.name format"
)
def test_api_v1_routes_prefixed_correctly(self):
api_routes = [r for r in get_all_routes() if r["blueprint"] == "api_v1"]
assert len(api_routes) > 0
for route in api_routes:
assert route["path"].startswith("/api/v1")
def test_settings_routes_prefixed_correctly(self):
settings_routes = [
r for r in get_all_routes() if r["blueprint"] == "settings"
]
assert len(settings_routes) > 0
for route in settings_routes:
assert route["path"].startswith("/settings")
class TestGetRoutesByBlueprintDeep:
"""Deeper checks for get_routes_by_blueprint."""
def test_settings_routes_have_all_required_keys(self):
required = {"method", "path", "endpoint", "description"}
for route in get_routes_by_blueprint("settings"):
assert required <= set(route.keys())
def test_metrics_routes_have_metrics_prefix(self):
for route in get_routes_by_blueprint("metrics"):
assert route["path"].startswith("/metrics")
def test_history_routes_have_history_prefix(self):
for route in get_routes_by_blueprint("history"):
assert route["path"].startswith("/history")