summaryrefslogtreecommitdiff
path: root/tests/test_transports.py
diff options
context:
space:
mode:
authortanaka takashi <isazaka@gmail.com>2026-07-11 19:35:37 +0900
committertanaka takashi <isazaka@gmail.com>2026-07-11 19:35:37 +0900
commitc2e5098d030fe902eff258e10d2fefc01226e4bf (patch)
tree70885d7bae28fde887580d7b631cfa987ea12f19 /tests/test_transports.py
parent93ca8050531ea99fa1d10ffb7d3f2c965e3a4ebe (diff)
テスト追加と修正
Diffstat (limited to 'tests/test_transports.py')
-rw-r--r--tests/test_transports.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/test_transports.py b/tests/test_transports.py
new file mode 100644
index 0000000..395977b
--- /dev/null
+++ b/tests/test_transports.py
@@ -0,0 +1,66 @@
+"""Tests for MCP server transport CLI argument parsing."""
+
+from unittest.mock import patch
+
+import pytest
+
+from mml_composemusic_mcp.server import main
+
+
+def test_transport_stdio_default():
+ """Default transport should be stdio."""
+ with patch("sys.argv", ["server", "--output-dir", "./data"]):
+ with patch("mml_composemusic_mcp.server.mcp.run") as mock_run:
+ main()
+ mock_run.assert_called_once()
+ call_kwargs = mock_run.call_args
+ assert call_kwargs[1]["transport"] == "stdio"
+
+
+def test_transport_http():
+ """HTTP transport should pass host and port."""
+ with patch(
+ "sys.argv",
+ ["server", "--transport", "http", "--host", "0.0.0.0", "--port", "9000"],
+ ):
+ with patch("mml_composemusic_mcp.server.mcp.run") as mock_run:
+ main()
+ call_kwargs = mock_run.call_args
+ assert call_kwargs[1]["transport"] == "http"
+ assert call_kwargs[1]["host"] == "0.0.0.0"
+ assert call_kwargs[1]["port"] == 9000
+
+
+def test_transport_sse():
+ """SSE transport should be accepted."""
+ with patch("sys.argv", ["server", "--transport", "sse", "--port", "8080"]):
+ with patch("mml_composemusic_mcp.server.mcp.run") as mock_run:
+ main()
+ call_kwargs = mock_run.call_args
+ assert call_kwargs[1]["transport"] == "sse"
+
+
+def test_transport_streamable_http():
+ """Streamable HTTP transport should be accepted."""
+ with patch("sys.argv", ["server", "--transport", "streamable-http"]):
+ with patch("mml_composemusic_mcp.server.mcp.run") as mock_run:
+ main()
+ call_kwargs = mock_run.call_args
+ assert call_kwargs[1]["transport"] == "streamable-http"
+
+
+def test_transport_invalid_rejected():
+ """Invalid transport should be rejected by argparse."""
+ with patch("sys.argv", ["server", "--transport", "invalid"]):
+ with pytest.raises(SystemExit):
+ main()
+
+
+def test_output_dir_override(tmp_path):
+ """--output-dir should set OUTPUT_DIR."""
+ with patch("sys.argv", ["server", "--output-dir", str(tmp_path / "out")]):
+ with patch("mml_composemusic_mcp.server.mcp.run"):
+ import mml_composemusic_mcp.server as srv
+
+ main()
+ assert srv.OUTPUT_DIR == tmp_path / "out"