Skip to content

Commit 5257533

Browse files
committed
test: Fix non-registration tests
#15 Branch: Run-15 Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
1 parent 6ba9158 commit 5257533

1 file changed

Lines changed: 105 additions & 67 deletions

File tree

tests/commands/server/test_run.py

Lines changed: 105 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -35,55 +35,67 @@ def test_run_with_stdio_defaults(self) -> None:
3535

3636
def test_run_with_custom_port_and_host(self) -> None:
3737
"""Test run command with custom port and host."""
38-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
39-
invoke_typer_command(run, stdio="cat", port=9000, host="0.0.0.0")
40-
mock_translate.assert_called_once()
41-
args = mock_translate.call_args[0][0]
38+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
39+
invoke_typer_command(run, stdio="cat", port=9000, host="0.0.0.0", register=False)
40+
mock_process.assert_called_once()
41+
call_args = mock_process.call_args[1]
42+
assert call_args.get("target") is mock_translate
43+
args = call_args["args"][0]
4244
assert "--port" in args
4345
assert "9000" in args
4446
assert "--host" in args
4547
assert "0.0.0.0" in args
4648

4749
def test_run_with_expose_sse(self) -> None:
4850
"""Test run command with SSE exposure enabled."""
49-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
50-
invoke_typer_command(run, stdio="cat", expose_sse=True)
51-
mock_translate.assert_called_once()
52-
args = mock_translate.call_args[0][0]
51+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
52+
invoke_typer_command(run, stdio="cat", expose_sse=True, register=False)
53+
mock_process.assert_called_once()
54+
call_args = mock_process.call_args[1]
55+
assert call_args.get("target") is mock_translate
56+
args = call_args["args"][0]
5357
assert "--expose-sse" in args
5458

5559
def test_run_with_expose_streamable_http(self) -> None:
5660
"""Test run command with streamable HTTP exposure enabled."""
57-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
58-
invoke_typer_command(run, stdio="cat", expose_streamable_http=True)
59-
mock_translate.assert_called_once()
60-
args = mock_translate.call_args[0][0]
61+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
62+
invoke_typer_command(run, stdio="cat", expose_streamable_http=True, register=False)
63+
mock_process.assert_called_once()
64+
call_args = mock_process.call_args[1]
65+
assert call_args.get("target") is mock_translate
66+
args = call_args["args"][0]
6167
assert "--expose-streamable-http" in args
6268

6369
def test_run_with_both_protocols(self) -> None:
6470
"""Test run command with both SSE and streamable HTTP enabled."""
65-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
66-
invoke_typer_command(run, stdio="cat", expose_sse=True, expose_streamable_http=True)
67-
mock_translate.assert_called_once()
68-
args = mock_translate.call_args[0][0]
71+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
72+
invoke_typer_command(run, stdio="cat", expose_sse=True, expose_streamable_http=True, register=False)
73+
mock_process.assert_called_once()
74+
call_args = mock_process.call_args[1]
75+
assert call_args.get("target") is mock_translate
76+
args = call_args["args"][0]
6977
assert "--expose-sse" in args
7078
assert "--expose-streamable-http" in args
7179

7280
def test_run_with_grpc(self) -> None:
7381
"""Test run command with gRPC server exposure."""
74-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
75-
invoke_typer_command(run, grpc="localhost:50051")
76-
mock_translate.assert_called_once()
77-
args = mock_translate.call_args[0][0]
82+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
83+
invoke_typer_command(run, grpc="localhost:50051", register=False)
84+
mock_process.assert_called_once()
85+
call_args = mock_process.call_args[1]
86+
assert call_args.get("target") is mock_translate
87+
args = call_args["args"][0]
7888
assert "--grpc" in args
7989
assert "localhost:50051" in args
8090

8191
def test_run_with_grpc_tls(self) -> None:
8292
"""Test run command with gRPC TLS enabled."""
83-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
84-
invoke_typer_command(run, grpc="localhost:50051", grpc_tls=True, grpc_cert="/path/to/cert", grpc_key="/path/to/key")
85-
mock_translate.assert_called_once()
86-
args = mock_translate.call_args[0][0]
93+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
94+
invoke_typer_command(run, grpc="localhost:50051", grpc_tls=True, grpc_cert="/path/to/cert", grpc_key="/path/to/key", register=False)
95+
mock_process.assert_called_once()
96+
call_args = mock_process.call_args[1]
97+
assert call_args.get("target") is mock_translate
98+
args = call_args["args"][0]
8799
assert "--grpc-tls" in args
88100
assert "--grpc-cert" in args
89101
assert "/path/to/cert" in args
@@ -92,101 +104,124 @@ def test_run_with_grpc_tls(self) -> None:
92104

