兼容新版 EverOS memory API

This commit is contained in:
2026-06-10 10:47:36 +08:00
parent 64e3ea9631
commit 000415404b
5 changed files with 177 additions and 46 deletions

View File

@ -732,3 +732,117 @@ def test_everos_user_payload_uses_user_id_as_sender():
assert message["role"] == "user"
assert message["sender_id"] == "tom"
assert message["sender_name"] == "tom"
def test_everos_append_message_posts_current_memory_add_contract():
client = EverOSMemorySystemClient()
calls = []
responses = [FakeResponse(200, {"request_id": "req-1", "data": {"status": "accumulated", "message_count": 1}})]
client._client = lambda: FakeAsyncClient( # type: ignore[method-assign]
calls,
responses,
client.api_key or "",
{},
)
result = asyncio.run(client.append_message("tom", "sess-1", "user", "我喜欢拿铁"))
assert result == {"request_id": "req-1", "data": {"status": "accumulated", "message_count": 1}}
assert calls[0][0] == "post"
assert calls[0][3] == "/api/v1/memory/add"
payload = calls[0][4]
assert payload["session_id"] == "sess-1"
assert "user_id" not in payload
assert payload["messages"][0]["sender_id"] == "tom"
assert payload["messages"][0]["role"] == "user"
assert payload["messages"][0]["content"] == "我喜欢拿铁"
def test_everos_flush_posts_current_memory_flush_contract():
client = EverOSMemorySystemClient()
calls = []
responses = [FakeResponse(200, {"request_id": "req-1", "data": {"status": "extracted"}})]
client._client = lambda: FakeAsyncClient( # type: ignore[method-assign]
calls,
responses,
client.api_key or "",
{},
)
result = asyncio.run(client.flush("tom", "sess-1"))
assert result == {"request_id": "req-1", "data": {"status": "extracted"}}
assert calls == [
(
"post",
client.api_key or "",
{},
"/api/v1/memory/flush",
{"session_id": "sess-1"},
None,
)
]
def test_everos_search_posts_current_memory_search_contract():
client = EverOSMemorySystemClient()
calls = []
responses = [FakeResponse(200, {"request_id": "req-1", "data": {"episodes": []}})]
client._client = lambda: FakeAsyncClient( # type: ignore[method-assign]
calls,
responses,
client.api_key or "",
{},
)
result = asyncio.run(client.search("tom", "sess-1", "牛奶在哪里", "hybrid", 7))
assert result == {"request_id": "req-1", "data": {"episodes": []}}
assert calls == [
(
"post",
client.api_key or "",
{},
"/api/v1/memory/search",
{
"user_id": "tom",
"query": "牛奶在哪里",
"method": "hybrid",
"top_k": 7,
"include_profile": True,
"filters": {"session_id": "sess-1"},
},
None,
)
]
def test_everos_get_profile_posts_current_memory_get_contract():
client = EverOSMemorySystemClient()
calls = []
responses = [FakeResponse(200, {"request_id": "req-1", "data": {"profiles": []}})]
client._client = lambda: FakeAsyncClient( # type: ignore[method-assign]
calls,
responses,
client.api_key or "",
{},
)
result = asyncio.run(client.get_profile("tom"))
assert result == {"request_id": "req-1", "data": {"profiles": []}}
assert calls == [
(
"post",
client.api_key or "",
{},
"/api/v1/memory/get",
{
"user_id": "tom",
"memory_type": "profile",
"page": 1,
"page_size": 20,
},
None,
)
]