hermes-agent/tests/agent/test_memory_write_bridge.py
Hao Zhe 70e7132e2f fix(openviking): gate memory writes and add viking_forget
Mirror built-in memory writes to external providers only after the native memory tool succeeds and is not staged for approval. Keep OpenViking's built-in memory mirroring add-only, since Hermes native memory entries do not yet have stable OpenViking file URIs for replace/remove.

Add a narrow viking_forget tool for exact user memory file deletion and document the current OpenViking write/delete behavior.
2026-06-22 07:00:42 -07:00

84 lines
2.3 KiB
Python

import json
from agent.memory_write_bridge import collect_memory_write_notifications
def test_collect_notifications_includes_remove_with_old_text_after_success():
notifications = collect_memory_write_notifications(
json.dumps({"success": True}),
{
"action": "remove",
"target": "memory",
"old_text": "stale preference entry",
},
)
assert notifications == [
{
"action": "remove",
"target": "memory",
"content": "",
"old_text": "stale preference entry",
}
]
def test_collect_notifications_skips_failed_memory_write():
notifications = collect_memory_write_notifications(
json.dumps({"success": False, "error": "No entry matched"}),
{
"action": "remove",
"target": "memory",
"old_text": "stale preference entry",
},
)
assert notifications == []
def test_collect_notifications_skips_staged_memory_write():
notifications = collect_memory_write_notifications(
json.dumps({"success": True, "staged": True, "pending_id": "abc123"}),
{
"action": "remove",
"target": "memory",
"old_text": "stale preference entry",
},
)
assert notifications == []
def test_collect_notifications_preserves_old_text_for_replace_and_remove_batch():
notifications = collect_memory_write_notifications(
json.dumps({"success": True}),
{
"target": "user",
"operations": [
{"action": "replace", "old_text": "old preference", "content": "updated"},
{"action": "remove", "old_text": "obsolete preference"},
{"action": "add", "content": "new fact"},
],
},
)
assert notifications == [
{
"action": "replace",
"target": "user",
"content": "updated",
"old_text": "old preference",
},
{
"action": "remove",
"target": "user",
"content": "",
"old_text": "obsolete preference",
},
{
"action": "add",
"target": "user",
"content": "new fact",
"old_text": "",
},
]