fix(proxy): scope wildcard cleanup to subpath entries and restore registry in test

- Only remove wildcard path from openai_routes when the route entry has
  type="subpath", avoiding accidental removal when two endpoints share
  the same base path but differ in include_subpath
- Clean up _registered_pass_through_routes in the test finally block to
  prevent stale entries from polluting subsequent tests on failure
This commit is contained in:
Sameer Kankute 2026-03-19 09:53:22 +05:30
parent 97b7358791
commit ab1744f9fe
2 changed files with 11 additions and 4 deletions

View file

@ -2033,13 +2033,13 @@ class InitPassThroughEndpointHelpers:
route_info = _registered_pass_through_routes[key]
path = route_info.get("path")
if isinstance(path, str):
# Remove base path and wildcard path from openai_routes
openai_routes = LiteLLMRoutes.openai_routes.value
if path in openai_routes:
openai_routes.remove(path)
wildcard_path = path.rstrip("/") + "/*"
if wildcard_path in openai_routes:
openai_routes.remove(wildcard_path)
if route_info.get("type") == "subpath":
wildcard_path = path.rstrip("/") + "/*"
if wildcard_path in openai_routes:
openai_routes.remove(wildcard_path)
del _registered_pass_through_routes[key]
verbose_proxy_logger.debug(
"Removed pass-through route from registry: %s", key

View file

@ -1397,3 +1397,10 @@ async def test_initialize_pass_through_registers_wildcard_for_auth_subpath():
assert wildcard_path not in LiteLLMRoutes.openai_routes.value
finally:
LiteLLMRoutes.openai_routes.value[:] = original_routes
# Clean up any routes registered during this test to avoid
# polluting the module-level _registered_pass_through_routes
registered = InitPassThroughEndpointHelpers.get_all_registered_pass_through_routes()
for k in registered:
InitPassThroughEndpointHelpers.remove_endpoint_routes(
k.split(":")[0]
)