Skip to content
This repository was archived by the owner on Mar 21, 2026. It is now read-only.

Commit 84b0d28

Browse files
Merge pull request #10 from PromptExecution/copilot/sub-pr-7-another-one
Add unit tests for --mcp flag functionality
2 parents 48ce566 + 3540681 commit 84b0d28

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

tests/test_entrypoint.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from pathlib import Path
44
from typing import Sequence
5+
from unittest.mock import MagicMock
56

67
import pytest
78

@@ -37,3 +38,65 @@ def fake_run(_cmd: Sequence[str], stdin_path: Path | None = None) -> str:
3738
rc = entrypoint.main(["--agent", "amp", "1"])
3839
assert rc == 0
3940
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

Comments
 (0)