generated from coulomb/repo-seed
Implement local runtime persistence and policy gates
This commit is contained in:
70
tests/test_runtime_snapshots.py
Normal file
70
tests/test_runtime_snapshots.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from phase_memory.runtime import PhaseMemoryRuntime
|
||||
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
|
||||
|
||||
def _load(name: str):
|
||||
return json.loads((FIXTURES / name).read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def test_profile_plan_runtime_snapshot() -> None:
|
||||
runtime = PhaseMemoryRuntime()
|
||||
envelope = runtime.plan_profile(_load("memory-profile.json"), source_ref="tests/fixtures/memory-profile.json")
|
||||
|
||||
assert _profile_projection(envelope) == _load("runtime-profile-plan-snapshot.json")
|
||||
|
||||
|
||||
def test_activation_plan_runtime_snapshot() -> None:
|
||||
runtime = PhaseMemoryRuntime()
|
||||
envelope = runtime.plan_activation(
|
||||
_load("memory-graph.json"),
|
||||
source_ref="tests/fixtures/memory-graph.json",
|
||||
max_items=2,
|
||||
max_tokens=18,
|
||||
profile_id="phase-memory-fixture-profile",
|
||||
priority_node_ids=("decision.boundary",),
|
||||
)
|
||||
|
||||
assert _activation_projection(envelope) == _load("runtime-activation-plan-snapshot.json")
|
||||
|
||||
|
||||
def _profile_projection(envelope: dict) -> dict:
|
||||
plan = envelope["data"]["plan"]
|
||||
return {
|
||||
"schema_version": envelope["schema_version"],
|
||||
"operation": envelope["operation"],
|
||||
"operation_id": envelope["operation_id"],
|
||||
"valid": envelope["valid"],
|
||||
"subject": envelope["subject"],
|
||||
"diagnostic_codes": [diagnostic["code"] for diagnostic in envelope["diagnostics"]],
|
||||
"data": {
|
||||
"ready": plan["ready"],
|
||||
"capabilities": plan["capabilities"],
|
||||
"required_adapters": plan["required_adapters"],
|
||||
"policy_gates": plan["policy_gates"],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def _activation_projection(envelope: dict) -> dict:
|
||||
plan = envelope["data"]["activation_plan"]
|
||||
return {
|
||||
"schema_version": envelope["schema_version"],
|
||||
"operation": envelope["operation"],
|
||||
"operation_id": envelope["operation_id"],
|
||||
"valid": envelope["valid"],
|
||||
"subject": envelope["subject"],
|
||||
"diagnostic_codes": [diagnostic["code"] for diagnostic in envelope["diagnostics"]],
|
||||
"data": {
|
||||
"plan_id": plan["plan_id"],
|
||||
"selected_node_ids": plan["selected_node_ids"],
|
||||
"selected_event_ids": plan["selected_event_ids"],
|
||||
"omitted": [f"{item['id']}:{item['reason']}" for item in plan["omitted"]],
|
||||
"token_estimate": plan["token_estimate"],
|
||||
"package_request_id": envelope["data"]["package_request"]["id"],
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user