Files
amnezia-web-panel/tests/test_route_uniqueness.py
hell 5a06a713a1 fix(api): register the protocol rename route once
The merge left two handlers on POST /api/servers/{server_id}/protocol/rename.
Starlette matches in definition order, so the first one won and the copy that
caps the name at CUSTOM_PROTOCOL_NAME_MAX and strips the protocol key never
ran - the cap added in #144 was silently dead, and /docs showed the endpoint
twice. Kept the capped handler.

tests/test_route_uniqueness.py now fails on any duplicate (path, method).
2026-09-10 00:17:22 +07:00

27 lines
914 B
Python

"""No two handlers may claim the same path and method.
Starlette matches routes in definition order, so a second registration of the
same (path, method) is dead code that the OpenAPI schema still advertises. A
merge produced exactly that for POST /api/servers/{id}/protocol/rename: the
copy with the length cap never ran.
"""
import collections
import unittest
import app as panel
class RouteUniquenessTests(unittest.TestCase):
def test_every_path_and_method_is_registered_once(self):
seen = collections.Counter()
for route in panel.app.routes:
for method in getattr(route, 'methods', None) or []:
seen[(getattr(route, 'path', ''), method)] += 1
duplicates = sorted(key for key, count in seen.items() if count > 1)
self.assertEqual(duplicates, [], f"duplicate route registrations: {duplicates}")
if __name__ == '__main__':
unittest.main()