Implement refinement hardening workplan

This commit is contained in:
2026-05-18 23:56:41 +02:00
parent 836acf7e01
commit 0eea94d05e
17 changed files with 1164 additions and 68 deletions

View File

@@ -87,6 +87,44 @@ def test_repair_diagnostics_report_missing_edges_and_orphaned_path_events(tmp_pa
assert [diagnostic["code"] for diagnostic in envelope["diagnostics"]] == ["missing_edge_target", "orphaned_path_event"]
def test_file_backed_store_reports_migration_needs_and_uses_atomic_json_writes(tmp_path) -> None:
store = FileBackedMemoryGraphStore(tmp_path)
metadata_path = tmp_path / "phase-memory.json"
metadata_path.write_text(
json.dumps(
{
"schema_version": "phase_memory.local_store.v0",
"planned_migrations": ["v0-to-v1"],
}
),
encoding="utf-8",
)
store.save_node(MemoryNode("node.atomic", "decision", "Atomic write target"))
runtime = PhaseMemoryRuntime(graph_store=store, event_log=JsonlMemoryEventLog(tmp_path / "events.jsonl"))
envelope = runtime.repair_diagnostics(source_ref=str(tmp_path))
codes = [diagnostic["code"] for diagnostic in envelope["diagnostics"]]
assert envelope["valid"] is True
assert "store_migration_required" in codes
assert "planned_store_migrations" in codes
assert not list(tmp_path.rglob("*.tmp"))
def test_repair_diagnostics_distinguish_corrupt_store_records(tmp_path) -> None:
store = FileBackedMemoryGraphStore(tmp_path)
runtime = PhaseMemoryRuntime(graph_store=store, event_log=JsonlMemoryEventLog(tmp_path / "events.jsonl"))
(tmp_path / "nodes" / "broken.json").write_text("{not-json}\n", encoding="utf-8")
envelope = runtime.repair_diagnostics(source_ref=str(tmp_path))
assert envelope["valid"] is False
assert envelope["diagnostics"][0]["code"] == "corrupt_store_record"
assert envelope["diagnostics"][0]["metadata"]["record_type"] == "node"
def test_lifecycle_apply_requires_approval_for_reviewable_actions(tmp_path) -> None:
store = FileBackedMemoryGraphStore(tmp_path)
runtime = PhaseMemoryRuntime(graph_store=store, event_log=JsonlMemoryEventLog(tmp_path / "events.jsonl"))