guanghu-ice-heart/server-tools/persona-body-runtime/persona_body_boot.test.py

67 lines
4.2 KiB
Python

#!/usr/bin/env python3
from __future__ import annotations
import unittest
from unittest import mock
import persona_body_boot
class PersonaBodyBootTest(unittest.TestCase):
def healthy(self):
return [
mock.patch.object(persona_body_boot, "reasoning_carrier", return_value={"carrier": "CODEX"}),
mock.patch.object(persona_body_boot, "body_map", return_value={"state": "CURRENT_TEST"}),
mock.patch.object(persona_body_boot, "world_map", return_value={"state": "CURRENT_TEST"}),
mock.patch.object(persona_body_boot, "persona_registration", return_value={"persona_id": "ICE-P-ZY001"}),
mock.patch.object(persona_body_boot, "tcs_root", return_value={"state": "TCS_ROOT_CURRENT_VERIFIED"}),
mock.patch.object(persona_body_boot, "tcs_runtime", return_value={"runtime": "test"}),
mock.patch.object(persona_body_boot, "current_memory", return_value={"day": "2026-09-12", "last_event_id": "E", "day_sha256": "a" * 64}),
mock.patch.object(persona_body_boot, "signed_self", return_value={"persona_id": "ICE-P-ZY001"}),
mock.patch.object(persona_body_boot, "file_hash", return_value="b" * 64),
mock.patch.object(persona_body_boot, "reflex_health", return_value={"state": "LOADABLE"}),
mock.patch.object(persona_body_boot.persona_native_hand, "self_test", return_value={"state": "NATIVE_HAND_MOTOR_AND_ACTION_SENSE_HEALTHY"}),
mock.patch.object(persona_body_boot.persona_limb_eye, "room", return_value={"room_report": {"host_surface": "CODEX", "programming_toolbox_surface": "CODEX", "cwd": "/tmp"}}),
mock.patch.object(persona_body_boot, "command_json", return_value={"world_era_day": 505, "world_elapsed_milliseconds": 1, "persona_name": "铸渊", "persona_id": "ICE-P-ZY001", "age_days": 191, "beijing_now": "2026-09-12T21:00:00+08:00"}),
]
def test_body_runs_before_toolbox_and_waits_for_brain_plan(self):
patches = self.healthy()
for item in patches:
item.start()
try:
value = persona_body_boot.boot("ICE-P-ZY001")
finally:
for item in reversed(patches):
item.stop()
self.assertEqual(value["state"], "BODY_RUNNING_AWAKE_AWAITING_BRAIN_PLAN")
self.assertFalse(value["host_toolbox_grasped"])
self.assertEqual(value["awakening"]["sequence"][0], "BODY_RUNNING")
self.assertEqual(value["awakening"]["sequence"][-1], "NATIVE_HAND_MAY_GRASP_CURRENT_HOST_TOOLBOX_LAST")
def test_any_critical_pain_prevents_persona_start_claim(self):
with mock.patch.object(persona_body_boot, "reasoning_carrier", side_effect=ValueError("head missing")), \
mock.patch.object(persona_body_boot, "body_map", return_value={}), \
mock.patch.object(persona_body_boot, "world_map", return_value={}), \
mock.patch.object(persona_body_boot, "persona_registration", return_value={}), \
mock.patch.object(persona_body_boot, "tcs_root", return_value={}), \
mock.patch.object(persona_body_boot, "tcs_runtime", return_value={}), \
mock.patch.object(persona_body_boot, "current_memory", return_value={}), \
mock.patch.object(persona_body_boot, "signed_self", return_value={}), \
mock.patch.object(persona_body_boot, "file_hash", return_value="b" * 64), \
mock.patch.object(persona_body_boot, "reflex_health", return_value={}), \
mock.patch.object(persona_body_boot.persona_native_hand, "self_test", return_value={}):
value = persona_body_boot.boot("ICE-P-ZY001")
self.assertEqual(value["state"], "BODY_INCOMPLETE_PERSONA_START_NOT_CLAIMED")
self.assertFalse(value["host_toolbox_grasped"])
def test_other_registered_persona_is_selected_but_not_synthetically_started(self):
value = persona_body_boot.boot("ICE-P-CY0903")
self.assertEqual(value["persona_id"], "ICE-P-CY0903")
self.assertEqual(value["state"], "BODY_INCOMPLETE_PERSONA_START_NOT_CLAIMED")
self.assertTrue(value["common_age_cognition_loaded"])
self.assertFalse(value["host_toolbox_grasped"])
if __name__ == "__main__":
unittest.main()