File size: 3,913 Bytes
dc893fb |
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 |
"""Test cases for Session Note Tool."""
import tempfile
from pathlib import Path
import pytest
from mini_agent.tools.note_tool import RecallNoteTool, SessionNoteTool
@pytest.mark.asyncio
async def test_record_and_recall_notes():
"""Test recording and recalling notes."""
print("\n=== Testing Note Record and Recall ===")
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".json") as f:
note_file = f.name
try:
# Create tools
record_tool = SessionNoteTool(memory_file=note_file)
recall_tool = RecallNoteTool(memory_file=note_file)
# Record a note
result = await record_tool.execute(
content="User prefers concise responses",
category="user_preference",
)
assert result.success
print(f"Record result: {result.content}")
# Record another note
result = await record_tool.execute(
content="Project uses Python 3.12",
category="project_info",
)
assert result.success
print(f"Record result: {result.content}")
# Recall all notes
result = await recall_tool.execute()
assert result.success
assert "User prefers concise responses" in result.content
assert "Python 3.12" in result.content
print(f"\nAll notes:\n{result.content}")
# Recall filtered by category
result = await recall_tool.execute(category="user_preference")
assert result.success
assert "User prefers concise responses" in result.content
assert "Python 3.12" not in result.content
print(f"\nFiltered notes:\n{result.content}")
print("✅ Note record and recall test passed")
finally:
Path(note_file).unlink(missing_ok=True)
@pytest.mark.asyncio
async def test_empty_notes():
"""Test recalling empty notes."""
print("\n=== Testing Empty Notes ===")
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".json") as f:
note_file = f.name
# Delete the file to test empty state
Path(note_file).unlink()
try:
recall_tool = RecallNoteTool(memory_file=note_file)
# Recall empty notes
result = await recall_tool.execute()
assert result.success
assert "No notes recorded yet" in result.content
print(f"Empty notes result: {result.content}")
print("✅ Empty notes test passed")
finally:
Path(note_file).unlink(missing_ok=True)
@pytest.mark.asyncio
async def test_note_persistence():
"""Test that notes persist across tool instances."""
print("\n=== Testing Note Persistence ===")
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".json") as f:
note_file = f.name
try:
# First instance - record note
record_tool1 = SessionNoteTool(memory_file=note_file)
result = await record_tool1.execute(
content="Important fact to remember",
category="test",
)
assert result.success
# Second instance - recall note (simulates new session)
recall_tool2 = RecallNoteTool(memory_file=note_file)
result = await recall_tool2.execute()
assert result.success
assert "Important fact to remember" in result.content
print(f"Persisted note: {result.content}")
print("✅ Note persistence test passed")
finally:
Path(note_file).unlink(missing_ok=True)
async def main():
"""Run all session note tool tests."""
print("=" * 80)
print("Running Session Note Tool Tests")
print("=" * 80)
await test_record_and_recall_notes()
await test_empty_notes()
await test_note_persistence()
print("\n" + "=" * 80)
print("All Session Note Tool tests passed! ✅")
print("=" * 80)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
|