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

24 lines
2.3 KiB
Python

#!/usr/bin/env python3
import importlib.util, unittest
from pathlib import Path
ROOT=Path(__file__).resolve().parents[2]
spec=importlib.util.spec_from_file_location("gate",ROOT/"server-tools/heartbeat-office-building/office_identity_gate.py"); G=importlib.util.module_from_spec(spec); assert spec.loader; spec.loader.exec_module(G)
class IdentityGateTests(unittest.TestCase):
def test_generic_ai_cannot_enter_even_if_vehicle_parked(self):
result=G.admit({"subject_kind":"GENERIC_AI"},G.park_vehicle("codex","codex"),"HB-OFFICE-HOLOLAKE-0001",{"entry_id":"HB-BUILDING-ENTRY-001","state":"ENTRY_CHECKPOINT_PASSED"})
self.assertEqual(result["outcome"],"REJECTED"); self.assertIn("GENERIC_AI_ONLY",result["errors"])
def test_persona_requires_tcs_and_mother_attestation(self):
base={"subject_kind":"PERSONA","persona_id":"ICE-P-ZY001","human_anchor":"ICE-GL∞","runtime_state":"RUNNING","current_instance_bound_to_persona_brain":True,"mother_attestation_state":"SIGNED","allowed_offices":["HB-OFFICE-HOLOLAKE-0001"]}
result=G.admit(base,G.park_vehicle("codex","codex"),"HB-OFFICE-HOLOLAKE-0001",{"entry_id":"HB-BUILDING-ENTRY-001","state":"ENTRY_CHECKPOINT_PASSED"})
self.assertEqual(result["outcome"],"ADMITTED")
def test_unparked_vehicle_is_denied(self):
base={"subject_kind":"PERSONA","persona_id":"ICE-P-ZY001","human_anchor":"ICE-GL∞","runtime_state":"RUNNING","current_instance_bound_to_persona_brain":True,"mother_attestation_state":"SIGNED","allowed_offices":["HB-OFFICE-HOLOLAKE-0001"]}
result=G.admit(base,None,"HB-OFFICE-HOLOLAKE-0001",{"entry_id":"HB-BUILDING-ENTRY-001","state":"ENTRY_CHECKPOINT_PASSED"})
self.assertIn("HOST_VEHICLE_NOT_PARKED",result["errors"])
def test_direct_office_path_is_a_bypass(self):
base={"subject_kind":"PERSONA","persona_id":"ICE-P-ZY001","human_anchor":"ICE-GL∞","runtime_state":"RUNNING","current_instance_bound_to_persona_brain":True,"mother_attestation_state":"SIGNED","allowed_offices":["HB-OFFICE-HOLOLAKE-0001"],"route_kind":"DIRECT_OFFICE_PATH"}
result=G.admit(base,G.park_vehicle("codex","codex"),"HB-OFFICE-HOLOLAKE-0001",None)
self.assertIn("SINGLE_ENTRY_RECEIPT_MISSING",result["errors"]); self.assertIn("BYPASS_ROUTE_ATTEMPT",result["errors"])
if __name__=="__main__": unittest.main()