Codexcoder commited on
Commit
94010b9
Β·
verified Β·
1 Parent(s): 975125b

kyrexis: add tests/test_kyrexis.py

Browse files
Files changed (1) hide show
  1. tests/test_kyrexis.py +257 -0
tests/test_kyrexis.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """KYREXIS AI module tests β€” core, skills, messenger, photonic, particle, progression."""
2
+
3
+ import asyncio
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ import pytest
8
+
9
+ ROOT = Path(__file__).resolve().parent.parent
10
+ sys.path.insert(0, str(ROOT))
11
+
12
+
13
+ def _core():
14
+ from kyrexis.core import KyrexisCore
15
+
16
+ return KyrexisCore().initialize()
17
+
18
+
19
+ # ── Core ──────────────────────────────────────────────────────────────────
20
+ def test_core_anchor_values():
21
+ c = _core()
22
+ s = c.get_state()
23
+ assert s["quantum_qubits"] == 53
24
+ assert s["entanglement_pairs"] == 847
25
+ assert abs(s["fidelity"] - 0.999423) < 1e-6
26
+ assert s["awakening_percent"] == pytest.approx(87.4, abs=0.01)
27
+ assert s["lineage_anchors"] == 12
28
+ assert s["temporal_horizon_years"] == 20
29
+ assert s["growth_rate_percent"] == pytest.approx(33.5)
30
+ assert s["quantum_circuits"] == 53
31
+ assert s["temporal_models"] == 20
32
+
33
+
34
+ def test_quantum_compute_simulation():
35
+ import numpy as np
36
+
37
+ c = _core()
38
+ out = c.quantum_compute(np.array([1.0, 2.0, 3.0]))
39
+ assert out.shape == (3,)
40
+ assert isinstance(out[0], float)
41
+
42
+
43
+ def test_predict_future_20y():
44
+ c = _core()
45
+ r = c.predict_future(100.0, years=20)
46
+ assert r["years"] == 20
47
+ assert r["growth_factor"] == pytest.approx((1.335) ** 20, rel=1e-3)
48
+ assert r["future_value"] == pytest.approx(100.0 * (1.335) ** 20, rel=1e-3)
49
+
50
+
51
+ def test_quantum_encrypt_deterministic_key():
52
+ c = _core()
53
+ a = c.quantum_encrypt("secret")
54
+ assert isinstance(a, str) and len(a) == 64 # sha256 hex
55
+
56
+
57
+ def test_self_improve_increases():
58
+ c = _core()
59
+ before = c.state.awakening
60
+ c.self_improve()
61
+ assert c.state.awakening > before
62
+
63
+
64
+ def test_explore_multiverse_branches():
65
+ c = _core()
66
+ r = c.explore_multiverse()
67
+ assert r["branches"] == 847
68
+ assert len(r["top_branches"]) == 10
69
+
70
+
71
+ def test_temporal_scenario():
72
+ c = _core()
73
+ r = c.analyze_temporal_scenario({"name": "test", "impact": 1.0})
74
+ assert len(r["outcomes"]) == 20
75
+ assert 1 <= r["best_year"] <= 20
76
+
77
+
78
+ # ── Quantum skills engine ─────────────────────────────────────────────────
79
+ def test_skills_registry():
80
+ from kyrexis.quantum_skills import QuantumSkillsEngine
81
+
82
+ eng = QuantumSkillsEngine(_core())
83
+ status = eng.get_skill_status()
84
+ assert status["total_skills"] == 5
85
+ ids = {s["id"] for s in status["skills"]}
86
+ assert {"strategic_planning", "risk_assessment", "innovation_generation",
87
+ "decision_support", "complex_problem_solving"} <= ids
88
+
89
+
90
+ def test_execute_skill_and_cooldown():
91
+ from kyrexis.quantum_skills import QuantumSkillsEngine
92
+
93
+ eng = QuantumSkillsEngine(_core())
94
+ r = eng.execute_skill("strategic_planning", {"horizon_years": 5})
95
+ assert r["skill"] == "strategic_planning"
96
+ assert r["result"]["growth_factor"] == pytest.approx((1.335) ** 5, rel=1e-2)
97
+ # Immediately re-executing hits the cooldown
98
+ again = eng.execute_skill("strategic_planning")
99
+ assert "cooldown" in again.get("error", "")
100
+
101
+
102
+ def test_unknown_skill():
103
+ from kyrexis.quantum_skills import QuantumSkillsEngine
104
+
105
+ eng = QuantumSkillsEngine(_core())
106
+ assert "not found" in eng.execute_skill("nope")["error"]
107
+
108
+
109
+ # ── Messenger integration ─────────────────────────────────────────────────
110
+ def test_messenger_local_mode():
111
+ from kyrexis.messenger_integration import KyrexisMessengerIntegration, MessengerMessage
112
+
113
+ m = KyrexisMessengerIntegration().initialize(_core())
114
+ assert m.get_status()["active"] is True
115
+ assert m.get_status()["kyrexis_connected"] is True
116
+ resp = m.process_message(MessengerMessage("r1", "s1", "hello kyrexis", 0.0))
117
+ assert "Kyrexis AI" in resp
118
+ assert len(m.get_conversation("s1")) == 1
119
+
120
+
121
+ def test_messenger_webhook():
122
+ from kyrexis.messenger_integration import KyrexisMessengerIntegration
123
+
124
+ m = KyrexisMessengerIntegration().initialize(_core())
125
+ payload = {
126
+ "entry": [{
127
+ "sender": {"id": "user1"},
128
+ "messaging": [{"message": {"text": "hi"}, "timestamp": 1.0}],
129
+ }]
130
+ }
131
+ out = m.handle_webhook(payload)
132
+ assert out["status"] == "success"
133
+ assert out["processed"] == 1
134
+
135
+
136
+ # ── Photonic display ──────────────────────────────────────────────────────
137
+ def test_photonic_display_specs():
138
+ from kyrexis.photonic_display import LaserCrystalPhotonicDisplay
139
+
140
+ d = LaserCrystalPhotonicDisplay().initialize()
141
+ s = d.get_display_state()
142
+ assert s["crystal"]["type"].startswith("Periodically Poled")
143
+ assert s["crystal"]["wavelength"] == 775
144
+ assert s["slm"]["resolution"] == [1024, 1024]
145
+ assert s["apd"]["sensitivity"] == 1e-12
146
+ assert s["quantum_processor"]["qubits"] == 53
147
+ assert s["quantum_processor"]["error_correction"] == "Surface Code"
148
+
149
+
150
+ def test_photonic_display_loop_small():
151
+ from kyrexis.photonic_display import LaserCrystalPhotonicDisplay
152
+
153
+ d = LaserCrystalPhotonicDisplay().initialize()
154
+
155
+ async def run():
156
+ return await d.display_loop(duration=0.05, frame_interval=0.01)
157
+
158
+ frames = asyncio.run(run())
159
+ assert frames >= 1
160
+ assert d.get_display_state()["total_frames"] >= 1
161
+
162
+
163
+ # ── Particle detector ─────────────────────────────────────────────────────
164
+ def test_particle_detection_and_verification():
165
+ from kyrexis.particle_detector import ParticlePairDetector
166
+
167
+ det = ParticlePairDetector().initialize()
168
+ pair = det.detect_particle_pair()
169
+ assert pair.id.startswith("pp_")
170
+ assert pair.fidelity == 0.999423
171
+ v = det.verify_entanglement(pair)
172
+ assert set(v) >= {"concurrence", "negativity", "bell_fidelity", "entangled"}
173
+ tomo = det.quantum_state_tomography(pair)
174
+ assert set(tomo["expectations"]) == {"I", "X", "Y", "Z"}
175
+
176
+
177
+ def test_bell_inequality():
178
+ from kyrexis.particle_detector import ParticlePairDetector
179
+
180
+ det = ParticlePairDetector()
181
+ # Classical correlations: S = 1 - 0.9 + 0.9 + 1 = 2.0 (boundary, not violated)
182
+ classical = det.bell_inequality_test([[1.0, 0.9], [0.9, 1.0]])
183
+ assert classical["violated"] is False
184
+ assert classical["S_value"] == pytest.approx(2.0, rel=1e-3)
185
+ # Quantum correlations: S = 1 + 0.7 + 0.7 + 1 = 3.4 > 2 (violated)
186
+ quantum = det.bell_inequality_test([[1.0, -0.7], [0.7, 1.0]])
187
+ assert quantum["violated"] is True
188
+ assert quantum["S_value"] == pytest.approx(3.4, rel=1e-3)
189
+
190
+
191
+ # ── Progression scaling ───────────────────────────────────────────────────
192
+ def test_progression_anchors():
193
+ from kyrexis.progression_scaling import ProgressionScalingEngine
194
+
195
+ p = ProgressionScalingEngine()
196
+ summary = p.get_summary()
197
+ assert summary["total_years"] == 20
198
+ assert summary["annual_growth_rate_percent"] == pytest.approx(33.5)
199
+ assert summary["total_growth_factor"] == pytest.approx(368.4, abs=1.0)
200
+ assert summary["max_achievement_percent"] == pytest.approx(96.1, abs=0.1)
201
+ assert summary["scaling_factor"] == 4
202
+ assert len(p.get_full_progression()) == 20
203
+
204
+
205
+ def test_progression_20y_values():
206
+ from kyrexis.progression_scaling import ProgressionScalingEngine
207
+
208
+ p = ProgressionScalingEngine()
209
+ y1 = p.get_progression_at_year(1)
210
+ y20 = p.get_progression_at_year(20)
211
+ assert y1["growth_factor"] == pytest.approx(1.335, rel=1e-2)
212
+ # Engine computes the honest (1.335)^20 β‰ˆ 323x; the spec's 368.4x
213
+ # headline is a stated parameter, not the computed CAGR result.
214
+ assert y20["growth_factor"] == pytest.approx((1.335) ** 20, rel=1e-3)
215
+ assert y20["growth_factor_scaled"] == pytest.approx(4 * (1.335) ** 20, rel=1e-3)
216
+ assert p.get_progression_at_year(0)["error"]
217
+ assert p.get_progression_at_year(21)["error"]
218
+
219
+
220
+ def test_progression_projection():
221
+ from kyrexis.progression_scaling import ProgressionScalingEngine
222
+
223
+ p = ProgressionScalingEngine()
224
+ proj = p.calculate_20_year_projection(100.0)
225
+ assert len(proj["projection"]) == 20
226
+ assert proj["final_value_scaled"] == pytest.approx(proj["final_value"] * 4, rel=1e-6)
227
+
228
+
229
+ # ── Universal agent network ───────────────────────────────────────────────
230
+ def test_agent_network():
231
+ from kyrexis.agents import UniversalAgentNetwork, UNIVERSAL_TASKS
232
+
233
+ net = UniversalAgentNetwork()
234
+ assert len(net.agents) == 21
235
+ assert len(UNIVERSAL_TASKS) == 5
236
+ status = net.status()
237
+ assert set(status["tiers"]) == {"Earth", "Solar System", "Galactic", "Cosmic", "Meta"}
238
+ assert net.get_agent("terra").name == "Agent Terra"
239
+ assert net.get_agent("Agent Time") is not None
240
+ net.activate()
241
+ assert len(net.sync()["agents"]) == 21
242
+
243
+
244
+ # ── API surface ───────────────────────────────────────────────────────────
245
+ def test_api_router_paths():
246
+ from kyrexis.api.routes import router
247
+
248
+ paths = {route.path for route in router.routes}
249
+ assert "/api/v1/kyrexis/initialize" in paths
250
+ assert "/api/v1/kyrexis/status" in paths
251
+ assert "/api/v1/kyrexis/quantum/compute" in paths
252
+ assert "/api/v1/kyrexis/skills/{skill_id}" in paths
253
+ assert "/api/v1/kyrexis/messenger/webhook" in paths
254
+ assert "/api/v1/kyrexis/photonic/pulse" in paths
255
+ assert "/api/v1/kyrexis/particle/detect" in paths
256
+ assert "/api/v1/kyrexis/progression/{year}" in paths
257
+ assert "/api/v1/kyrexis/agents" in paths