555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
97 lines
3.4 KiB
Python
97 lines
3.4 KiB
Python
import pytest
|
|
|
|
from mem0.memory import main as memory_main
|
|
from mem0.memory.main import AsyncMemory, Memory
|
|
|
|
|
|
def test_sync_add_timestamp_raises_before_validation(monkeypatch):
|
|
calls = []
|
|
|
|
def get_error(sync_type, trigger_function, trigger_parameter):
|
|
calls.append((sync_type, trigger_function, trigger_parameter))
|
|
return "blocked timestamp"
|
|
|
|
monkeypatch.setattr(memory_main, "get_temporal_feature_error_message", get_error)
|
|
|
|
with pytest.raises(ValueError, match="blocked timestamp"):
|
|
Memory.add(Memory.__new__(Memory), "hello", timestamp=123)
|
|
|
|
assert calls == [("sync", "add", "timestamp")]
|
|
|
|
|
|
def test_sync_search_reference_date_raises_before_validation(monkeypatch):
|
|
calls = []
|
|
|
|
def get_error(sync_type, trigger_function, trigger_parameter):
|
|
calls.append((sync_type, trigger_function, trigger_parameter))
|
|
return "blocked reference date"
|
|
|
|
monkeypatch.setattr(memory_main, "get_temporal_feature_error_message", get_error)
|
|
|
|
with pytest.raises(ValueError, match="blocked reference date"):
|
|
Memory.search(Memory.__new__(Memory), "what happened last week?", reference_date="2025-03-21")
|
|
|
|
assert calls == [("sync", "search", "reference_date")]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_async_add_timestamp_raises_before_validation(monkeypatch):
|
|
calls = []
|
|
|
|
async def get_error(sync_type, trigger_function, trigger_parameter):
|
|
calls.append((sync_type, trigger_function, trigger_parameter))
|
|
return "blocked async timestamp"
|
|
|
|
monkeypatch.setattr(memory_main, "get_temporal_feature_error_message_async", get_error)
|
|
|
|
with pytest.raises(ValueError, match="blocked async timestamp"):
|
|
await AsyncMemory.add(AsyncMemory.__new__(AsyncMemory), "hello", timestamp=123)
|
|
|
|
assert calls == [("async", "add", "timestamp")]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_async_search_reference_date_raises_before_validation(monkeypatch):
|
|
calls = []
|
|
|
|
async def get_error(sync_type, trigger_function, trigger_parameter):
|
|
calls.append((sync_type, trigger_function, trigger_parameter))
|
|
return "blocked async reference date"
|
|
|
|
monkeypatch.setattr(memory_main, "get_temporal_feature_error_message_async", get_error)
|
|
|
|
with pytest.raises(ValueError, match="blocked async reference date"):
|
|
await AsyncMemory.search(
|
|
AsyncMemory.__new__(AsyncMemory),
|
|
"what happened last week?",
|
|
reference_date="2025-03-21",
|
|
)
|
|
|
|
assert calls == [("async", "search", "reference_date")]
|
|
|
|
|
|
def test_sync_add_without_timestamp_does_not_call_temporal_feature_notice(monkeypatch):
|
|
get_error = monkeypatch.setattr(
|
|
memory_main,
|
|
"get_temporal_feature_error_message",
|
|
lambda *args: pytest.fail("temporal feature notice should not run"),
|
|
)
|
|
|
|
with pytest.raises(Exception, match="At least one of 'user_id', 'agent_id', or 'run_id'"):
|
|
Memory.add(Memory.__new__(Memory), "hello")
|
|
|
|
assert get_error is None
|
|
|
|
|
|
def test_sync_search_without_reference_date_does_not_call_temporal_feature_notice(monkeypatch):
|
|
get_error = monkeypatch.setattr(
|
|
memory_main,
|
|
"get_temporal_feature_error_message",
|
|
lambda *args: pytest.fail("temporal feature notice should not run"),
|
|
)
|
|
|
|
with pytest.raises(ValueError, match="filters must contain"):
|
|
Memory.search(Memory.__new__(Memory), "hello")
|
|
|
|
assert get_error is None
|