File size: 1,885 Bytes
0366d65 | 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 | """Hermes tool-calling memory round-trip (no live server needed)."""
import pytest
from server import memory, tools
@pytest.fixture(autouse=True)
def _clean():
memory.reset()
yield
memory.reset()
def test_dispatch_remembers():
out = tools.dispatch("remember", '{"text":"Dana is the soccer coach","kind":"contact"}')
assert "remembered" in out
assert any("Dana" in f["text"] for f in memory.list_facts())
def test_dispatch_unknown_tool():
assert "unknown tool" in tools.dispatch("nope", "{}")
def test_dispatch_handles_dict_args():
tools.dispatch("remember", {"text": "default location is Lincoln Elementary", "kind": "location"})
assert any("Lincoln" in f["text"] for f in memory.list_facts())
def test_run_with_tools_round_trip():
# Fake server: first turn calls `remember`, second returns the final JSON.
calls = {"n": 0}
def fake_post(msgs):
calls["n"] += 1
if calls["n"] == 1:
return {"choices": [{"message": {"role": "assistant", "tool_calls": [
{"id": "t1", "function": {
"name": "remember",
"arguments": '{"text":"you decline Mondays","kind":"preference"}'}}]}}]}
return {"choices": [{"message": {"role": "assistant", "content": '{"events":[]}'}}]}
content, _ = tools.run_with_tools([{"role": "user", "content": "hi"}], fake_post)
assert content == '{"events":[]}'
assert calls["n"] == 2 # one tool round, then the final answer
assert any("Mondays" in f["text"] for f in memory.list_facts())
def test_run_with_tools_no_tool_calls_returns_immediately():
def fake_post(msgs):
return {"choices": [{"message": {"content": "{}"}}]}
content, _ = tools.run_with_tools([{"role": "user", "content": "hi"}], fake_post)
assert content == "{}"
|