-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathtest_prompts.py
More file actions
167 lines (123 loc) · 5.85 KB
/
test_prompts.py
File metadata and controls
167 lines (123 loc) · 5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"""Tests for MCP prompts."""
from datetime import timezone, datetime
import pytest
from basic_memory.mcp.prompts.continue_conversation import continue_conversation
from basic_memory.mcp.prompts.search import search_prompt
from basic_memory.mcp.prompts.recent_activity import recent_activity_prompt
@pytest.mark.asyncio
async def test_continue_conversation_with_topic(client, test_graph):
"""Test continue_conversation with a topic."""
# We can use the test_graph fixture which already has relevant content
# Call the function with a topic that should match existing content
result = await continue_conversation.fn(topic="Root", timeframe="1w")
# Check that the result contains expected content
assert "Continuing conversation on: Root" in result
assert "This is a memory retrieval session" in result
assert "Start by executing one of the suggested commands" in result
@pytest.mark.asyncio
async def test_continue_conversation_with_recent_activity(client, test_graph):
"""Test continue_conversation with no topic, using recent activity."""
# Call the function without a topic
result = await continue_conversation.fn(timeframe="1w")
# Check that the result contains expected content for recent activity
assert "Continuing conversation on: Recent Activity" in result
assert "This is a memory retrieval session" in result
assert "Please use the available basic-memory tools" in result
assert "Next Steps" in result
@pytest.mark.asyncio
async def test_continue_conversation_no_results(client):
"""Test continue_conversation when no results are found."""
# Call with a non-existent topic
result = await continue_conversation.fn(topic="NonExistentTopic", timeframe="1w")
# Check the response indicates no results found
assert "Continuing conversation on: NonExistentTopic" in result
assert "The supplied query did not return any information" in result
@pytest.mark.asyncio
async def test_continue_conversation_creates_structured_suggestions(client, test_graph):
"""Test that continue_conversation generates structured tool usage suggestions."""
# Call the function with a topic that should match existing content
result = await continue_conversation.fn(topic="Root", timeframe="1w")
# Verify the response includes clear tool usage instructions
assert "start by executing one of the suggested commands" in result.lower()
# Check that the response contains tool call examples
assert "read_note" in result
assert "search" in result
assert "recent_activity" in result
# Search prompt tests
@pytest.mark.asyncio
async def test_search_prompt_with_results(client, test_graph):
"""Test search_prompt with a query that returns results."""
# Call the function with a query that should match existing content
result = await search_prompt.fn("Root")
# Check the response contains expected content
assert 'Search Results for: "Root"' in result
assert "I found " in result
assert "You can view this content with: `read_note" in result
assert "Synthesize and Capture Knowledge" in result
@pytest.mark.asyncio
async def test_search_prompt_with_timeframe(client, test_graph):
"""Test search_prompt with a timeframe."""
# Call the function with a query and timeframe
result = await search_prompt.fn("Root", timeframe="1w")
# Check the response includes timeframe information
assert 'Search Results for: "Root" (after 7d)' in result
assert "I found " in result
@pytest.mark.asyncio
async def test_search_prompt_no_results(client):
"""Test search_prompt when no results are found."""
# Call with a query that won't match anything
result = await search_prompt.fn("XYZ123NonExistentQuery")
# Check the response indicates no results found
assert 'Search Results for: "XYZ123NonExistentQuery"' in result
assert "I couldn't find any results for this query" in result
assert "Opportunity to Capture Knowledge" in result
assert "write_note" in result
# Test utils
def test_prompt_context_with_file_path_no_permalink():
"""Test format_prompt_context with items that have file_path but no permalink."""
from basic_memory.mcp.prompts.utils import (
format_prompt_context,
PromptContext,
PromptContextItem,
)
from basic_memory.schemas.memory import EntitySummary
# Create a mock context with a file that has no permalink (like a binary file)
test_entity = EntitySummary(
type="entity",
title="Test File",
permalink=None, # No permalink
file_path="test_file.pdf",
created_at=datetime.now(timezone.utc),
)
context = PromptContext(
topic="Test Topic",
timeframe="1d",
results=[
PromptContextItem(
primary_results=[test_entity],
related_results=[test_entity], # Also use as related
)
],
)
# Format the context
result = format_prompt_context(context)
# Check that file_path is used when permalink is missing
assert "test_file.pdf" in result
assert "read_file" in result
# Recent activity prompt tests
@pytest.mark.asyncio
async def test_recent_activity_prompt(client, test_graph):
"""Test recent_activity_prompt."""
# Call the function
result = await recent_activity_prompt.fn(timeframe="1w")
# Check the response contains expected content
assert "Recent Activity" in result
assert "Opportunity to Capture Activity Summary" in result
assert "write_note" in result
@pytest.mark.asyncio
async def test_recent_activity_prompt_with_custom_timeframe(client, test_graph):
"""Test recent_activity_prompt with custom timeframe."""
# Call the function with a custom timeframe
result = await recent_activity_prompt.fn(timeframe="1d")
# Check the response includes the custom timeframe
assert "Recent Activity from (1d)" in result