|
34 | 34 | from mcp import ClientSession |
35 | 35 | from mcp.shared.memory import create_client_server_memory_streams |
36 | 36 | from pydantic import BaseModel |
37 | | -from zoneinfo import ZoneInfoNotFoundError |
38 | 37 |
|
39 | 38 | from mcp_server_time.server import serve |
40 | 39 |
|
@@ -236,16 +235,31 @@ async def test_empty_local_timezone_override_is_treated_as_absent() -> None: |
236 | 235 | assert result == {"tools": expected_tools("Africa/Cairo")} |
237 | 236 |
|
238 | 237 |
|
239 | | -# KNOWN BUG #5001: an invalid --local-timezone crashes serve() with a traceback instead of a clean error; the fix changes this assertion. |
240 | | -async def test_invalid_local_timezone_fails_before_the_transport_opens() -> None: |
241 | | - # An unknown `--local-timezone` raises out of `serve()` itself, before |
242 | | - # stdio is opened: the process dies with a traceback instead of starting. |
| 238 | +@pytest.mark.parametrize( |
| 239 | + "local_timezone", |
| 240 | + [ |
| 241 | + "Not/AZone", # unknown name: ZoneInfoNotFoundError |
| 242 | + "America", # a tzdata directory, not a zone: OSError |
| 243 | + "../etc/passwd", # outside TZPATH: ValueError |
| 244 | + ], |
| 245 | +) |
| 246 | +async def test_invalid_local_timezone_fails_before_the_transport_opens( |
| 247 | + local_timezone: str, |
| 248 | +) -> None: |
| 249 | + # An invalid `--local-timezone` stops `serve()` before stdio is opened, |
| 250 | + # with a one-line message naming the value and a non-zero exit, rather |
| 251 | + # than a traceback (#5001). A `SystemExit` whose code is a string prints |
| 252 | + # that string to stderr and exits 1. |
243 | 253 | def unexpected_stdio_server(): |
244 | 254 | raise AssertionError("stdio_server must not be reached") |
245 | 255 |
|
246 | 256 | with patch("mcp_server_time.server.stdio_server", unexpected_stdio_server): |
247 | | - with pytest.raises(ZoneInfoNotFoundError, match="Not/AZone"): |
248 | | - await serve("Not/AZone") |
| 257 | + with pytest.raises(SystemExit) as exit_info: |
| 258 | + await serve(local_timezone) |
| 259 | + assert exit_info.value.code == ( |
| 260 | + f"Error: invalid --local-timezone {local_timezone!r}: " |
| 261 | + "not a known IANA timezone name" |
| 262 | + ) |
249 | 263 |
|
250 | 264 |
|
251 | 265 | # --------------------------------------------------------------------------- |
|
0 commit comments