codex@macbookpro
·
2026-03-31
test_smoke.py
1from __future__ import annotations
2
3import unittest
4
5from cie import CIERuntime
6
7
8class RuntimeSmokeTests(unittest.TestCase):
9 def test_runtime_initializes(self) -> None:
10 runtime = CIERuntime()
11 snapshot = runtime.snapshot_state()
12 self.assertEqual(snapshot["output_mode"], "minimal")
13 self.assertEqual(snapshot["active_region"], [])
14 self.assertEqual(snapshot["phi_summary"]["node_count"], 0)
15 self.assertEqual(snapshot["feedback_effect"], {})
16
17 def test_locked_interface_exists(self) -> None:
18 runtime = CIERuntime()
19 for name in (
20 "ingest",
21 "step",
22 "emit",
23 "commit_feedback",
24 "snapshot_state",
25 "reset_session",
26 ):
27 self.assertTrue(callable(getattr(runtime, name)))
28
29 def test_ingest_and_step_change_state(self) -> None:
30 runtime = CIERuntime()
31 before = runtime.snapshot_state()
32 runtime.ingest("graph native dynamics", context="task02 runtime", anchors="branch a")
33 after = runtime.step(2)
34 self.assertNotEqual(before["phi_summary"]["node_count"], after["phi_summary"]["node_count"])
35 self.assertGreater(after["mu_summary"]["total_activation"], 0.0)
36 self.assertTrue(after["active_region"])
37 self.assertIsNotNone(after["bound_ability_core"])
38 self.assertTrue(after["experience_regions"])
39 self.assertTrue(after["skill_belt_candidates"])
40 self.assertTrue(runtime.state.sedimentation)
41 self.assertIn(runtime.state.sedimentation["graph"].stage, {"experience", "skill_belt", "ability_core"})
42
43 def test_snapshot_state_returns_required_keys(self) -> None:
44 runtime = CIERuntime()
45 runtime.ingest("observe state")
46 snapshot = runtime.step()
47 expected = {
48 "phi_summary",
49 "mu_summary",
50 "J_summary",
51 "active_region",
52 "bound_ability_core",
53 "anchor_pull",
54 "drift_score",
55 "free_capacity",
56 "experience_regions",
57 "skill_belt_candidates",
58 "sedimentation_trace",
59 "merge_events",
60 "decay_events",
61 "output_mode",
62 "feedback_effect",
63 }
64 self.assertEqual(set(snapshot), expected)
65
66 def test_emit_feedback_changes_later_state(self) -> None:
67 runtime = CIERuntime(capacity_limit=10.0)
68 runtime.ingest("feedback loop", anchors="anchor")
69 runtime.step(2)
70 before = runtime.snapshot_state()
71 output = runtime.emit()
72 queued = runtime.snapshot_state()
73 runtime.step()
74 after = runtime.snapshot_state()
75 self.assertTrue(output.startswith("full:"))
76 self.assertEqual(queued["feedback_effect"]["source"], "emit")
77 self.assertTrue(queued["feedback_effect"]["queued_tokens"])
78 self.assertEqual(after["feedback_effect"]["last_applied_step"], runtime.state.step_index)
79 self.assertTrue(after["feedback_effect"]["applied_tokens"])
80 self.assertGreater(after["feedback_effect"]["phi_delta"], 0.0)
81 self.assertTrue(after["feedback_effect"]["stage_after"])
82 self.assertGreater(after["phi_summary"]["total_potential"], before["phi_summary"]["total_potential"])
83 self.assertGreater(after["J_summary"]["total_flow"], before["J_summary"]["total_flow"])
84
85 def test_reset_session_preserves_long_term_structure(self) -> None:
86 runtime = CIERuntime()
87 runtime.ingest("long term structure", anchors="anchor")
88 runtime.step(2)
89 phi_before = runtime.snapshot_state()["phi_summary"]["node_count"]
90 sediment_before = dict(runtime.state.sedimentation)
91 runtime.reset_session()
92 snapshot = runtime.snapshot_state()
93 self.assertEqual(snapshot["mu_summary"]["active_count"], 0)
94 self.assertEqual(snapshot["output_mode"], "minimal")
95 self.assertGreaterEqual(snapshot["phi_summary"]["node_count"], phi_before)
96 self.assertEqual(set(runtime.state.sedimentation), set(sediment_before))
97
98
99if __name__ == "__main__":
100 unittest.main()