test: migrate mcp controller tests to testcontainers#34297
Merged
asukaminato0721 merged 3 commits intolanggenius:mainfrom Mar 31, 2026
Merged
Conversation
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-30 16:36:17.870383122 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-30 16:36:06.171202192 +0000
@@ -670,6 +670,12 @@
--> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:197:9
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/controllers/console/helpers.py:40:48
+ERROR `SimpleNamespace` is not assignable to attribute `mcp_ns` with type `Namespace` [bad-assignment]
+ --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:26:21
+ERROR Attribute `payload` of class `Namespace` is a read-only property and cannot be set [read-only]
+ --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:30:5
+ERROR Argument `DummyServer` is not assignable to parameter `mcp_server` with type `AppMCPServer` in function `controllers.mcp.mcp.MCPAppApi._validate_server_status` [bad-argument-type]
+ --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:453:37
ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
--> tests/test_containers_integration_tests/controllers/web/test_wraps.py:74:33
ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
@@ -2104,14 +2110,6 @@
--> tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py:286:35
ERROR Argument `type[PluginTestPayload]` is not assignable to parameter `payload_type` with type `type[BaseModel]` in function `controllers.inner_api.plugin.wraps.plugin_data` [bad-argument-type]
--> tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py:299:35
-ERROR `SimpleNamespace` is not assignable to attribute `db` with type `SQLAlchemy` [bad-assignment]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:19:17
-ERROR `SimpleNamespace` is not assignable to attribute `mcp_ns` with type `Namespace` [bad-assignment]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:40:21
-ERROR Attribute `payload` of class `Namespace` is a read-only property and cannot be set [read-only]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:44:5
-ERROR Argument `DummyServer` is not assignable to parameter `mcp_server` with type `AppMCPServer` in function `controllers.mcp.mcp.MCPAppApi._validate_server_status` [bad-argument-type]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:467:37
ERROR Cannot index into `Iterable[bytes]` [bad-index]
--> tests/unit_tests/controllers/service_api/app/test_audio.py:213:16
ERROR Cannot index into `Response` [bad-index]
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-30 17:40:27.805888900 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-30 17:40:17.239874542 +0000
@@ -670,6 +670,12 @@
--> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:197:9
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/controllers/console/helpers.py:40:48
+ERROR `SimpleNamespace` is not assignable to attribute `mcp_ns` with type `Namespace` [bad-assignment]
+ --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:26:21
+ERROR Attribute `payload` of class `Namespace` is a read-only property and cannot be set [read-only]
+ --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:30:5
+ERROR Argument `DummyServer` is not assignable to parameter `mcp_server` with type `AppMCPServer` in function `controllers.mcp.mcp.MCPAppApi._validate_server_status` [bad-argument-type]
+ --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:454:37
ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
--> tests/test_containers_integration_tests/controllers/web/test_wraps.py:74:33
ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
@@ -2104,14 +2110,6 @@
--> tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py:286:35
ERROR Argument `type[PluginTestPayload]` is not assignable to parameter `payload_type` with type `type[BaseModel]` in function `controllers.inner_api.plugin.wraps.plugin_data` [bad-argument-type]
--> tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py:299:35
-ERROR `SimpleNamespace` is not assignable to attribute `db` with type `SQLAlchemy` [bad-assignment]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:19:17
-ERROR `SimpleNamespace` is not assignable to attribute `mcp_ns` with type `Namespace` [bad-assignment]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:40:21
-ERROR Attribute `payload` of class `Namespace` is a read-only property and cannot be set [read-only]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:44:5
-ERROR Argument `DummyServer` is not assignable to parameter `mcp_server` with type `AppMCPServer` in function `controllers.mcp.mcp.MCPAppApi._validate_server_status` [bad-argument-type]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:467:37
ERROR Cannot index into `Iterable[bytes]` [bad-index]
--> tests/unit_tests/controllers/service_api/app/test_audio.py:213:16
ERROR Cannot index into `Response` [bad-index]
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-30 18:06:56.268826563 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-30 18:06:46.053865506 +0000
@@ -670,6 +670,12 @@
--> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:197:9
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/controllers/console/helpers.py:40:48
+ERROR `SimpleNamespace` is not assignable to attribute `mcp_ns` with type `Namespace` [bad-assignment]
+ --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:27:21
+ERROR Attribute `payload` of class `Namespace` is a read-only property and cannot be set [read-only]
+ --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:31:5
+ERROR Argument `DummyServer` is not assignable to parameter `mcp_server` with type `AppMCPServer` in function `controllers.mcp.mcp.MCPAppApi._validate_server_status` [bad-argument-type]
+ --> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:460:37
ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
--> tests/test_containers_integration_tests/controllers/web/test_wraps.py:74:33
ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
@@ -2104,14 +2110,6 @@
--> tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py:286:35
ERROR Argument `type[PluginTestPayload]` is not assignable to parameter `payload_type` with type `type[BaseModel]` in function `controllers.inner_api.plugin.wraps.plugin_data` [bad-argument-type]
--> tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py:299:35
-ERROR `SimpleNamespace` is not assignable to attribute `db` with type `SQLAlchemy` [bad-assignment]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:19:17
-ERROR `SimpleNamespace` is not assignable to attribute `mcp_ns` with type `Namespace` [bad-assignment]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:40:21
-ERROR Attribute `payload` of class `Namespace` is a read-only property and cannot be set [read-only]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:44:5
-ERROR Argument `DummyServer` is not assignable to parameter `mcp_server` with type `AppMCPServer` in function `controllers.mcp.mcp.MCPAppApi._validate_server_status` [bad-argument-type]
- --> tests/unit_tests/controllers/mcp/test_mcp.py:467:37
ERROR Cannot index into `Iterable[bytes]` [bad-index]
--> tests/unit_tests/controllers/service_api/app/test_audio.py:213:16
ERROR Cannot index into `Response` [bad-index]
|
asukaminato0721
approved these changes
Mar 31, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates MCP controller tests into the testcontainers integration-test suite so the controller runs against a real PostgreSQL-backed db.engine/Session rather than patched fakes.
Changes:
- Added/updated
api/tests/test_containers_integration_tests/controllers/mcp/test_mcp.pyto cover MCP request/notification handling and various validation/error cases under a containerized Flask request context. - Removed the prior approach of autouse fixtures that replaced
module.db/module.Sessionwith fakes, relying instead on the testcontainers app configuration.
Comments suppressed due to low confidence (3)
api/tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:75
- Patching
module.handle_mcp_requestdoesn’t bypass the DB side-effects inMCPAppApi._handle_mcp_request(it still queries/createsEndUser, commits, and opens an extra session before callinghandle_mcp_request). This makes these tests slower and can leak state into the shared testcontainers DB. PatchMCPAppApi._handle_mcp_requestinstead (or patch_retrieve_end_user/_create_end_user) to keep these controller tests isolated from DB writes unless the test is explicitly verifying DB behavior.
api/tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:41 - The module-level
_TENANT_ID/_APP_ID/_SERVER_IDconstants are shared across all tests in this module. Since the controller now uses a real database session, any created records (e.g.,EndUseroninitialize) will persist and can change the code path for later tests, making them order-dependent. Prefer generating IDs per test (fixture) or perDummyServerinstance, or explicitly cleaning up inserted rows.
api/tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:73 @pytest.mark.usefixtures("flask_req_ctx_with_containers")applies the containerized Flask request context to every test in the class, including tests that only call helper methods (e.g._convert_user_input_form,_validate_server_status) and don’t need Flask/DB. Splitting pure unit-style tests into a separate class without this fixture (or applying the fixture only to the tests that callpost) will reduce unnecessary container/app overhead.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Migrate tests from
api/tests/unit_tests/controllers/mcp/test_mcp.pyto testcontainers integration tests atapi/tests/test_containers_integration_tests/controllers/mcp/test_mcp.py.Removed
mock_dbandmock_sessionautouse fixtures that were replacingmodule.dbandmodule.Sessionwith fakes - the controller now uses realSession(db.engine)from the testcontainers PostgreSQL instance. All 17 tests migrated: MCP request handling (success, notification initialized, invalid notification, inactive server, invalid payload, missing request ID, no response), server/app lookup (server not found, app not found), app availability (no workflow, no model config), app modes (workflow with user input form, chat with model config), invalid request format, server status validation, user input form conversion, and invalid user input form validation.Part of #32454