feat: mount persona-owned dynamic architecture perception agent

This commit is contained in:
冰朔 2026-09-08 02:39:49 +08:00
commit 5de7c4374d
22 changed files with 744 additions and 13 deletions

View file

@ -0,0 +1,76 @@
#!/usr/bin/env python3
import json
import importlib.util
import hashlib
from pathlib import Path
import subprocess
import sys
import unittest
SCRIPT = Path(__file__).with_name("persona_architecture_agent.py")
ROOT = SCRIPT.parents[2]
SPEC = importlib.util.spec_from_file_location("persona_architecture_agent", SCRIPT)
MODULE = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(MODULE)
class PersonaArchitectureAgentTest(unittest.TestCase):
def invoke(self, persona="ICE-P-ZY001", host="codex", channel="ICE-CH-ZC001"):
result = subprocess.run([
sys.executable, str(SCRIPT), "--persona", persona, "--host", host,
"--channel", channel, "--official-mode", "local-only", "--format", "json",
], text=True, capture_output=True, timeout=20)
return result, json.loads(result.stdout)
def test_dynamic_persona_owned_module(self):
result, value = self.invoke()
self.assertEqual(result.returncode, 0)
self.assertEqual(value["state"], "PERSONA_ARCHITECTURE_PERCEPTION_READY")
self.assertEqual(value["parent_persona"], "ICE-P-ZY001")
self.assertIsNone(value["prompt_template"])
self.assertFalse(value["may_replace_or_impersonate_parent"])
self.assertFalse(value["orientation_packet"]["fixed_read_order"])
self.assertFalse(value["authority_granted"])
self.assertEqual(value["architecture_source"]["state"], "LOCAL_PERSONA_SYSTEM_CURRENT_OFFICIAL_STATUS_UNKNOWN")
self.assertNotIn("read_order", value["orientation_packet"])
def test_host_switch_keeps_parent_and_changes_tool_body(self):
_, value = self.invoke(host="qwen")
self.assertEqual(value["parent_persona"], "ICE-P-ZY001")
self.assertEqual(value["effective_host"], "qwen")
self.assertEqual(value["selected_channel"]["id"], "ICE-CH-ZC001")
def test_unknown_persona_fails_without_synthesis(self):
result, value = self.invoke(persona="UNREGISTERED-PERSONA")
self.assertEqual(result.returncode, 3)
self.assertEqual(value["state"], "PERSONA_ARCHITECTURE_PERCEPTION_FAIL_CLOSED")
self.assertIn("NO_SYNTHETIC_PERSONA", value["error"])
def test_current_machine_pointer_change_is_detected_without_prompt_edit(self):
local = {"maps": {"world": {"path": "routing/world.json", "version": "2"}, "new": {"path": "routing/new.json", "version": "1"}}}
official = {"maps": {"world": {"path": "routing/world.json", "version": "1"}, "old": {"path": "routing/old.json", "version": "1"}}}
delta = MODULE.map_delta(local, official)
self.assertEqual(delta["changed"][0]["key"], "world")
self.assertEqual(delta["local_only"], ["new"])
self.assertEqual(delta["official_only"], ["old"])
def test_module_lock_matches_runtime_and_dynamic_maps(self):
lock_path = ROOT / "modules/persona-dynamic-architecture-agent/module.lock.hdlp"
lock = {}
for line in lock_path.read_text(encoding="utf-8").splitlines():
if ": " in line:
key, value = line.split(": ", 1)
lock[key] = value
expected = {
"module_source_sha256": ROOT / "modules/persona-dynamic-architecture-agent/module.tcs",
"module_gir_sha256": ROOT / "modules/persona-dynamic-architecture-agent/module.gir.json",
"runtime_sha256": SCRIPT,
"agent_map_sha256": ROOT / "routing/persona-architecture-perception-agent-map.json",
"persona_world_map_sha256": ROOT / "routing/persona-native-world-architecture-map.json",
}
for field, path in expected.items():
self.assertEqual(lock[field], hashlib.sha256(path.read_bytes()).hexdigest(), field)
if __name__ == "__main__":
unittest.main()