93105
def test_run_with_grpc_metadata(self) -> None:
94106
"""Test run command with gRPC metadata."""
95-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
96-
invoke_typer_command(run, grpc="localhost:50051", grpc_metadata=["key1=value1", "key2=value2"])
97-
mock_translate.assert_called_once()
98-
args = mock_translate.call_args[0][0]
107+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
108+
invoke_typer_command(run, grpc="localhost:50051", grpc_metadata=["key1=value1", "key2=value2"], register=False)
109+
mock_process.assert_called_once()
110+
call_args = mock_process.call_args[1]
111+
assert call_args.get("target") is mock_translate
112+
args = call_args["args"][0]
99113
assert "--grpc-metadata" in args
100114
assert "key1=value1" in args
101115
assert "key2=value2" in args
102116

103117
def test_run_with_cors(self) -> None:
104118
"""Test run command with CORS origins."""
105-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
106-
invoke_typer_command(run, stdio="cat", cors=["https://app.example.com", "https://web.example.com"])
107-
mock_translate.assert_called_once()
108-
args = mock_translate.call_args[0][0]
119+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
120+
invoke_typer_command(run, stdio="cat", cors=["https://app.example.com", "https://web.example.com"], register=False)
121+
mock_process.assert_called_once()
122+
call_args = mock_process.call_args[1]
123+
assert call_args.get("target") is mock_translate
124+
args = call_args["args"][0]
109125
assert "--cors" in args
110126
assert "https://app.example.com" in args
111127
assert "https://web.example.com" in args
112128

113129
def test_run_with_oauth2_bearer(self) -> None:
114130
"""Test run command with OAuth2 bearer token."""
115-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
116-
invoke_typer_command(run, stdio="cat", oauth2_bearer="token123")
117-
mock_translate.assert_called_once()
118-
args = mock_translate.call_args[0][0]
131+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
132+
invoke_typer_command(run, stdio="cat", oauth2_bearer="token123", register=False)
133+
mock_process.assert_called_once()
134+
call_args = mock_process.call_args[1]
135+
assert call_args.get("target") is mock_translate
136+
args = call_args["args"][0]
119137
assert "--oauth2Bearer" in args
120138
assert "token123" in args
121139

122140
def test_run_with_custom_sse_paths(self) -> None:
123141
"""Test run command with custom SSE paths."""
124-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
125-
invoke_typer_command(run, stdio="cat", sse_path="/events", message_path="/send")
126-
mock_translate.assert_called_once()
127-
args = mock_translate.call_args[0][0]
142+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
143+
invoke_typer_command(run, stdio="cat", sse_path="/events", message_path="/send", register=False)
144+
mock_process.assert_called_once()
145+
call_args = mock_process.call_args[1]
146+
assert call_args.get("target") is mock_translate
147+
args = call_args["args"][0]
128148
assert "--ssePath" in args
129149
assert "/events" in args
130150
assert "--messagePath" in args
131151
assert "/send" in args
132152

133153
def test_run_with_custom_keep_alive(self) -> None:
134154
"""Test run command with custom keep-alive interval."""
135-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
136-
invoke_typer_command(run, stdio="cat", keep_alive=60)
137-
mock_translate.assert_called_once()
138-
args = mock_translate.call_args[0][0]
155+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
156+
invoke_typer_command(run, stdio="cat", keep_alive=60, register=False)
157+
mock_process.assert_called_once()
158+
call_args = mock_process.call_args[1]
159+
assert call_args.get("target") is mock_translate
160+
args = call_args["args"][0]
139161
assert "--keepAlive" in args
140162
assert "60" in args
141163

142164
def test_run_with_stdio_command(self) -> None:
143165
"""Test run command with stdio command for bridging."""
144-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
145-
invoke_typer_command(run, stdio="cat", stdio_command="uvx mcp-client")
146-
mock_translate.assert_called_once()
147-
args = mock_translate.call_args[0][0]
166+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
167+
invoke_typer_command(run, stdio="cat", stdio_command="uvx mcp-client", register=False)
168+
mock_process.assert_called_once()
169+
call_args = mock_process.call_args[1]
170+
assert call_args.get("target") is mock_translate
171+
args = call_args["args"][0]
148172
assert "--stdioCommand" in args
149173
assert "uvx mcp-client" in args
150174

