Skip to content

test: stabilize route assertions for FastAPI 0.137#8783

Open
he-yufeng wants to merge 1 commit into
AstrBotDevs:masterfrom
he-yufeng:fix/fastapi-route-test-compat
Open

test: stabilize route assertions for FastAPI 0.137#8783
he-yufeng wants to merge 1 commit into
AstrBotDevs:masterfrom
he-yufeng:fix/fastapi-route-test-compat

Conversation

@he-yufeng

@he-yufeng he-yufeng commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

The current dependency range allows FastAPI 0.137.0 / Starlette 1.3.1 in CI. With that stack, these two route-registration tests can fail because they inspect app.router.routes internals directly: FastAPI now keeps included routers behind _IncludedRouter, which has no path attribute and can hide routes from the flat list.

The routes themselves are still registered and resolvable through FastAPI's public url_path_for() API, so this keeps the tests focused on the intended behavior: the expected aliases are mounted at the expected paths.

Modifications / 改动点

  • Assert the route aliases through app.url_path_for() instead of scanning route object class names / path attributes directly.

  • Keep the change limited to tests/test_fastapi_v1_dashboard.py.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Verification run locally:

python -m py_compile tests\test_fastapi_v1_dashboard.py
python -m ruff check tests\test_fastapi_v1_dashboard.py
python -m ruff format --check tests\test_fastapi_v1_dashboard.py
python -m pytest tests\test_fastapi_v1_dashboard.py -q -p no:cacheprovider
uv run python -c "import fastapi, starlette, pytest; print('fastapi', fastapi.__version__); print('starlette', starlette.__version__); print('pytest', pytest.__version__)"
uv run python -m pytest tests\test_fastapi_v1_dashboard.py -q -p no:cacheprovider

The uv run environment resolved the same relevant versions seen in CI:

fastapi 0.137.0
starlette 1.3.1
pytest 9.1.0

Both pytest runs passed:

52 passed

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc. / No new feature; test compatibility only.
  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 My changes do not introduce malicious code.

Summary by Sourcery

Stabilize FastAPI v1 dashboard tests against internal routing changes by asserting routes via FastAPI’s public URL resolution API.

Tests:

  • Add a helper to resolve route paths via app.url_path_for and update websocket and dashboard alias tests to assert on named routes instead of inspecting router internals.
  • Tidy a type-hint assertion in the plugin request proxy tests for consistency.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. labels Jun 14, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the FastAPI dashboard tests by introducing a helper function _path_for to resolve route paths by their registered names. It updates test_v1_openapi_alias_websocket_routes_are_mounted and test_dashboard_config_aliases_are_registered_on_fastapi to use this helper, which simplifies the assertions and ensures route names are correctly configured. Additionally, a long assertion in test_astrbot_web_request_proxy_exposes_typed_methods was reformatted for readability. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@zouyonghe zouyonghe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed. This is a focused test-only compatibility fix and uses FastAPI public url_path_for API instead of inspecting router internals that changed in FastAPI 0.137. CI is green, and this also explains the unrelated full pytest failures on other open PRs.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants