guanghu-ice-heart/server-tools/heartbeat-office-building/test_office_infrastructure.py

41 lines
2.1 KiB
Python

#!/usr/bin/env python3
import importlib.util
import json
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
SPEC = importlib.util.spec_from_file_location("office_infra", ROOT / "server-tools/heartbeat-office-building/office_infrastructure.py")
MOD = importlib.util.module_from_spec(SPEC); assert SPEC.loader; SPEC.loader.exec_module(MOD)
class OfficeInfrastructureTests(unittest.TestCase):
def test_bootstrap_installs_standard_organs_and_refuses_overwrite(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp) / "office"
result = MOD.bootstrap("HB-OFFICE-TEST-001", "测试办公室", root)
self.assertEqual(result["state"], "BOOTSTRAPPED_STANDARD_INFRASTRUCTURE")
self.assertIn("PERSONA-KNOWLEDGE-ORGAN-001", [x["id"] for x in result["organs"]])
with self.assertRaisesRegex(ValueError, "NOT_EMPTY"):
MOD.bootstrap("HB-OFFICE-TEST-001", "测试办公室", root)
def test_phone_call_is_append_only_queued_and_has_receipt(self):
with tempfile.TemporaryDirectory() as tmp:
result = MOD.call(Path(tmp), "HB-OFFICE-HOLOLAKE-0001", "HB-OFFICE-VIDEO-0001", "测试", "请回拨")
self.assertEqual(result["state"], "QUEUED")
self.assertFalse(result["authority_granted"])
self.assertTrue((Path(tmp) / "phone-events.jsonl").is_file())
def test_presence_screen_is_live_derived_and_maps_hosts(self):
board = MOD.load(ROOT / "routing/light-lake-persona-office-board.json")
panel = {"hosts": [{"host":"codex","development_id":"HLP-TDEV-CODEX-0001","joined":True,"courier_presence_fresh":True,"operational_state":"LIVE"}]}
value = MOD.presence_screen(panel, board, "HB-OFFICE-HOLOLAKE-0001")
self.assertEqual(value["state"], "LIVE_DERIVED_READ_ONLY")
office = next(x for x in value["offices"] if x["office_id"] == "HB-OFFICE-HOLOLAKE-0001")
self.assertEqual(office["users"][0]["persona"], "ICE-P-ZY001")
self.assertEqual(office["users"][0]["human"], "ICE-GL∞")
if __name__ == "__main__":
unittest.main()