|
2 | 2 |
|
3 | 3 | from pathlib import Path |
4 | 4 | from typing import Sequence |
| 5 | +from unittest.mock import MagicMock |
5 | 6 |
|
6 | 7 | import pytest |
7 | 8 |
|
@@ -37,3 +38,65 @@ def fake_run(_cmd: Sequence[str], stdin_path: Path | None = None) -> str: |
37 | 38 | rc = entrypoint.main(["--agent", "amp", "1"]) |
38 | 39 | assert rc == 0 |
39 | 40 | assert (tmp_path / "progress.txt").exists() |
| 41 | + |
| 42 | + |
| 43 | +def test_parse_args_mcp_without_agent() -> None: |
| 44 | + """Test that --mcp flag works without requiring --agent.""" |
| 45 | + args = entrypoint._parse_args(["--mcp"]) |
| 46 | + assert args.mcp is True |
| 47 | + assert args.agent is None |
| 48 | + |
| 49 | + |
| 50 | +def test_parse_args_mcp_with_default_transport() -> None: |
| 51 | + """Test that --mcp uses stdio as default transport.""" |
| 52 | + args = entrypoint._parse_args(["--mcp"]) |
| 53 | + assert args.mcp is True |
| 54 | + assert args.transport == "stdio" |
| 55 | + |
| 56 | + |
| 57 | +def test_parse_args_mcp_with_http_transport() -> None: |
| 58 | + """Test that --mcp accepts HTTP transport with host and port.""" |
| 59 | + args = entrypoint._parse_args([ |
| 60 | + "--mcp", |
| 61 | + "--transport", "http", |
| 62 | + "--host", "0.0.0.0", |
| 63 | + "--port", "9000", |
| 64 | + ]) |
| 65 | + assert args.mcp is True |
| 66 | + assert args.transport == "http" |
| 67 | + assert args.host == "0.0.0.0" |
| 68 | + assert args.port == 9000 |
| 69 | + |
| 70 | + |
| 71 | +def test_parse_args_mcp_with_default_host_port() -> None: |
| 72 | + """Test that --mcp uses default host and port values.""" |
| 73 | + args = entrypoint._parse_args(["--mcp", "--transport", "http"]) |
| 74 | + assert args.host == "127.0.0.1" |
| 75 | + assert args.port == 8000 |
| 76 | + |
| 77 | + |
| 78 | +def test_main_mcp_calls_run_with_stdio(monkeypatch: pytest.MonkeyPatch) -> None: |
| 79 | + """Test that main() calls mcp.run() with correct parameters for stdio.""" |
| 80 | + mock_mcp_run = MagicMock() |
| 81 | + monkeypatch.setattr("ralph.entrypoint.mcp.run", mock_mcp_run) |
| 82 | + |
| 83 | + rc = entrypoint.main(["--mcp"]) |
| 84 | + |
| 85 | + assert rc == 0 |
| 86 | + mock_mcp_run.assert_called_once_with(transport="stdio") |
| 87 | + |
| 88 | + |
| 89 | +def test_main_mcp_calls_run_with_http(monkeypatch: pytest.MonkeyPatch) -> None: |
| 90 | + """Test that main() calls mcp.run() with correct parameters for HTTP.""" |
| 91 | + mock_mcp_run = MagicMock() |
| 92 | + monkeypatch.setattr("ralph.entrypoint.mcp.run", mock_mcp_run) |
| 93 | + |
| 94 | + rc = entrypoint.main([ |
| 95 | + "--mcp", |
| 96 | + "--transport", "http", |
| 97 | + "--host", "0.0.0.0", |
| 98 | + "--port", "9000", |
| 99 | + ]) |
| 100 | + |
| 101 | + assert rc == 0 |
| 102 | + mock_mcp_run.assert_called_once_with(transport="http", host="0.0.0.0", port=9000) |
0 commit comments