Skip to content

Commit 95da6fe

Browse files
committed
add test
1 parent 1aed8a7 commit 95da6fe

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Test
22

33
on:
44
push:
5-
branches: ["main"]
5+
branches: ["main","test/add-prompt-test"]
66
pull_request:
7-
branches: ["main"]
7+
branches: ["main","test/add-prompt-test"]
88

99
defaults:
1010
run:

tests/test_common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,8 @@ async def execute_code(self, code, timeout=60):
396396
structured["result"] = [result_val]
397397

398398
return structured
399+
400+
@requires_session
401+
async def jupyter_cite(self, prompt, cell_indices, notebook_name=""):
402+
prompt = await self._session.get_prompt("jupyter_cite", arguments={"prompt": prompt, "cell_indices": cell_indices, "notebook_name": notebook_name}) # type: ignore
403+
return [message.content.text for message in prompt.messages]

tests/test_prompts.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Test for MCP Prompts Feature
3+
"""
4+
5+
import os
6+
import logging
7+
from http import HTTPStatus
8+
9+
import pytest
10+
import requests
11+
12+
from .test_common import MCPClient, JUPYTER_TOOLS, timeout_wrapper
13+
14+
# Now, prompt feature is only available in MCP_SERVER mode.
15+
pytestmark = pytest.mark.skipif(
16+
not os.environ.get("TEST_MCP_SERVER", "false").lower() == "true",
17+
reason="Prompt feature is only available in MCP_SERVER mode now."
18+
)
19+
20+
21+
@pytest.mark.asyncio
22+
@timeout_wrapper(60)
23+
async def test_jupyter_cite(mcp_client_parametrized: MCPClient):
24+
"""Test jupyter cite prompt feature"""
25+
async with mcp_client_parametrized:
26+
await mcp_client_parametrized.use_notebook("new", "new.ipynb")
27+
await mcp_client_parametrized.use_notebook("notebook", "notebook.ipynb")
28+
# Test prompt injection
29+
response = await mcp_client_parametrized.jupyter_cite(prompt="test prompt", cell_indices="0")
30+
assert "# Matplotlib Examples" in response[0], "Cell 0 should contain Matplotlib Examples"
31+
assert "test prompt" not in response[0], "Prompt should not be injected"
32+
# Test mixed cell_indices
33+
response = await mcp_client_parametrized.jupyter_cite(prompt="", cell_indices="0-2,4")
34+
assert "USER Cite cells [0, 1, 2, 4]" in response[0], "Cell indices should be [0, 1, 2, 4]"
35+
assert "## 1. Import Required Libraries" in response[0], "Cell 1 should contain Import Required Libraries"
36+
assert "%matplotlib inline" in response[0], "Cell 2 should contain %matplotlib inline"
37+
assert "## 2. Basic Line Plot" not in response[0], "Cell 3 should not be cited"
38+
assert "y = np.sin(x)" in response[0], "Cell 4 should contain y = np.sin(x)"
39+
# Test cite other notebook
40+
response = await mcp_client_parametrized.jupyter_cite(prompt="", cell_indices="0", notebook_name="new")
41+
assert "from notebook new" in response[0], "should cite new notebook"
42+
assert "# A New Notebook" in response[0], "Cell 0 of new notebook should contain A New Notebook"

0 commit comments

Comments
 (0)