test(main): fix route-registration tests for FastAPI >=0.138 - #37
Merged
Merged
Conversation
FastAPI >=0.138 no longer flattens included routers into app.routes;
they become opaque _IncludedRouter wrappers without a .path attribute,
so `[r.path for r in app.routes]` raised AttributeError. CI resolves
deps fresh from PyPI, so it picked up FastAPI 0.138.x and these two
tests started failing (blocking the starlette and pydantic-settings
Dependabot PRs).
Assert HTTP routes against app.openapi()["paths"] and the WebSocket
route via app.url_path_for("websocket_live") — both public, version-
stable APIs. Verified passing on FastAPI 0.135.3 (locked) and 0.138.1.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016xQgiPUb99rkTtZHoFncEh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The backend Dependabot PRs (#33 starlette, #36 pydantic-settings) fail CI on two tests:
Root cause
This is not a problem with either dependency. CI installs the backend with
uv pip install -e ".[dev]", which ignoresuv.lockand resolves fresh from PyPI — so it picks up FastAPI 0.138.x. In 0.138,include_router()no longer flattens sub-routes intoapp.routes; instead it inserts opaque_IncludedRouterwrapper objects that have no.path. The tests did[r.path for r in app.routes], which now throws.Because the backend Dependabot PRs trigger backend CI (path-scoped), they surface the failure;
mainwould fail the same way if its backend CI re-ran.Fix
Assert against public, version-stable APIs instead of FastAPI's internal route objects:
app.openapi()["paths"]app.url_path_for("websocket_live")(WebSockets aren't in the OpenAPI schema)Deliberately avoids the private
_IncludedRouter/effective_route_contextsinternals — depending on those is what made the test brittle in the first place.Verification
test_main.pypasses on the locked FastAPI 0.135.3 / Starlette 1.0.1ruffcleanOnce merged, #33 and #36 just need a rebase to go green.
🤖 Generated with Claude Code