Files
ss-tools/backend/tests/api/test_scenario_wire_routes.py

65 lines
3.2 KiB
Python

# #region Test.Api.ScenarioWireRoutes [C:3] [TYPE Module] [SEMANTICS test,api,scenario,wire,routes,prefix]
# @BRIEF Integration assertion on the real generated FastAPI app routes: scenario-analytics and
# scenario-automation must be served under /api/... exactly as the frontend calls them,
# and the legacy bare-prefix routes (/scenario-analytics, /scenario-automation) must not
# be registered anywhere in the app.
# @RELATION BINDS_TO -> [Api.ScenarioAnalytics.Routes]
# @RELATION BINDS_TO -> [Api.ScenarioAutomation.Routes]
# @TEST_EDGE legacy_prefix_absent -> bare /scenario-* paths never match a registered route
from __future__ import annotations
from src.app import app
def _route_paths() -> set[str]:
return {getattr(route, "path", "") for route in app.routes}
# #region Test.Api.ScenarioWireRoutes.TestGeneratedAppRoutes [C:2] [TYPE Class] [SEMANTICS test,api,wire,generated]
# @BRIEF Assert the app's generated route table contains the /api/... wire paths used by the frontend.
class TestGeneratedAppRoutes:
def test_scenario_analytics_routes_are_under_api(self) -> None:
paths = _route_paths()
for expected in {
"/api/scenario-analytics/queue",
"/api/scenario-analytics/cases/{case_id}",
"/api/scenario-analytics/cases/{case_id}/disposition",
"/api/scenario-analytics/scenarios/{scenario_id}/health",
"/api/scenario-analytics/scenarios/{scenario_id}/trends",
"/api/scenario-analytics/scenarios/{scenario_id}/recurring-failures",
}:
assert expected in paths, f"missing generated route {expected}"
def test_scenario_automation_routes_are_under_api(self) -> None:
paths = _route_paths()
for expected in {
"/api/scenario-automation/schedules",
"/api/scenario-automation/trigger-rules",
"/api/scenario-automation/policies",
"/api/scenario-automation/metrics",
"/api/scenario-automation/notifications",
"/api/scenario-automation/retention",
"/api/scenario-automation/scenarios/{scenario_id}/trigger",
}:
assert expected in paths, f"missing generated route {expected}"
def test_direct_trigger_path_matches_frontend_wire(self) -> None:
# Frontend: fetchApi(`${BASE}/scenarios/${scenarioId}/trigger`) with BASE="/scenario-automation"
# and API_BASE_URL="/api" -> real request path /api/scenario-automation/scenarios/{id}/trigger.
paths = _route_paths()
assert "/api/scenario-automation/scenarios/{scenario_id}/trigger" in paths
assert "/api/scenario-automation/scenarios/{scenario_id}/trigger" in {
getattr(route, "path", "") for route in app.routes if route.path.endswith("/trigger")
}
def test_legacy_bare_prefixes_are_not_registered(self) -> None:
paths = _route_paths()
for legacy in (
"/scenario-analytics/queue",
"/scenario-automation/schedules",
"/scenario-automation/scenarios/{scenario_id}/trigger",
):
assert legacy not in paths, f"legacy bare-prefix route still registered: {legacy}"
# #endregion Test.Api.ScenarioWireRoutes.TestGeneratedAppRoutes
# #endregion Test.Api.ScenarioWireRoutes