test: cover path-isolated memory cache and restart persistence
This commit is contained in:
1 parent
d449fd6905
commit
fc2275ca06
1 file changed
+26
@@ -0,0 +1,26 @@
|
|||||||
|
"""Regression tests for durable global memory."""
|
||||||
|
|
||||||
|
from homeagent.memory.global_memory import GlobalMemory, get_global_memory
|
||||||
|
|
||||||
|
|
||||||
|
def test_global_memory_survives_new_instance_and_uses_atomic_file(tmp_path):
|
||||||
|
path = tmp_path / "data" / "global_memory.json"
|
||||||
|
memory = GlobalMemory(path)
|
||||||
|
item = memory.add_fact("Не терять память после рестарта", category="reliability")
|
||||||
|
|
||||||
|
restarted = GlobalMemory(path)
|
||||||
|
assert restarted.search("рестарта")[0].id == item.id
|
||||||
|
assert path.read_text(encoding="utf-8").startswith("[")
|
||||||
|
assert not list(path.parent.glob("*.tmp"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_global_memory_singleton_isolated_by_path(tmp_path):
|
||||||
|
first_path = tmp_path / "one.json"
|
||||||
|
second_path = tmp_path / "two.json"
|
||||||
|
|
||||||
|
first = get_global_memory(first_path)
|
||||||
|
second = get_global_memory(second_path)
|
||||||
|
assert first is not second
|
||||||
|
|
||||||
|
first.add_fact("только в первом хранилище")
|
||||||
|
assert second.list_facts() == []
|
||||||
Reference in new issue
Block a user