Skip to content

The agent that grows with you

test(memory): trim the journey identity tests to their invariants

kshitijk4poorcd8d70bb9577
diff --git a/tests/agent/test_learning_graph_render.py b/tests/agent/test_learning_graph_render.py
index 1e2acfe6903..2f603926ee4 100644
--- a/tests/agent/test_learning_graph_render.py
+++ b/tests/agent/test_learning_graph_render.py
@@ -125,15 +125,13 @@ def test_frames_play_through_grows_visibility():
assert fr["grid"]
-def test_memory_rows_carry_their_card_body_for_fingerprinted_ids(tmp_path, monkeypatch):
+def test_memory_rows_carry_their_card_body_for_fingerprinted_ids():
"""The chart looks a memory card up by node id. Node ids carry the card's fingerprint, so a
lookup keyed on the bare `memory:<source>:<index>` shape would render every body empty."""
- monkeypatch.setenv("HERMES_HOME", str(tmp_path))
- import hermes_constants
+ from hermes_constants import get_hermes_home
- monkeypatch.setattr(hermes_constants, "_cached_default_hermes_root", None, raising=False)
- memories = tmp_path / "memories"
- memories.mkdir(parents=True)
+ memories = get_hermes_home() / "memories"
+ memories.mkdir(parents=True, exist_ok=True)
(memories / "MEMORY.md").write_text("alpha note\n§\nbeta note", encoding="utf-8")
from agent.learning_graph import build_learning_graph
@@ -142,5 +140,4 @@ def test_memory_rows_carry_their_card_body_for_fingerprinted_ids(tmp_path, monke
payload = build_learning_graph()
rows = [n for bucket in render_frames(payload, cols=80, rows=24, frames=1)["buckets"] for n in bucket["nodes"]]
- assert [n["id"].count(":") for n in rows] == [3, 3]
assert sorted(n["body"] for n in rows) == ["alpha note", "beta note"]
diff --git a/tests/agent/test_learning_mutations.py b/tests/agent/test_learning_mutations.py
index 941d6815ae2..f04a3f842f3 100644
--- a/tests/agent/test_learning_mutations.py
+++ b/tests/agent/test_learning_mutations.py
@@ -238,80 +238,18 @@ def _journey_id(home, label: str) -> str:
return nodes[index]["id"]
-def test_the_id_journey_renders_names_the_cards_text(home):
- from agent.learning_graph import memory_fingerprint
-
- node_id = _journey_id(home, "beta")
-
- assert node_id.split(":")[:3] == ["memory", "memory", "1"]
- assert node_id.split(":")[3] == memory_fingerprint("beta note")
-
-
-def test_edit_targets_the_clicked_card_when_the_list_shifted_before_submit(home):
- """The window a displayed-index identity cannot see: another writer prepends an entry AFTER
- the graph is drawn and BEFORE the edit is submitted, so by the time the mutation reads the
[email protected]("op", ["edit", "delete"])
+def test_mutation_targets_the_clicked_card_when_the_list_shifted_before_submit(home, op):
+ """The window a displayed-index identity cannot see: an earlier entry is removed AFTER the
+ graph is drawn and BEFORE the edit/delete is submitted, so by the time the mutation reads the
file that index names somebody else's card."""
node_id = _journey_id(home, "beta") # what Journey showed the user
- _write_memory_file(home, "zeta first", "alpha note\nline two", "beta note")
-
- assert lm.edit_node(node_id, "beta rewritten")["ok"]
-
- assert _memory_entries(home) == ["zeta first", "alpha note\nline two", "beta rewritten"]
-
-
-def test_delete_targets_the_clicked_card_when_the_list_shifted_before_submit(home):
- node_id = _journey_id(home, "beta")
- _write_memory_file(home, "zeta first", "alpha note\nline two", "beta note")
-
- assert lm.delete_node(node_id)["ok"]
-
- assert _memory_entries(home) == ["zeta first", "alpha note\nline two"]
-
-
-def test_detail_prefills_the_clicked_card_after_a_shift(home):
- node_id = _journey_id(home, "beta")
- _write_memory_file(home, "zeta first", "alpha note\nline two", "beta note")
-
- assert lm.node_detail(node_id)["content"] == "beta note"
-
-
-def test_a_clicked_card_that_is_gone_refuses_even_though_its_index_still_exists(home):
- node_id = _journey_id(home, "beta")
- _write_memory_file(home, "alpha note\nline two", "gamma replaced beta")
+ _write_memory_file(home, "beta note", "gamma note")
- result = lm.edit_node(node_id, "beta rewritten")
+ mutate = (lambda: lm.edit_node(node_id, "beta rewritten")) if op == "edit" else (lambda: lm.delete_node(node_id))
+ assert mutate()["ok"]
+ assert _memory_entries(home) == (["beta rewritten", "gamma note"] if op == "edit" else ["gamma note"])
+ # The clicked card is gone now; its id must not fall back to whatever sits at that index.
+ result = mutate()
assert result["ok"] is False and "stale" in result["message"]
- assert _memory_entries(home) == ["alpha note\nline two", "gamma replaced beta"]
-
-
-def test_an_id_from_an_older_graph_still_resolves_by_position(home):
- """Pre-fingerprint ids (a cached graph, an older shell) keep working."""
- assert lm.edit_node("memory:memory:1", "beta rewritten")["ok"]
-
- assert _memory_entries(home) == ["alpha note\nline two", "beta rewritten"]
-
-
-def test_a_profile_card_resolves_through_its_fingerprinted_id(home):
- """USER.md cards sit after the MEMORY.md ones in the id's global index."""
- from agent.learning_graph import build_learning_graph
-
- profile = next(n for n in build_learning_graph()["nodes"] if n.get("memorySource") == "profile")
-
- assert lm.edit_node(profile["id"], "rewritten profile")["ok"]
-
- assert (home / "memories" / "USER.md").read_text(encoding="utf-8").strip() == "rewritten profile"
-
-
-def test_a_memory_longer_than_the_rendered_card_still_matches(home):
- """The card renders a truncated body; the fingerprint must digest the WHOLE entry or a long
- memory never matches itself."""
- from agent.learning_graph import build_learning_graph
-
- long_entry = "long memory " + ("x" * 2000)
- _write_memory_file(home, long_entry, "beta note")
- node = [n for n in build_learning_graph()["nodes"] if n["kind"] == "memory"][0]
-
- assert lm.node_detail(node["id"])["content"] == long_entry
- assert lm.edit_node(node["id"], "trimmed")["ok"]
- assert _memory_entries(home) == ["trimmed", "beta note"]