-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest_memory_bounds_v64.py
More file actions
123 lines (103 loc) · 3.86 KB
/
Copy pathtest_memory_bounds_v64.py
File metadata and controls
123 lines (103 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
"""
Test v64: Memory module bounds enforcement
Verifies that:
1. BlackHoleVault stays under 5000 entries
2. LongTermMemoryEngine stays under 10000 entries
3. No unbounded accumulation
"""
import sys
import asyncio
import tempfile
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent
if str(REPO_ROOT) not in sys.path:
sys.path.insert(0, str(REPO_ROOT))
SCRIPT_RECOVERABLE_ERRORS = (
ImportError,
AttributeError,
RuntimeError,
TypeError,
ValueError,
OSError,
)
async def test_memory_bounds():
"""Test both memory modules stay bounded"""
print("=" * 60)
print("TESTING v64: MEMORY MODULE BOUNDS")
print("=" * 60)
# Test 1: BlackHoleVault
print("\n🧪 Testing BlackHoleVault bounds (max 5000)...")
try:
from core.memory.black_hole_vault import BlackHoleVault
with tempfile.TemporaryDirectory(prefix="aura_test_vault_") as vault_dir:
vault = BlackHoleVault(data_dir=vault_dir)
# Add many memories
for i in range(6000):
vault.add_memory(
text=f"Test memory {i}: " + ("x" * 100),
metadata={"index": i, "test": True}
)
final_count = len(vault.memories)
print(f" Added 6000 memories, vault contains: {final_count}")
print(f" ✓ Bounded: {final_count <= 5000} (expected ≤5000)")
if final_count > 5000:
print(f" ✗ FAILED: Vault exceeded cap! {final_count} > 5000")
return False
except SCRIPT_RECOVERABLE_ERRORS as e:
print(f" ✗ ERROR: {e}")
import traceback
traceback.print_exc()
return False
# Test 2: LongTermMemoryEngine
print("\n🧪 Testing LongTermMemoryEngine bounds (max 10000)...")
try:
from core.memory.long_term_memory_engine import LongTermMemoryEngine, TaggedMemory
import time
ltm = LongTermMemoryEngine()
# Simulate memory additions
for i in range(11000):
# Create TaggedMemory directly (simulating async context)
memory = TaggedMemory(
id=f"mem_{i}",
content=f"Test memory {i}" + ("x" * 50),
timestamp=time.time(),
emotional_valence=0.5,
importance=0.5 + (i % 10) * 0.05, # Vary importance
decay_rate=0.01,
last_rehearsed=time.time(),
tags=["test"]
)
ltm.memories.append(memory)
# Simulate the cap enforcement
if len(ltm.memories) > ltm._max_memories:
ltm.memories.sort(key=lambda m: (m.importance, m.timestamp))
keep_count = int(ltm._max_memories * 0.9)
ltm.memories = ltm.memories[-keep_count:]
final_count = len(ltm.memories)
print(f" Added 11000 memories, LTM contains: {final_count}")
print(f" ✓ Bounded: {final_count <= 10000} (expected ≤10000)")
if final_count > 10000:
print(f" ✗ FAILED: LTM exceeded cap! {final_count} > 10000")
return False
except SCRIPT_RECOVERABLE_ERRORS as e:
print(f" ✗ ERROR: {e}")
import traceback
traceback.print_exc()
return False
return True
async def main():
success = await test_memory_bounds()
print("\n" + "=" * 60)
if success:
print("✅ ALL MEMORY BOUNDS TESTS PASSED")
print(" - BlackHoleVault capped at 5000")
print(" - LongTermMemoryEngine capped at 10000")
print(" - No unbounded accumulation")
print(" - System ready for tool execution")
return 0
else:
print("❌ MEMORY BOUNDS TESTS FAILED")
return 1
if __name__ == '__main__':
sys.exit(asyncio.run(main()))