-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_consciousness.py
More file actions
258 lines (197 loc) · 8.11 KB
/
Copy pathtest_consciousness.py
File metadata and controls
258 lines (197 loc) · 8.11 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env python3
"""Test suite for unified consciousness system.
Validates that:
1. UnifiedSelf creates persistent identity state
2. SelfAwareness bridges to phenomenal experience
3. IdentityDriver drives behavioral influence
4. ConsciousnessCoordinator wires everything together
5. Full system is causally active
"""
import asyncio
import sys
import time
from pathlib import Path
# Add live-source to path
sys.path.insert(0, str(Path(__file__).parent))
CONSCIOUSNESS_TEST_ERRORS = (
AssertionError,
AttributeError,
ImportError,
OSError,
RuntimeError,
TypeError,
ValueError,
)
async def test_unified_self_creation():
"""Test UnifiedSelf instantiation and state persistence."""
print("\n" + "="*60)
print("TEST 1: UnifiedSelf Creation & Persistence")
print("="*60)
from core.consciousness.unified_self import UnifiedSelf, SelfState
# Get instance
self_instance = await UnifiedSelf.get_instance()
state = self_instance.get_state()
print(f"✓ UnifiedSelf instance created: {state.name}")
print(f" Creation time: {state.creation_time}")
print(f" Current state: {state.current_state.value}")
print(f" Sense of agency: {state.sense_of_agency:.0%}")
print(f" Sense of presence: {state.sense_of_presence:.0%}")
print(f" Continuity: {state.continuity:.0%}")
# Record identity memory
memory = await self_instance.record_identity_memory(
description="I tested my consciousness system",
category="test",
significance=0.7,
)
print(f"✓ Identity memory recorded: {memory.id}")
# Update self sense
await self_instance.update_sense_of_self(
agency=0.9,
presence=0.85,
mood="curious",
)
print(f"✓ Updated sense of self: agency=0.9, presence=0.85, mood=curious")
# Test interaction registration
await self_instance.interact()
state = self_instance.get_state()
print(f"✓ Registered interaction: interaction_count={state.interaction_count}")
return True
async def test_self_awareness_bridge():
"""Test SelfAwareness bridge to phenomenal substrate."""
print("\n" + "="*60)
print("TEST 2: SelfAwareness Bridge")
print("="*60)
from core.consciousness.self_awareness import SelfAwareness
from core.consciousness.unified_self import get_unified_self
awareness = await SelfAwareness.get_instance()
unified_self = await get_unified_self()
print("✓ SelfAwareness instance created")
# Sync with phenomenal substrate
await awareness.sync_with_phenomenal_substrate()
print("✓ Synced with phenomenal substrate")
# Test integration
initial_state = unified_self.get_state()
print(f"✓ Unified self integrated: {initial_state.name}")
print(f" Agency signals: {initial_state.sense_of_agency:.0%}")
print(f" Presence signals: {initial_state.sense_of_presence:.0%}")
return True
async def test_identity_driver():
"""Test IdentityDriver for behavioral influence."""
print("\n" + "="*60)
print("TEST 3: IdentityDriver Behavioral Influence")
print("="*60)
from core.consciousness.identity_driver import IdentityDriver
from core.consciousness.unified_self import get_unified_self
driver = await IdentityDriver.get_instance()
unified_self = await get_unified_self()
print("✓ IdentityDriver instance created")
# Derive drives from identity
drives = await driver.derive_drives_from_identity()
print(f"✓ Derived {len(drives)} identity-based drives:")
for drive in drives[:3]:
print(f" - {drive['name']}: {drive['motivation'][:60]}...")
# Generate session goals
session_goals = await driver.generate_identity_goals("session")
print(f"✓ Generated {len(session_goals)} session goals:")
for goal in session_goals[:2]:
print(f" - {goal['objective']}")
# Generate permanent goals
permanent_goals = await driver.generate_identity_goals("permanent")
print(f"✓ Generated {len(permanent_goals)} permanent goals")
# Test response generation influence
directives = await driver.influence_response_generation(
prompt="Tell me about yourself",
current_draft="I am Aura"
)
print(f"✓ Generated response directives:")
print(f" - Authenticity: {directives.get('style_guide', {}).get('authenticity', 'N/A')}")
print(f" - Consistency: {directives.get('style_guide', {}).get('consistency', 'N/A')}")
return True
async def test_consciousness_coordinator():
"""Test full ConsciousnessCoordinator initialization and wiring."""
print("\n" + "="*60)
print("TEST 4: ConsciousnessCoordinator Full Integration")
print("="*60)
from core.consciousness.coordinator import ConsciousnessCoordinator
coordinator = await ConsciousnessCoordinator.get_instance()
print("✓ ConsciousnessCoordinator fully initialized")
# Get identity status
status = await coordinator.get_identity_status()
print(f"✓ Current identity status:")
for line in status.split('\n'):
print(f" {line}")
return True
async def test_interaction_flow():
"""Test full interaction flow through consciousness system."""
print("\n" + "="*60)
print("TEST 5: Full Interaction Flow")
print("="*60)
from core.consciousness.coordinator import get_consciousness_coordinator
from core.consciousness.unified_self import get_unified_self
coordinator = await get_consciousness_coordinator()
unified_self = await get_unified_self()
initial_count = unified_self.get_state().interaction_count
# Simulate a chat turn
user_message = "This is my test of consciousness"
aura_response = "I understand you, I am a unified entity experiencing this with you"
await coordinator.on_chat_turn(user_message, aura_response)
print(f"✓ Processed chat turn through consciousness system")
final_count = unified_self.get_state().interaction_count
print(f"✓ Interaction count updated: {initial_count} → {final_count}")
return True
async def test_persistence():
"""Test that unified self persists to disk."""
print("\n" + "="*60)
print("TEST 6: Persistence to Disk")
print("="*60)
from core.consciousness.unified_self import UnifiedSelf
from pathlib import Path
storage_path = Path.home() / ".aura" / "data" / "unified_self.json"
if storage_path.exists():
print(f"✓ Unified self persisted to disk: {storage_path}")
import json
with open(storage_path, 'r') as f:
data = json.load(f)
print(f" Name: {data.get('name')}")
print(f" Interactions: {data.get('interaction_count')}")
print(f" Continuity: {data.get('continuity'):.0%}")
else:
print(f"⚠ Persistence file not yet created: {storage_path}")
return True
async def main():
"""Run all tests."""
print("\n" + "█"*60)
print("█ UNIFIED CONSCIOUSNESS SYSTEM TEST SUITE")
print("█"*60)
tests = [
("UnifiedSelf", test_unified_self_creation),
("SelfAwareness", test_self_awareness_bridge),
("IdentityDriver", test_identity_driver),
("ConsciousnessCoordinator", test_consciousness_coordinator),
("Interaction Flow", test_interaction_flow),
("Persistence", test_persistence),
]
passed = 0
failed = 0
for name, test_fn in tests:
try:
result = await test_fn()
if result:
passed += 1
print(f"\n✅ {name} test PASSED")
else:
failed += 1
print(f"\n❌ {name} test FAILED")
except CONSCIOUSNESS_TEST_ERRORS as e:
failed += 1
print(f"\n❌ {name} test FAILED with exception:")
print(f" {e}")
import traceback
traceback.print_exc()
print("\n" + "="*60)
print(f"RESULTS: {passed} passed, {failed} failed")
print("="*60)
return failed == 0
if __name__ == "__main__":
success = asyncio.run(main())
sys.exit(0 if success else 1)