151175
def test_run_with_dynamic_env(self) -> None:
152176
"""Test run command with dynamic environment injection."""
153-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
154-
invoke_typer_command(run, stdio="cat", enable_dynamic_env=True, header_to_env=["Authorization=AUTH_TOKEN", "X-API-Key=API_KEY"])
155-
mock_translate.assert_called_once()
156-
args = mock_translate.call_args[0][0]
177+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
178+
invoke_typer_command(run, stdio="cat", enable_dynamic_env=True, header_to_env=["Authorization=AUTH_TOKEN", "X-API-Key=API_KEY"], register=False)
179+
mock_process.assert_called_once()
180+
call_args = mock_process.call_args[1]
181+
assert call_args.get("target") is mock_translate
182+
args = call_args["args"][0]
157183
assert "--enable-dynamic-env" in args
158184
assert "--header-to-env" in args
159185
assert "Authorization=AUTH_TOKEN" in args
160186
assert "X-API-Key=API_KEY" in args
161187

162188
def test_run_with_stateless_mode(self) -> None:
163189
"""Test run command with stateless mode for streamable HTTP."""
164-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
165-
invoke_typer_command(run, stdio="cat", expose_streamable_http=True, stateless=True)
166-
mock_translate.assert_called_once()
167-
args = mock_translate.call_args[0][0]
190+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
191+
invoke_typer_command(run, stdio="cat", expose_streamable_http=True, stateless=True, register=False)
192+
mock_process.assert_called_once()
193+
call_args = mock_process.call_args[1]
194+
assert call_args.get("target") is mock_translate
195+
args = call_args["args"][0]
168196
assert "--stateless" in args
169197

170198
def test_run_with_json_response(self) -> None:
171199
"""Test run command with JSON response mode."""
172-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
173-
invoke_typer_command(run, stdio="cat", expose_streamable_http=True, json_response=True)
174-
mock_translate.assert_called_once()
175-
args = mock_translate.call_args[0][0]
200+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
201+
invoke_typer_command(run, stdio="cat", expose_streamable_http=True, json_response=True, register=False)
202+
mock_process.assert_called_once()
203+
call_args = mock_process.call_args[1]
204+
assert call_args.get("target") is mock_translate
205+
args = call_args["args"][0]
176206
assert "--jsonResponse" in args
177207

178208
def test_run_with_log_level(self) -> None:
179209
"""Test run command with custom log level."""
180-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
181-
invoke_typer_command(run, stdio="cat", log_level="debug")
182-
mock_translate.assert_called_once()
183-
args = mock_translate.call_args[0][0]
210+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process:
211+
invoke_typer_command(run, stdio="cat", log_level="debug", register=False)
212+
mock_process.assert_called_once()
213+
call_args = mock_process.call_args[1]
214+
assert call_args.get("target") is mock_translate
215+
args = call_args["args"][0]
184216
assert "--logLevel" in args
185217
assert "debug" in args
186218

187219
def test_run_with_all_options(self) -> None:
188220
"""Test run command with all options enabled."""
189-
with patch("cforge.commands.server.run.translate_main") as mock_translate:
221+
with patch("mcpgateway.translate.main") as mock_translate, patch("multiprocessing.Process") as mock_process, patch("cforge.commands.server.run.make_authenticated_request") as mock_request:
222+
223+
mock_request.return_value = {"id": "test-server-id"}
224+
190225
invoke_typer_command(
191226
run,
192227
stdio="uvx mcp-server-git",
@@ -203,9 +238,12 @@ def test_run_with_all_options(self) -> None:
203238
header_to_env=["Authorization=AUTH_TOKEN"],
204239
stateless=True,
205240
json_response=True,
241+
register=False,
206242
)
207-
mock_translate.assert_called_once()
208-
args = mock_translate.call_args[0][0]
243+
mock_process.assert_called_once()
244+
call_args = mock_process.call_args[1]
245+
assert call_args.get("target") is mock_translate
246+
args = call_args["args"][0]
209247
# Verify key arguments are present
210248
assert "--stdio" in args
211249
assert "uvx mcp-server-git" in args

0 commit comments

Comments
 (0)