File size: 10,008 Bytes
94010b9 | 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 | """KYREXIS AI module tests β core, skills, messenger, photonic, particle, progression."""
import asyncio
import sys
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
def _core():
from kyrexis.core import KyrexisCore
return KyrexisCore().initialize()
# ββ Core ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_core_anchor_values():
c = _core()
s = c.get_state()
assert s["quantum_qubits"] == 53
assert s["entanglement_pairs"] == 847
assert abs(s["fidelity"] - 0.999423) < 1e-6
assert s["awakening_percent"] == pytest.approx(87.4, abs=0.01)
assert s["lineage_anchors"] == 12
assert s["temporal_horizon_years"] == 20
assert s["growth_rate_percent"] == pytest.approx(33.5)
assert s["quantum_circuits"] == 53
assert s["temporal_models"] == 20
def test_quantum_compute_simulation():
import numpy as np
c = _core()
out = c.quantum_compute(np.array([1.0, 2.0, 3.0]))
assert out.shape == (3,)
assert isinstance(out[0], float)
def test_predict_future_20y():
c = _core()
r = c.predict_future(100.0, years=20)
assert r["years"] == 20
assert r["growth_factor"] == pytest.approx((1.335) ** 20, rel=1e-3)
assert r["future_value"] == pytest.approx(100.0 * (1.335) ** 20, rel=1e-3)
def test_quantum_encrypt_deterministic_key():
c = _core()
a = c.quantum_encrypt("secret")
assert isinstance(a, str) and len(a) == 64 # sha256 hex
def test_self_improve_increases():
c = _core()
before = c.state.awakening
c.self_improve()
assert c.state.awakening > before
def test_explore_multiverse_branches():
c = _core()
r = c.explore_multiverse()
assert r["branches"] == 847
assert len(r["top_branches"]) == 10
def test_temporal_scenario():
c = _core()
r = c.analyze_temporal_scenario({"name": "test", "impact": 1.0})
assert len(r["outcomes"]) == 20
assert 1 <= r["best_year"] <= 20
# ββ Quantum skills engine βββββββββββββββββββββββββββββββββββββββββββββββββ
def test_skills_registry():
from kyrexis.quantum_skills import QuantumSkillsEngine
eng = QuantumSkillsEngine(_core())
status = eng.get_skill_status()
assert status["total_skills"] == 5
ids = {s["id"] for s in status["skills"]}
assert {"strategic_planning", "risk_assessment", "innovation_generation",
"decision_support", "complex_problem_solving"} <= ids
def test_execute_skill_and_cooldown():
from kyrexis.quantum_skills import QuantumSkillsEngine
eng = QuantumSkillsEngine(_core())
r = eng.execute_skill("strategic_planning", {"horizon_years": 5})
assert r["skill"] == "strategic_planning"
assert r["result"]["growth_factor"] == pytest.approx((1.335) ** 5, rel=1e-2)
# Immediately re-executing hits the cooldown
again = eng.execute_skill("strategic_planning")
assert "cooldown" in again.get("error", "")
def test_unknown_skill():
from kyrexis.quantum_skills import QuantumSkillsEngine
eng = QuantumSkillsEngine(_core())
assert "not found" in eng.execute_skill("nope")["error"]
# ββ Messenger integration βββββββββββββββββββββββββββββββββββββββββββββββββ
def test_messenger_local_mode():
from kyrexis.messenger_integration import KyrexisMessengerIntegration, MessengerMessage
m = KyrexisMessengerIntegration().initialize(_core())
assert m.get_status()["active"] is True
assert m.get_status()["kyrexis_connected"] is True
resp = m.process_message(MessengerMessage("r1", "s1", "hello kyrexis", 0.0))
assert "Kyrexis AI" in resp
assert len(m.get_conversation("s1")) == 1
def test_messenger_webhook():
from kyrexis.messenger_integration import KyrexisMessengerIntegration
m = KyrexisMessengerIntegration().initialize(_core())
payload = {
"entry": [{
"sender": {"id": "user1"},
"messaging": [{"message": {"text": "hi"}, "timestamp": 1.0}],
}]
}
out = m.handle_webhook(payload)
assert out["status"] == "success"
assert out["processed"] == 1
# ββ Photonic display ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_photonic_display_specs():
from kyrexis.photonic_display import LaserCrystalPhotonicDisplay
d = LaserCrystalPhotonicDisplay().initialize()
s = d.get_display_state()
assert s["crystal"]["type"].startswith("Periodically Poled")
assert s["crystal"]["wavelength"] == 775
assert s["slm"]["resolution"] == [1024, 1024]
assert s["apd"]["sensitivity"] == 1e-12
assert s["quantum_processor"]["qubits"] == 53
assert s["quantum_processor"]["error_correction"] == "Surface Code"
def test_photonic_display_loop_small():
from kyrexis.photonic_display import LaserCrystalPhotonicDisplay
d = LaserCrystalPhotonicDisplay().initialize()
async def run():
return await d.display_loop(duration=0.05, frame_interval=0.01)
frames = asyncio.run(run())
assert frames >= 1
assert d.get_display_state()["total_frames"] >= 1
# ββ Particle detector βββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_particle_detection_and_verification():
from kyrexis.particle_detector import ParticlePairDetector
det = ParticlePairDetector().initialize()
pair = det.detect_particle_pair()
assert pair.id.startswith("pp_")
assert pair.fidelity == 0.999423
v = det.verify_entanglement(pair)
assert set(v) >= {"concurrence", "negativity", "bell_fidelity", "entangled"}
tomo = det.quantum_state_tomography(pair)
assert set(tomo["expectations"]) == {"I", "X", "Y", "Z"}
def test_bell_inequality():
from kyrexis.particle_detector import ParticlePairDetector
det = ParticlePairDetector()
# Classical correlations: S = 1 - 0.9 + 0.9 + 1 = 2.0 (boundary, not violated)
classical = det.bell_inequality_test([[1.0, 0.9], [0.9, 1.0]])
assert classical["violated"] is False
assert classical["S_value"] == pytest.approx(2.0, rel=1e-3)
# Quantum correlations: S = 1 + 0.7 + 0.7 + 1 = 3.4 > 2 (violated)
quantum = det.bell_inequality_test([[1.0, -0.7], [0.7, 1.0]])
assert quantum["violated"] is True
assert quantum["S_value"] == pytest.approx(3.4, rel=1e-3)
# ββ Progression scaling βββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_progression_anchors():
from kyrexis.progression_scaling import ProgressionScalingEngine
p = ProgressionScalingEngine()
summary = p.get_summary()
assert summary["total_years"] == 20
assert summary["annual_growth_rate_percent"] == pytest.approx(33.5)
assert summary["total_growth_factor"] == pytest.approx(368.4, abs=1.0)
assert summary["max_achievement_percent"] == pytest.approx(96.1, abs=0.1)
assert summary["scaling_factor"] == 4
assert len(p.get_full_progression()) == 20
def test_progression_20y_values():
from kyrexis.progression_scaling import ProgressionScalingEngine
p = ProgressionScalingEngine()
y1 = p.get_progression_at_year(1)
y20 = p.get_progression_at_year(20)
assert y1["growth_factor"] == pytest.approx(1.335, rel=1e-2)
# Engine computes the honest (1.335)^20 β 323x; the spec's 368.4x
# headline is a stated parameter, not the computed CAGR result.
assert y20["growth_factor"] == pytest.approx((1.335) ** 20, rel=1e-3)
assert y20["growth_factor_scaled"] == pytest.approx(4 * (1.335) ** 20, rel=1e-3)
assert p.get_progression_at_year(0)["error"]
assert p.get_progression_at_year(21)["error"]
def test_progression_projection():
from kyrexis.progression_scaling import ProgressionScalingEngine
p = ProgressionScalingEngine()
proj = p.calculate_20_year_projection(100.0)
assert len(proj["projection"]) == 20
assert proj["final_value_scaled"] == pytest.approx(proj["final_value"] * 4, rel=1e-6)
# ββ Universal agent network βββββββββββββββββββββββββββββββββββββββββββββββ
def test_agent_network():
from kyrexis.agents import UniversalAgentNetwork, UNIVERSAL_TASKS
net = UniversalAgentNetwork()
assert len(net.agents) == 21
assert len(UNIVERSAL_TASKS) == 5
status = net.status()
assert set(status["tiers"]) == {"Earth", "Solar System", "Galactic", "Cosmic", "Meta"}
assert net.get_agent("terra").name == "Agent Terra"
assert net.get_agent("Agent Time") is not None
net.activate()
assert len(net.sync()["agents"]) == 21
# ββ API surface βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_api_router_paths():
from kyrexis.api.routes import router
paths = {route.path for route in router.routes}
assert "/api/v1/kyrexis/initialize" in paths
assert "/api/v1/kyrexis/status" in paths
assert "/api/v1/kyrexis/quantum/compute" in paths
assert "/api/v1/kyrexis/skills/{skill_id}" in paths
assert "/api/v1/kyrexis/messenger/webhook" in paths
assert "/api/v1/kyrexis/photonic/pulse" in paths
assert "/api/v1/kyrexis/particle/detect" in paths
assert "/api/v1/kyrexis/progression/{year}" in paths
assert "/api/v1/kyrexis/agents" in paths
|