|
4 | 4 |
|
5 | 5 | from unittest.mock import Mock |
6 | 6 |
|
| 7 | +from marimo._ai._tools.types import MarimoNotebookInfo |
7 | 8 | from marimo._mcp.server._prompts.prompts.notebooks import ActiveNotebooks |
| 9 | +from marimo._types.ids import SessionId |
8 | 10 |
|
9 | 11 |
|
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.""" |
22 | 14 | 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 | | - |
49 | 15 | 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 | + ), |
52 | 26 | ] |
53 | 27 |
|
54 | 28 | prompt = ActiveNotebooks(context=context) |
55 | 29 | 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") |
76 | 34 | ) |
| 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