Lee-W commented on code in PR #74451:
URL: https://github.com/apache/airflow/pull/74451#discussion_r4227743962


##########
providers/common/ai/tests/unit/common/ai/hooks/test_mcp.py:
##########
@@ -207,6 +209,54 @@ def test_stdio_without_command_raises(self):
             with pytest.raises(ValueError, match="requires 'command'"):
                 hook.get_conn()
 
+    def test_missing_mcp_dependency_raises_optional_feature_exception(self):
+        hook = MCPHook(mcp_conn_id="test_conn")
+        with patch.dict(sys.modules, {"fastmcp.client.transports": None}):
+            with pytest.raises(AirflowOptionalProviderFeatureException, 
match="pydantic-ai-slim"):
+                hook.get_conn()
+
+    @pytest.mark.parametrize("bad_args", [{"a": 1}, ["-m", 1], 5], 
ids=["dict", "non_string_item", "int"])
+    def test_stdio_invalid_args_raises(self, bad_args):
+        hook = MCPHook(mcp_conn_id="test_conn")
+        conn = Connection(
+            conn_id="test_conn",
+            conn_type="mcp",
+            extra=json.dumps({"transport": "stdio", "command": "uvx", "args": 
bad_args}),
+        )
+        with patch.object(hook, "get_connection", return_value=conn):
+            with pytest.raises(ValueError, match="'args' in extra"):
+                hook.get_conn()
+
+    @pytest.mark.parametrize(
+        "bad_timeout",
+        ["30", -5, -0.5, float("nan"), float("inf"), True, [10]],
+        ids=["str", "neg", "neg_float", "nan", "inf", "bool", "list"],
+    )
+    def test_stdio_invalid_timeout_raises(self, bad_timeout):
+        hook = MCPHook(mcp_conn_id="test_conn")
+        conn = Connection(
+            conn_id="test_conn",
+            conn_type="mcp",
+            extra=json.dumps({"transport": "stdio", "command": "uvx", "args": 
[], "timeout": bad_timeout}),
+        )
+        with patch.object(hook, "get_connection", return_value=conn):
+            with pytest.raises(ValueError, match="'timeout' in extra"):
+                hook.get_conn()
+
+    @patch(_MCP_TOOLSET, autospec=True)
+    @patch(_STDIO_TRANSPORT, autospec=True)
+    def test_stdio_float_zero_and_null_timeout_accepted(self, 
mock_transport_cls, mock_toolset_cls):

Review Comment:
   Sure, parametrized. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to