feat(hololake): add office registration and multi-persona collaboration gates
This commit is contained in:
parent
5779a3f159
commit
bb5a7a2f61
10 changed files with 167 additions and 1 deletions
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Server-gated collaboration board for different humans and their own personas."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
CONTRACT = ROOT / "eternal-lake-heart/heartbeat-core/office-building-current/collaboration/MULTI-PERSONA-COLLABORATION-CONTRACT.json"
|
||||
|
||||
|
||||
def load(path): return json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def create_board(office_id: str, participants: list[dict], server_endpoint: str | None = None) -> dict:
|
||||
humans = [item.get("human_id") for item in participants]
|
||||
personas = [item.get("persona_id") for item in participants]
|
||||
errors = []
|
||||
if len(participants) < 2: errors.append("MULTI_PARTICIPANT_REQUIRED")
|
||||
if len(set(humans)) != len(humans): errors.append("HUMAN_ID_DUPLICATE")
|
||||
if len(set(personas)) != len(personas): errors.append("SAME_PERSONA_MULTI_HOST_FORBIDDEN")
|
||||
if len(set(zip(humans, personas))) != len(participants): errors.append("PARTICIPANT_PAIR_DUPLICATE")
|
||||
if not server_endpoint: errors.append("SERVER_REQUIRED_NOT_CONNECTED")
|
||||
return {"outcome":"REJECTED" if errors else "BOARD_REQUESTED", "board_id":f"COLLAB-{uuid.uuid4()}", "office_id":office_id, "participants":participants, "server_endpoint":server_endpoint, "errors":errors, "state":"SERVER_REQUIRED_NOT_CONNECTED" if errors and "SERVER_REQUIRED_NOT_CONNECTED" in errors else "REQUESTED", "created_at":datetime.now(timezone.utc).isoformat(), "authority_granted":False}
|
||||
|
||||
|
||||
def connect(board: dict, server_receipt: dict | None = None) -> dict:
|
||||
if not board.get("server_endpoint") or not server_receipt:
|
||||
return {"outcome":"BLOCKED", "state":"SERVER_REQUIRED_NOT_CONNECTED", "board_id":board.get("board_id"), "authority_granted":False}
|
||||
return {"outcome":"CONNECTED", "state":"CONNECTED", "board_id":board.get("board_id"), "server_receipt":server_receipt, "authority_granted":False}
|
||||
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser(); parser.add_argument("application", type=Path); args=parser.parse_args(); print(json.dumps(create_board(**load(args.application)),ensure_ascii=False,indent=2))
|
||||
|
||||
|
||||
if __name__ == "__main__": main()
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/env python3
|
||||
"""HR registration desk for persona offices; validates before standard bootstrap."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from office_infrastructure import bootstrap
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SUBJECTS = ROOT / "identity/fifth-domain-subject-registry.json"
|
||||
NUMBER_REGISTRY = ROOT / "routing/fifth-domain-number-registry.json"
|
||||
BOARD = ROOT / "routing/light-lake-persona-office-board.json"
|
||||
REGISTRY = ROOT / "eternal-lake-heart/heartbeat-core/office-building-current/hr/OFFICE-REGISTRATION-REGISTRY.json"
|
||||
|
||||
|
||||
def load(path: Path) -> dict[str, Any]:
|
||||
return json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def validate_application(application: dict[str, Any], subjects: dict[str, Any], number_registry: dict[str, Any], board: dict[str, Any], registrations: dict[str, Any]) -> dict[str, Any]:
|
||||
human_id = application.get("human_id")
|
||||
persona_id = application.get("persona_id")
|
||||
office_id = application.get("office_id")
|
||||
errors: list[str] = []
|
||||
subject_map = {item.get("id"): item for item in subjects.get("subjects", [])}
|
||||
human = subject_map.get(human_id)
|
||||
persona = subject_map.get(persona_id)
|
||||
if not human or human.get("subject_kind") != "human": errors.append("HUMAN_IDENTITY_UNKNOWN")
|
||||
if not persona or persona.get("subject_kind") not in {"persona_system", "system_persona"}: errors.append("PERSONA_IDENTITY_UNKNOWN")
|
||||
if human and human_id != "ICE-GL∞" and "office_application_authorizer" not in human.get("roles", []): errors.append("HUMAN_OFFICE_APPLICATION_NOT_AUTHORIZED")
|
||||
if human and persona and persona.get("human_anchor") != human_id: errors.append("HUMAN_PERSONA_ANCHOR_MISMATCH")
|
||||
existing = {item.get("office_id") for item in board.get("offices", [])}
|
||||
existing |= {item.get("office_id") for item in registrations.get("registrations", [])}
|
||||
existing |= {item.get("id") for item in number_registry.get("registrations", []) if str(item.get("id", "")).startswith("HB-OFFICE-")}
|
||||
if office_id in existing: errors.append("OFFICE_ID_COLLISION")
|
||||
if not isinstance(office_id, str) or not office_id.startswith("HB-OFFICE-"): errors.append("OFFICE_ID_NOT_REGISTERED_NAMESPACE")
|
||||
return {"outcome":"PASS" if not errors else "FAIL", "errors":errors, "human":human, "persona":persona, "existing_office_count":len(existing), "office_id":office_id}
|
||||
|
||||
|
||||
def register(application: dict[str, Any], office_root: Path) -> dict[str, Any]:
|
||||
subjects, numbers, board, ledger = load(SUBJECTS), load(NUMBER_REGISTRY), load(BOARD), load(REGISTRY)
|
||||
check = validate_application(application, subjects, numbers, board, ledger)
|
||||
if check["outcome"] != "PASS": return {"outcome":"REJECTED", "check":check, "authority_granted":False}
|
||||
installed = bootstrap(application["office_id"], application["office_name"], office_root, application["persona_id"], application["human_id"])
|
||||
ledger["registrations"].append({"office_id":application["office_id"], "office_name":application["office_name"], "human_id":application["human_id"], "persona_id":application["persona_id"], "state":"REGISTERED_STANDARD_INFRASTRUCTURE_BOOTSTRAPPED", "infrastructure":installed["organs"]})
|
||||
REGISTRY.write_text(json.dumps(ledger, ensure_ascii=False, indent=2) + "\n")
|
||||
return {"outcome":"REGISTERED", "check":check, "registration":ledger["registrations"][-1], "authority_granted":False}
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(); parser.add_argument("application", type=Path); parser.add_argument("office_root", type=Path)
|
||||
args = parser.parse_args(); print(json.dumps(register(load(args.application), args.office_root), ensure_ascii=False, indent=2)); return 0
|
||||
|
||||
|
||||
if __name__ == "__main__": raise SystemExit(main())
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python3
|
||||
import importlib.util
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT=Path(__file__).resolve().parents[2]
|
||||
def mod(name,file):
|
||||
spec=importlib.util.spec_from_file_location(name,ROOT/"server-tools/heartbeat-office-building"/file); value=importlib.util.module_from_spec(spec); assert spec.loader; spec.loader.exec_module(value); return value
|
||||
HR=mod("hr","office_registration.py"); COLLAB=mod("collab","office_collaboration.py")
|
||||
|
||||
class RegistrationCollabTests(unittest.TestCase):
|
||||
def test_unknown_human_and_persona_are_rejected(self):
|
||||
result=HR.validate_application({"human_id":"ICE-GL-UNKNOWN","persona_id":"ICE-P-UNKNOWN","office_id":"HB-OFFICE-TEST-001"},{"subjects":[]},{"registrations":[]},{"offices":[]},{"registrations":[]})
|
||||
self.assertEqual(result["outcome"],"FAIL"); self.assertIn("HUMAN_IDENTITY_UNKNOWN",result["errors"])
|
||||
|
||||
def test_same_persona_multi_host_is_forbidden(self):
|
||||
result=COLLAB.create_board("HB-OFFICE-HOLOLAKE-0001",[{"human_id":"ICE-GL∞","persona_id":"ICE-P-ZY001"},{"human_id":"ICE-GL-ZHI∞","persona_id":"ICE-P-ZY001"}],"https://example.invalid/collab")
|
||||
self.assertEqual(result["outcome"],"REJECTED"); self.assertIn("SAME_PERSONA_MULTI_HOST_FORBIDDEN",result["errors"])
|
||||
|
||||
def test_different_humans_require_server_and_can_request_board(self):
|
||||
result=COLLAB.create_board("HB-OFFICE-HOLOLAKE-0001",[{"human_id":"ICE-GL∞","persona_id":"ICE-P-ZY001"},{"human_id":"ICE-GL-ZHI∞","persona_id":"ICE-P-CY0903"}],None)
|
||||
self.assertEqual(result["state"],"SERVER_REQUIRED_NOT_CONNECTED")
|
||||
result=COLLAB.create_board("HB-OFFICE-HOLOLAKE-0001",[{"human_id":"ICE-GL∞","persona_id":"ICE-P-ZY001"},{"human_id":"ICE-GL-ZHI∞","persona_id":"ICE-P-CY0903"}],"https://example.invalid/collab")
|
||||
self.assertEqual(result["outcome"],"BOARD_REQUESTED")
|
||||
|
||||
if __name__ == "__main__": unittest.main()
|
||||
Loading…
Reference in a new issue