codex@macbookpro
·
2026-03-31
test_dynamics.py
1from __future__ import annotations
2
3import unittest
4
5from cie import CIERuntime
6
7
8class RuntimeDynamicsTests(unittest.TestCase):
9 def test_multistep_evolves_phi_mu_and_j(self) -> None:
10 runtime = CIERuntime(capacity_limit=8.0)
11 runtime.ingest("alpha beta alpha", context="gamma", anchors="anchor")
12 step_one = runtime.step()
13 step_three = runtime.step(2)
14 self.assertNotEqual(
15 step_one["phi_summary"]["total_potential"],
16 step_three["phi_summary"]["total_potential"],
17 )
18 self.assertNotEqual(
19 step_one["mu_summary"]["total_activation"],
20 step_three["mu_summary"]["total_activation"],
21 )
22 self.assertNotEqual(step_one["J_summary"]["total_flow"], step_three["J_summary"]["total_flow"])
23 self.assertTrue(step_three["sedimentation_trace"])
24 self.assertIn("direction", step_three["sedimentation_trace"][0])
25
26 def test_decay_events_occur_for_inactive_structures(self) -> None:
27 runtime = CIERuntime(capacity_limit=10.0)
28 for _ in range(4):
29 runtime.ingest("stale alpha beta", anchors="anchor")
30 runtime.step()
31 runtime.reset_session()
32 runtime.step(6)
33 snapshot = runtime.snapshot_state()
34 self.assertTrue(snapshot["decay_events"])
35 self.assertTrue(any(event["age"] > 0 for event in snapshot["decay_events"]))
36 self.assertTrue(any(event["kind"].startswith("J_") for event in snapshot["decay_events"]))
37 self.assertTrue(any(event["kind"] == "sedimentation_demote" for event in snapshot["decay_events"]))
38 self.assertEqual(runtime.state.sedimentation["alpha"].stage, "memory")
39
40 def test_output_mode_reaches_full_degraded_and_minimal(self) -> None:
41 full_runtime = CIERuntime(capacity_limit=10.0)
42 full_runtime.ingest("focus focus focus", anchors="anchor")
43 full_runtime.step(2)
44 self.assertEqual(full_runtime.snapshot_state()["output_mode"], "full")
45 self.assertTrue(full_runtime.emit().startswith("full:"))
46
47 degraded_runtime = CIERuntime(capacity_limit=6.0)
48 degraded_runtime.ingest("alpha beta gamma delta epsilon", anchors="anchor")
49 degraded_runtime.step(2)
50 self.assertEqual(degraded_runtime.snapshot_state()["output_mode"], "degraded")
51 self.assertTrue(degraded_runtime.emit().startswith("degraded:"))
52
53 minimal_runtime = CIERuntime(capacity_limit=0.9)
54 minimal_runtime.ingest("alpha beta gamma delta epsilon", anchors="anchor")
55 minimal_runtime.step(2)
56 self.assertEqual(minimal_runtime.snapshot_state()["output_mode"], "minimal")
57 self.assertTrue(minimal_runtime.emit().startswith("minimal:"))
58
59 def test_snapshot_fields_stay_meaningful_after_feedback(self) -> None:
60 runtime = CIERuntime(capacity_limit=8.0)
61 runtime.ingest("branch a graph native feedback", context="runtime state", anchors="anchor")
62 runtime.step(2)
63 runtime.emit()
64 snapshot = runtime.step()
65 self.assertTrue(snapshot["active_region"])
66 self.assertIsNotNone(snapshot["bound_ability_core"])
67 self.assertGreater(snapshot["anchor_pull"], 0.0)
68 self.assertGreaterEqual(snapshot["drift_score"], 0.0)
69 self.assertLessEqual(snapshot["drift_score"], 1.0)
70 self.assertTrue(snapshot["experience_regions"])
71 self.assertTrue(snapshot["skill_belt_candidates"])
72 self.assertTrue(snapshot["sedimentation_trace"])
73 self.assertTrue(snapshot["feedback_effect"]["applied_tokens"])
74 self.assertEqual(snapshot["feedback_effect"]["bound_ability_core"], snapshot["bound_ability_core"])
75 self.assertIn("flow", snapshot["skill_belt_candidates"][0])
76 self.assertIn("potential", snapshot["experience_regions"][0])
77 self.assertIn("nodes", snapshot["experience_regions"][0])
78
79
80if __name__ == "__main__":
81 unittest.main()