Skip to content

Commit 5812342

Browse files
cdeustclaude
andcommitted
test(viz): update open_visualization tests for tilemap pipeline
The handler now drives prepare-then-render: ``launch_server`` → ``_prepare_layout`` → ``open_in_browser(<url>?viz=tilemap)``. Tests patch the new ``_prepare_layout`` so they don't issue real HTTP traffic, and assert against the new URL surface. * test_returns_url / test_default_args_none / test_launches_unified — same intent, updated assertion to expect ``?viz=tilemap`` suffix and stub the layout pipeline. * test_opens_browser → test_opens_browser_at_tilemap_url + a new test_opens_browser_at_legacy_url_when_extras_missing covering the graceful fallback when ``viz-tile`` is not installed. Local run: 7/7 pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 54f443d commit 5812342

1 file changed

Lines changed: 45 additions & 3 deletions

File tree

tests_py/handlers/test_open_visualization.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,27 @@ def test_domain_is_optional(self):
2121

2222

2323
class TestOpenVisualizationHandler:
24+
"""The handler now drives the full prepare-then-render pipeline:
25+
after launching the standalone server it polls /api/graph/progress,
26+
invokes /api/recompute_layout, and only then opens the browser at
27+
the ``?viz=tilemap`` path. Tests stub ``_prepare_layout`` so they
28+
don't issue real HTTP traffic."""
29+
2430
def test_returns_url(self):
2531
with (
2632
patch(
2733
"mcp_server.handlers.open_visualization.launch_server",
2834
return_value="http://localhost:3458",
2935
),
3036
patch("mcp_server.handlers.open_visualization.open_in_browser"),
37+
patch(
38+
"mcp_server.handlers.open_visualization._prepare_layout",
39+
return_value={"status": "ok", "node_count": 0, "cached": True},
40+
),
3141
):
3242
result = asyncio.run(handler({}))
3343

34-
assert result["url"] == "http://localhost:3458"
44+
assert result["url"] == "http://localhost:3458/?viz=tilemap"
3545
assert "localhost" in result["message"]
3646

3747
def test_default_args_none(self):
@@ -41,9 +51,13 @@ def test_default_args_none(self):
4151
return_value="http://localhost:3458",
4252
),
4353
patch("mcp_server.handlers.open_visualization.open_in_browser"),
54+
patch(
55+
"mcp_server.handlers.open_visualization._prepare_layout",
56+
return_value={"status": "ok", "node_count": 0, "cached": True},
57+
),
4458
):
4559
result = asyncio.run(handler(None))
46-
assert result["url"] == "http://localhost:3458"
60+
assert result["url"] == "http://localhost:3458/?viz=tilemap"
4761

4862
def test_launches_unified_server_type(self):
4963
mock_launch = MagicMock(return_value="http://localhost:3458")
@@ -53,12 +67,17 @@ def test_launches_unified_server_type(self):
5367
mock_launch,
5468
),
5569
patch("mcp_server.handlers.open_visualization.open_in_browser"),
70+
patch(
71+
"mcp_server.handlers.open_visualization._prepare_layout",
72+
return_value={"status": "ok", "node_count": 0, "cached": True},
73+
),
5674
):
5775
asyncio.run(handler({}))
5876

5977
mock_launch.assert_called_once_with("unified")
6078

61-
def test_opens_browser(self):
79+
def test_opens_browser_at_tilemap_url(self):
80+
"""When extras are present the browser opens at the tilemap URL."""
6281
with (
6382
patch(
6483
"mcp_server.handlers.open_visualization.launch_server",
@@ -67,6 +86,29 @@ def test_opens_browser(self):
6786
patch(
6887
"mcp_server.handlers.open_visualization.open_in_browser",
6988
) as mock_open,
89+
patch(
90+
"mcp_server.handlers.open_visualization._prepare_layout",
91+
return_value={"status": "ok", "node_count": 0, "cached": True},
92+
),
7093
):
7194
asyncio.run(handler({}))
95+
mock_open.assert_called_once_with("http://localhost:5555/?viz=tilemap")
96+
97+
def test_opens_browser_at_legacy_url_when_extras_missing(self):
98+
"""``viz-tile`` extras unavailable falls back to the legacy URL."""
99+
with (
100+
patch(
101+
"mcp_server.handlers.open_visualization.launch_server",
102+
return_value="http://localhost:5555",
103+
),
104+
patch(
105+
"mcp_server.handlers.open_visualization.open_in_browser",
106+
) as mock_open,
107+
patch(
108+
"mcp_server.handlers.open_visualization._prepare_layout",
109+
return_value={"status": "error", "reason": "igraph_missing"},
110+
),
111+
):
112+
result = asyncio.run(handler({}))
72113
mock_open.assert_called_once_with("http://localhost:5555")
114+
assert "viz-tile" in result["message"]

0 commit comments

Comments
 (0)