Skip to content

Commit c6e863c

Browse files
committed
Work on test failures
1 parent 5322526 commit c6e863c

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

agent_memory_server/cli.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
from agent_memory_server.utils.redis import ensure_search_index_exists, get_redis_conn
1616

1717

18-
# Set up logging
1918
configure_logging()
2019
logger = get_logger(__name__)
2120

22-
# Define the version
23-
VERSION = "0.2.0" # Matches the version in pyproject.toml
21+
VERSION = "0.2.0"
2422

2523

2624
@click.group()
@@ -68,6 +66,10 @@ def mcp(port: int, sse: bool):
6866
"""Run the MCP server."""
6967
import asyncio
7068

69+
# Update the port in settings FIRST
70+
settings.mcp_port = port
71+
72+
# Import mcp_app AFTER settings have been updated
7173
from agent_memory_server.mcp import mcp_app
7274

7375
async def setup_and_run():
@@ -83,9 +85,6 @@ async def setup_and_run():
8385
# Update the port in settings
8486
settings.mcp_port = port
8587

86-
# Update the port in the mcp_app
87-
mcp_app._port = port
88-
8988
click.echo(f"Starting MCP server on port {port}")
9089

9190
if sse:

tests/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
from agent_memory_server.messages import (
2424
MemoryMessage,
2525
)
26+
27+
# Import the module to access its global for resetting
28+
from agent_memory_server.utils import redis as redis_utils_module
2629
from agent_memory_server.utils.keys import Keys
2730
from agent_memory_server.utils.redis import ensure_search_index_exists
2831

@@ -64,7 +67,8 @@ def mock_openai_client():
6467
@pytest.fixture(autouse=True)
6568
async def search_index(async_redis_client):
6669
"""Create a Redis connection pool for testing"""
67-
# TODO: Replace with RedisVL index.
70+
# Reset the cached index in redis_utils_module
71+
redis_utils_module._index = None
6872

6973
await async_redis_client.flushdb()
7074

tests/test_long_term_memory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
search_long_term_memories,
1414
)
1515
from agent_memory_server.models import LongTermMemory, LongTermMemoryResult
16+
from agent_memory_server.utils.redis import ensure_search_index_exists
1617

1718

1819
class TestLongTermMemory:
@@ -162,6 +163,7 @@ class TestLongTermMemoryIntegration:
162163
@pytest.mark.asyncio
163164
async def test_search_messages(self, async_redis_client):
164165
"""Test searching messages"""
166+
await ensure_search_index_exists(async_redis_client)
165167

166168
long_term_memories = [
167169
LongTermMemory(text="Paris is the capital of France", session_id="123"),
@@ -192,6 +194,7 @@ async def test_search_messages(self, async_redis_client):
192194
@pytest.mark.asyncio
193195
async def test_search_messages_with_distance_threshold(self, async_redis_client):
194196
"""Test searching messages with a distance threshold"""
197+
await ensure_search_index_exists(async_redis_client)
195198

196199
long_term_memories = [
197200
LongTermMemory(text="Paris is the capital of France", session_id="123"),

tests/test_mcp.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from unittest import mock
23

34
import pytest
45
from mcp.shared.memory import (
@@ -12,11 +13,27 @@
1213
)
1314

1415

16+
@pytest.fixture
17+
async def mcp_test_setup(async_redis_client, search_index):
18+
with (
19+
mock.patch(
20+
"agent_memory_server.long_term_memory.get_redis_conn",
21+
return_value=async_redis_client,
22+
) as _mock_ltm_redis,
23+
mock.patch(
24+
"agent_memory_server.api.get_redis_conn",
25+
return_value=async_redis_client,
26+
create=True,
27+
) as _mock_api_redis,
28+
):
29+
yield
30+
31+
1532
class TestMCP:
1633
"""Test search functionality and memory prompt endpoints via client sessions."""
1734

1835
@pytest.mark.asyncio
19-
async def test_create_long_term_memory(self, session):
36+
async def test_create_long_term_memory(self, session, mcp_test_setup):
2037
async with client_session(mcp_app._mcp_server) as client:
2138
results = await client.call_tool(
2239
"create_long_term_memories",
@@ -31,7 +48,7 @@ async def test_create_long_term_memory(self, session):
3148
assert results.content[0].text == '{"status": "ok"}'
3249

3350
@pytest.mark.asyncio
34-
async def test_search_memory(self, session):
51+
async def test_search_memory(self, session, mcp_test_setup):
3552
"""Test searching through session memory using the client."""
3653
async with client_session(mcp_app._mcp_server) as client:
3754
results = await client.call_tool(
@@ -65,7 +82,7 @@ async def test_search_memory(self, session):
6582
assert results["memories"][1]["session_id"] == session
6683

6784
@pytest.mark.asyncio
68-
async def test_memory_prompt(self, session):
85+
async def test_memory_prompt(self, session, mcp_test_setup):
6986
"""Test memory prompt with various parameter combinations."""
7087
async with client_session(mcp_app._mcp_server) as client:
7188
prompt = await client.call_tool(
@@ -98,7 +115,7 @@ async def test_memory_prompt(self, session):
98115
assert "assistant: Hi there" in message["content"]["text"]
99116

100117
@pytest.mark.asyncio
101-
async def test_memory_prompt_error_handling(self, session):
118+
async def test_memory_prompt_error_handling(self, session, mcp_test_setup):
102119
"""Test error handling in memory prompt generation via the client."""
103120
async with client_session(mcp_app._mcp_server) as client:
104121
# Test with a non-existent session id

0 commit comments

Comments
 (0)