Cameron's void repo torn apart for local testing
1import uuid
2
3import memory_store
4from tools.memory_write import (
5 user_note_append,
6 user_note_replace,
7 user_note_set,
8 user_note_view,
9)
10
11
12def _create_block(tmp_path):
13 # simulate creating a block directly through the store for isolation
14 bid = str(uuid.uuid4())
15 blk = memory_store._Block(id=bid, label="test", value="", limit=None, attached_agents=[]) # type: ignore
16 memory_store._save_block(blk) # type: ignore
17 return bid
18
19
20def test_append_and_view(tmp_path, monkeypatch):
21 monkeypatch.setattr(memory_store, 'BASE_DIR', tmp_path)
22 tmp_path.mkdir(parents=True, exist_ok=True)
23 bid = _create_block(tmp_path)
24 r1 = user_note_append(bid, "First note")
25 assert "First note" in r1
26 r2 = user_note_append(bid, "Second note")
27 assert "Second note" in r2
28 view = user_note_view(bid, last=2)
29 assert "First note" in view and "Second note" in view
30
31
32def test_replace_flow(tmp_path, monkeypatch):
33 monkeypatch.setattr(memory_store, 'BASE_DIR', tmp_path)
34 tmp_path.mkdir(parents=True, exist_ok=True)
35 bid = _create_block(tmp_path)
36 user_note_append(bid, "Alpha")
37 out = user_note_replace(bid, "Alpha-Edited")
38 assert "Alpha-Edited" in out
39 view = user_note_view(bid, last=1)
40 # 'Alpha' substring will still appear inside 'Alpha-Edited'; just assert edited form present
41 assert "Alpha-Edited" in view
42
43
44def test_set_overwrites(tmp_path, monkeypatch):
45 monkeypatch.setattr(memory_store, 'BASE_DIR', tmp_path)
46 tmp_path.mkdir(parents=True, exist_ok=True)
47 bid = _create_block(tmp_path)
48 user_note_append(bid, "One")
49 user_note_append(bid, "Two")
50 user_note_set(bid, "Custom content block")
51 v = user_note_view(bid, last=5)
52 assert "Custom content block" in v
53 # After set, old note format may not persist
54 assert "One" not in v and "Two" not in v
55
56
57def test_errors(tmp_path, monkeypatch):
58 monkeypatch.setattr(memory_store, 'BASE_DIR', tmp_path)
59 tmp_path.mkdir(parents=True, exist_ok=True)
60 # invalid block
61 try:
62 user_note_append("missing", "x")
63 except Exception as e:
64 assert "Block not found" in str(e)
65 bid = _create_block(tmp_path)
66 try:
67 user_note_replace(bid, "")
68 except Exception as e:
69 assert "note cannot be empty" in str(e)
70 try:
71 user_note_replace(bid, "New")
72 except Exception as e:
73 assert "no existing notes" in str(e)