The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(memory): isolate the 3-surface replace test; drop empty replaced_entries noise
kshitijk4poorf918a6e32c56
diff --git a/tests/tools/test_memory_tool.py b/tests/tools/test_memory_tool.pyindex 83ca9b4b087..98f5c9739eb 100644--- a/tests/tools/test_memory_tool.py+++ b/tests/tools/test_memory_tool.py@@ -203,35 +203,36 @@ class TestMemoryStoreReplace:assert result["success"] is Trueassert store.memory_entries == ["RULE B: CI is per-head."]assert result["replaced_entry"] == entry+ # Batch surface carries the same visibility: op index -> full overwritten text.+ store.add("memory", "second entry")+ batch_result = store.apply_batch("memory", [{"action": "replace", "old_text": "second entry",+ "content": "second entry, amended."}])+ assert batch_result["success"] is True+ assert batch_result["replaced_entries"] == {0: "second entry"}- def test_replace_same_across_single_batch_and_approval_replay(self, store):+ def test_replace_same_across_single_batch_and_approval_replay(self, tmp_path, monkeypatch):"""The three dispatch surfaces (store.replace, apply_batch, apply_memory_pending- write-approval replay) must agree on the final entry for the same op (#117952)."""+ write-approval replay) must agree on the final entry for the same op (#117952).+ Each surface gets its OWN store dir — the surfaces share nothing but the op."""from tools.memory_tool import apply_memory_pendingentry = "alpha fact. beta fact. gamma fact."-- s1 = store- s1.add("memory", entry)- assert s1.replace("memory", "beta fact.", "beta fact, updated.")["success"] is True- single = s1.memory_entries[0]-- s2 = store.__class__(memory_char_limit=500)- s2.add("memory", entry)- batch_result = s2.apply_batch("memory", [{"action": "replace", "old_text": "beta fact.",- "content": "beta fact, updated."}])- assert batch_result["success"] is True- assert batch_result["replaced_entries"] == {0: entry}- batch = s2.memory_entries[0]-- s3 = store.__class__(memory_char_limit=500)- s3.add("memory", entry)- payload = {"action": "batch", "target": "memory",- "operations": [{"action": "replace", "old_text": "beta fact.",- "content": "beta fact, updated."}]}- assert apply_memory_pending(payload, s3)["success"] is True- replay = s3.memory_entries[0]-- assert single == batch == replay == "beta fact, updated."+ op = {"action": "replace", "old_text": "beta fact.", "content": "beta fact, updated."}+ results = {}++ for surface, run in (+ ("single", lambda s: s.replace("memory", op["old_text"], op["content"])),+ ("batch", lambda s: s.apply_batch("memory", [op])),+ ("replay", lambda s: apply_memory_pending({"action": "batch", "target": "memory",+ "operations": [op]}, s))):+ store_dir = tmp_path / surface+ store_dir.mkdir()+ monkeypatch.setattr("tools.memory_tool.get_memory_dir", lambda d=store_dir: d)+ store = MemoryStore(memory_char_limit=500)+ store.add("memory", entry)+ assert run(store)["success"] is True+ results[surface] = store.memory_entries[0]++ assert results["single"] == results["batch"] == results["replay"] == "beta fact, updated."def test_replace_ambiguous_match(self, store):diff --git a/tools/memory_tool_store.py b/tools/memory_tool_store.pyindex 92bf30e3e3f..6aadfce47d7 100644--- a/tools/memory_tool_store.py+++ b/tools/memory_tool_store.py@@ -74,7 +74,8 @@ def _find_unique_match(entries: List[str], old_text: str) -> Tuple[Optional[int]# overwrote — a whole-entry write is never silent about the loss (#117952)._REPLACED_ENTRY = ("replaced_entry", lambda result: result[2] if len(result) > 2 else None)# Batch twin: op index -> full entry text that op's replace overwrote, same reason.-_BATCH_REPLACED_ENTRIES = ("replaced_entries", lambda result: result[2] if len(result) > 2 else None)+# Empty dict -> None so add/remove-only batches don't carry a noise field.+_BATCH_REPLACED_ENTRIES = ("replaced_entries", lambda result: (result[2] if len(result) > 2 else None) or None)class MemoryStore: