Repository navigation
Expand file tree
/
Copy pathtest_audit.py
More file actions
36 lines (28 loc) · 1.53 KB
/
Copy pathtest_audit.py
File metadata and controls
36 lines (28 loc) · 1.53 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
"""Proves the governance edge: every memory carries an auditable access/lifecycle
trail, deletions are logged, and the whole thing is exportable — "what does the AI
know about this user, who touched it, and what happened to it." No API key needed.
Run: python3 test_audit.py
"""
from cortex.memory_engine import MemoryEngine
eng = MemoryEngine()
eng.agent_name = "assistant"
m = eng.add("The user is allergic to nuts", "fact", 0.95, source="onboarding chat")
# a DIFFERENT agent reads it twice
eng.agent_name = "code-helper"
eng.retrieve("is the user allergic to nuts")
eng.retrieve("what is the user allergic to")
print("Per-memory audit trail:")
for e in m.audit:
print(f" {e['action']:10} by {e['agent']:12} {e.get('query','')}")
assert any(e["action"] == "create" for e in m.audit), "create not audited"
assert sum(1 for e in m.audit if e["action"] == "access") >= 2, "accesses not audited"
assert m.audit[0].get("agent") == "assistant", "provenance/agent not captured"
# right-to-be-forgotten: deletion is still logged
eng.supersede(lambda x: x.id == m.id, reason="user requested deletion")
report = eng.export_audit(m.id)
print(f"\nExportable audit for this memory: {len(report)} events")
for e in report:
print(f" {e['action']:10} · {e['agent']:12} · {e.get('reason', e.get('query',''))}")
assert any(e["action"] == "supersede" for e in report), "deletion not logged"
assert eng._by_id(m.id) is None, "memory should be gone after supersede"
print("\nPASS: per-access audit trail + provenance, deletion logged, full trail exportable.")