41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
|
|
"""Regressionstest: FastAPI-Route-Matching im Plugin-Router.
|
||
|
|
|
||
|
|
GET /{name} (d9aed51) wurde vor /active-manifests registriert und
|
||
|
|
verschluckte literale Routen: /plugins/active-manifests wurde als
|
||
|
|
Plugin-Name 'active-manifests' interpretiert → 404 → Frontend-Sidebar
|
||
|
|
ohne Plugin-Menüeinträge (nur statische Dashboard/Kontakte/System).
|
||
|
|
|
||
|
|
Fix: statische Routen werden vor dynamischen /{name} registriert.
|
||
|
|
"""
|
||
|
|
from fastapi.routing import APIRoute
|
||
|
|
|
||
|
|
from app.routes.plugins import router
|
||
|
|
|
||
|
|
|
||
|
|
def test_active_manifests_registered_before_dynamic_name_route():
|
||
|
|
"""active-manifests muss vor /{name} registriert sein (FastAPI matcht in Reihenfolge)."""
|
||
|
|
paths = [r.path for r in router.routes if isinstance(r, APIRoute)]
|
||
|
|
assert '/api/v1/plugins/active-manifests' in paths, 'active-manifests Route fehlt'
|
||
|
|
assert '/api/v1/plugins/{name}' in paths, '/{name} Route fehlt'
|
||
|
|
assert paths.index('/api/v1/plugins/active-manifests') < paths.index(
|
||
|
|
'/api/v1/plugins/{name}'
|
||
|
|
), (
|
||
|
|
'/active-manifests muss VOR /{name} registriert werden — '
|
||
|
|
'sonst matcht /{name} das Literal und liefert 404 '
|
||
|
|
'(Sidebar ohne Plugin-Menüeinträge)'
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def test_other_literal_routes_also_before_dynamic_name_route():
|
||
|
|
"""Alle literalen Unterrouten müssen vor /{name} registriert sein."""
|
||
|
|
literals = [
|
||
|
|
'/api/v1/plugins/manifest',
|
||
|
|
'/api/v1/plugins/updates',
|
||
|
|
'/api/v1/plugins/active-manifests',
|
||
|
|
]
|
||
|
|
paths = [r.path for r in router.routes if isinstance(r, APIRoute)]
|
||
|
|
name_idx = paths.index('/api/v1/plugins/{name}')
|
||
|
|
for lit in literals:
|
||
|
|
assert lit in paths, f'{lit} fehlt'
|
||
|
|
assert paths.index(lit) < name_idx, f'{lit} muss vor /{{name}} registriert sein'
|