Skip to content

Commit fd6daeb

Browse files
committed
update prompt tests to check for essential data in prompts only
1 parent 36d6811 commit fd6daeb

File tree

2 files changed

+91
-60
lines changed

2 files changed

+91
-60
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import pytest
2+
3+
pytest.importorskip("mcp", reason="MCP requires Python 3.10+")
4+
5+
from unittest.mock import Mock
6+
7+
from marimo._ai._tools.types import (
8+
MarimoCellErrors,
9+
MarimoErrorDetail,
10+
MarimoNotebookInfo,
11+
)
12+
from marimo._mcp.server._prompts.prompts.errors import ErrorsSummary
13+
from marimo._types.ids import CellId_t, SessionId
14+
15+
16+
def test_errors_summary_includes_essential_data():
17+
"""Test that essential data (notebook info, cell IDs, error messages) are included."""
18+
context = Mock()
19+
context.get_active_sessions_internal.return_value = [
20+
MarimoNotebookInfo(
21+
name="notebook.py",
22+
path="/path/to/notebook.py",
23+
session_id=SessionId("session_1"),
24+
)
25+
]
26+
context.get_notebook_errors.return_value = [
27+
MarimoCellErrors(
28+
cell_id=CellId_t("cell_1"),
29+
errors=[
30+
MarimoErrorDetail(
31+
type="ValueError",
32+
message="invalid value",
33+
traceback=["line 1"],
34+
)
35+
],
36+
),
37+
MarimoCellErrors(
38+
cell_id=CellId_t("cell_2"),
39+
errors=[
40+
MarimoErrorDetail(
41+
type="TypeError",
42+
message="wrong type",
43+
traceback=["line 2"],
44+
)
45+
],
46+
),
47+
]
48+
49+
prompt = ErrorsSummary(context=context)
50+
messages = prompt.handle()
51+
text = "\n".join(
52+
msg.content.text # type: ignore[attr-defined]
53+
for msg in messages
54+
if hasattr(msg.content, "text")
55+
)
56+
57+
# Essential data must be present
58+
assert "notebook.py" in text
59+
assert "session_1" in text
60+
assert "/path/to/notebook.py" in text
61+
assert "cell_1" in text
62+
assert "cell_2" in text
63+
assert "ValueError" in text
64+
assert "invalid value" in text
65+
assert "TypeError" in text
66+
assert "wrong type" in text
67+

tests/_mcp/server/prompts/test_notebooks_prompts.py

Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,37 @@
44

55
from unittest.mock import Mock
66

7+
from marimo._ai._tools.types import MarimoNotebookInfo
78
from marimo._mcp.server._prompts.prompts.notebooks import ActiveNotebooks
9+
from marimo._types.ids import SessionId
810

911

10-
def test_active_notebooks_metadata():
11-
"""Test that name and description are properly set."""
12-
prompt = ActiveNotebooks(context=Mock())
13-
assert prompt.name == "active_notebooks"
14-
assert (
15-
prompt.description
16-
== "Get current active notebooks and their session IDs and file paths."
17-
)
18-
19-
20-
def test_active_notebooks_no_sessions():
21-
"""Test output when no sessions are active."""
12+
def test_active_notebooks_includes_session_ids_and_paths():
13+
"""Test that essential data (session IDs and file paths) are included."""
2214
context = Mock()
23-
context.get_active_sessions_internal.return_value = []
24-
25-
prompt = ActiveNotebooks(context=context)
26-
messages = prompt.handle()
27-
28-
assert len(messages) == 1
29-
assert messages[0].role == "user"
30-
assert messages[0].content.type == "text"
31-
assert (
32-
"No active marimo notebook sessions found" in messages[0].content.text
33-
)
34-
35-
36-
def test_active_notebooks_with_sessions():
37-
"""Test output with active sessions."""
38-
context = Mock()
39-
40-
# Mock active session objects
41-
active_session1 = Mock()
42-
active_session1.session_id = "session_1"
43-
active_session1.path = "/path/to/notebook.py"
44-
45-
active_session2 = Mock()
46-
active_session2.session_id = "session_2"
47-
active_session2.path = None
48-
4915
context.get_active_sessions_internal.return_value = [
50-
active_session1,
51-
active_session2,
16+
MarimoNotebookInfo(
17+
name="notebook.py",
18+
path="/path/to/notebook.py",
19+
session_id=SessionId("session_1"),
20+
),
21+
MarimoNotebookInfo(
22+
name="other.py",
23+
path="/other/path.py",
24+
session_id=SessionId("session_2"),
25+
),
5226
]
5327

5428
prompt = ActiveNotebooks(context=context)
5529
messages = prompt.handle()
56-
57-
assert len(messages) == 3 # 2 sessions + 1 action message
58-
59-
# Check first message (with file path)
60-
assert messages[0].role == "user"
61-
assert messages[0].content.type == "text"
62-
assert "session_1" in messages[0].content.text
63-
assert "/path/to/notebook.py" in messages[0].content.text
64-
65-
# Check second message (without file path)
66-
assert messages[1].role == "user"
67-
assert messages[1].content.type == "text"
68-
assert "session_2" in messages[1].content.text
69-
70-
# Check action message
71-
assert messages[2].role == "user"
72-
assert messages[2].content.type == "text"
73-
assert (
74-
"Use these session_ids when calling marimo MCP tools"
75-
in messages[2].content.text
30+
text = "\n".join(
31+
msg.content.text # type: ignore[attr-defined]
32+
for msg in messages
33+
if hasattr(msg.content, "text")
7634
)
35+
36+
# Essential data must be present
37+
assert "session_1" in text
38+
assert "session_2" in text
39+
assert "/path/to/notebook.py" in text
40+
assert "/other/path.py" in text

0 commit comments

Comments
 (0)