"""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