Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.9 KB
Raw Blame
"""No static route may be shadowed by an earlier parameterized route.

FastAPI/Starlette match routes in registration order. A parameterized
route like ``/collections/{collection_id}`` registered before its static
sibling ``/collections/create`` swallows the static path (the literal
``create`` binds to ``collection_id``) and serves the wrong page — this
shipped as a real bug: /library/collections/create rendered the
collection-DETAILS page, so the create form never appeared (found by the
Puppeteer api-crud shard).

This walks the live route table and fails when any static path would be
captured by an earlier route's pattern for an overlapping HTTP method.
"""

from fastapi.routing import APIRoute

from local_deep_research.web.fastapi_app import app


def test_no_static_route_shadowed_by_earlier_param_route():
    api_routes = [r for r in app.routes if isinstance(r, APIRoute)]

    shadowed = []
    for later_idx, later in enumerate(api_routes):
        if "{" in later.path:
            continue  # only static paths can be swallowed whole
        for earlier in api_routes[:later_idx]:
            if "{" not in earlier.path:
                continue  # static-vs-static duplicates are a different bug
            if not (earlier.methods & later.methods):
                continue
            match = earlier.path_regex.match(later.path)
            if match:
                shadowed.append(
                    f"{sorted(later.methods)} {later.path} is unreachable: "
                    f"registered after {earlier.path}, whose pattern "
                    f"captures it as {match.groupdict()}"
                )

    assert not shadowed, (
        "Static route(s) shadowed by an earlier parameterized route — "
        "FastAPI matches in registration order, so these can never be "
        "reached. Register the static route BEFORE its parameterized "
        "sibling:\n  " + "\n  ".join(shadowed)
    )