Skip to content

test: cover middleware on composed app - #254

Open
SabrinaTso wants to merge 1 commit into
NTHU-SA:mainfrom
SabrinaTso:test/cors-middleware-regression
Open

test: cover middleware on composed app#254
SabrinaTso wants to merge 1 commit into
NTHU-SA:mainfrom
SabrinaTso:test/cors-middleware-regression

Conversation

@SabrinaTso

Copy link
Copy Markdown

Internal

  • Add regression tests for the public composed ASGI application.
  • Cover browser CORS preflight and an actual request retaining both CORS and X-Process-Time middleware.

Notes

  • This is intentionally a test-first PR. On current main, pytest tests/test_app_middleware.py -q fails with:
    • OPTIONS /openapi.json returning 405 instead of a CORS preflight response.
    • GET /openapi.json missing Access-Control-Allow-Origin.
  • No app-composition or middleware implementation is included. Maintainers can choose the appropriate composition approach while preserving FastMCP's lifespan and the REST application's middleware behavior.
  • The tests use the exported data_api.api.api.app and /openapi.json, so they do not depend on crawled campus data or external network access.

@sonarqubecloud

Copy link
Copy Markdown

@SabrinaTso

Copy link
Copy Markdown
Author

Hi @l7wei — I opened #254 as a test-first reproduction for the public composed ASGI app’s middleware contract. It intentionally includes no composition patch.

The tests reproduce:

  • CORS preflight OPTIONS /openapi.json returning 405.
  • An actual GET /openapi.json response missing Access-Control-Allow-Origin; the contract also requires the existing X-Process-Time middleware to remain on the exported app.

The fork workflows currently show action_required, so I have not treated the project CI as having run yet.

Could you advise whether the project would prefer a follow-up implementation PR after reviewing this regression contract, or an implementation added to #254? I will follow the preferred workflow.

Drafted with AI assistance; reviewed and posted by SabrinaTso.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds regression coverage to ensure the publicly exported, composed ASGI application preserves the REST API’s middleware behavior (notably CORS handling and the X-Process-Time header) when serving /openapi.json.

Changes:

  • Introduces an in-process httpx.AsyncClient fixture targeting the exported data_api.api.api.app.
  • Adds a CORS preflight regression test for OPTIONS /openapi.json.
  • Adds an API response regression test for GET /openapi.json asserting both CORS and X-Process-Time are present.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +30 to +42
assert response.status_code == 200
assert response.headers["access-control-allow-origin"] == "*"
assert "GET" in response.headers["access-control-allow-methods"]

async def test_public_app_keeps_cors_and_process_time_on_api_responses(
self, client: AsyncClient
):
"""The composed app keeps CORS and timing middleware on actual API responses."""
response = await client.get("/openapi.json", headers={"Origin": "https://consumer.example"})

assert response.status_code == 200
assert response.headers["access-control-allow-origin"] == "*"
assert float(response.headers["x-process-time"]) >= 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants