test(p6): add local cross-plugin workspace harness
这个提交存在于:
父节点
f7d5a7c0db
当前提交
b031efd901
共有 1 个文件被更改,包括 70 次插入 和 0 次删除
70
tests/test_p6_joint_workspace.py
普通文件
70
tests/test_p6_joint_workspace.py
普通文件
|
|
@ -0,0 +1,70 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""P6-C local two-repository contract and no-effect harness."""
|
||||
from __future__ import annotations
|
||||
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from context_orchestration import contract_descriptor as companion_p3_descriptor
|
||||
from p5_ingress_firewall import evaluate_ingress_segment
|
||||
from p6_readonly_projection import build_p6_readonly_status
|
||||
from unified_person_contract import empty_unified_person_store
|
||||
from unified_person_registry import UnifiedPersonRegistry
|
||||
|
||||
|
||||
WORKSPACE_ROOT = Path(__file__).resolve().parents[2]
|
||||
MEMORY_ROOT = WORKSPACE_ROOT / "astrbot_plugin_memory_companion-main"
|
||||
if str(MEMORY_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(MEMORY_ROOT))
|
||||
|
||||
from core import context_orchestration as memory_p3 # noqa: E402
|
||||
from core.p6_readonly_projection import build_p6_readonly_status as build_memory_p6_status # noqa: E402
|
||||
from core.recall_firewall import MEMORY_RECALL_SINK, evaluate_recall_disposition # noqa: E402
|
||||
|
||||
|
||||
def identity(subject_id: str) -> dict[str, str]:
|
||||
return {
|
||||
"companion_instance_id": "companion-a",
|
||||
"bot_account_id": "bot-1",
|
||||
"adapter_instance_id": "telegram-main",
|
||||
"subject_namespace": "telegram.user",
|
||||
"platform_subject_id": subject_id,
|
||||
}
|
||||
|
||||
|
||||
@unittest.skipUnless(MEMORY_ROOT.is_dir(), "P6 joint workspace requires the memory companion sibling repository")
|
||||
class P6JointWorkspaceTests(unittest.TestCase):
|
||||
def test_status_contract_p3_and_p5_boundaries_align_without_sensitive_projection(self) -> None:
|
||||
status = {"profiles": 2, "identity_links": 2, "audit_events": 3, "operations": 4, "person_id": "not-exported"}
|
||||
companion = build_p6_readonly_status(status)
|
||||
memory = build_memory_p6_status(status)
|
||||
self.assertEqual(companion["schema_version"], memory["schema_version"])
|
||||
self.assertEqual(companion["contract_fingerprint"], memory["contract_fingerprint"])
|
||||
self.assertEqual(companion["counts"], memory["counts"])
|
||||
self.assertNotIn("person_id", companion)
|
||||
self.assertNotIn("person_id", memory)
|
||||
self.assertEqual(companion_p3_descriptor(), memory_p3.contract_descriptor())
|
||||
|
||||
ingress = evaluate_ingress_segment({"source_kind": "forwarded_text", "trust": "T3", "source_hash": "sha256:" + ("a" * 64), "sink": "tool_execution", "security_state": "sanitized"})
|
||||
recall = evaluate_recall_disposition({"source_kind": "legacy_memory", "source_trust": "T4", "firewall_status": "allowed", "record_id": "p6-joint-untrusted", "target_sink": MEMORY_RECALL_SINK})
|
||||
self.assertEqual("none", ingress["execution_authority"])
|
||||
self.assertEqual("none", recall["audit"]["execution_authority"])
|
||||
|
||||
def test_p4_preparation_ledger_does_not_project_a_live_effect(self) -> None:
|
||||
store = {"unified_person": empty_unified_person_store()}
|
||||
registry = UnifiedPersonRegistry(store)
|
||||
created = registry.upsert_observed_identity(identity("p6-person"), operation_id="p6-observe")
|
||||
person_id = created["person_id"]
|
||||
before = deepcopy(store["unified_person"]["profiles"][person_id])
|
||||
recorded = registry.record_p4_effect_event(person_id, {"event_id": "p6-effect-normal", "occurred_at": "2026-07-30T00:00:00Z", "kind": "normal"}, operation_id="p6-effect-op", actor_id="p6-joint")
|
||||
self.assertTrue(recorded["ok"])
|
||||
self.assertEqual(before, store["unified_person"]["profiles"][person_id])
|
||||
self.assertNotIn("p4_shadow", store["unified_person"])
|
||||
state = registry.read_p4_effect_state(person_id)
|
||||
self.assertEqual("effect_preparation", state["p4_effect_state"]["mode"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
正在加载…
添加表格
在新工单中引用