Implement live-shaped readiness workplan

This commit is contained in:
2026-05-19 01:06:41 +02:00
parent 3a52b3df41
commit 635d999621
21 changed files with 1507 additions and 54 deletions

View File

@@ -1,7 +1,7 @@
import json
from pathlib import Path
from phase_memory.adapters import FileBackedMemoryGraphStore, JsonlAuditSink, JsonlMemoryEventLog
from phase_memory.adapters import FileBackedMemoryGraphStore, JsonlAuditSink, JsonlMemoryEventLog, LOCAL_STORE_SCHEMA
from phase_memory.lifecycle import plan_compaction, plan_retention
from phase_memory.models import LifecycleAction, LifecycleActionKind, LifecycleState, MemoryEdge, MemoryEvent, MemoryNode
from phase_memory.paths import abandon_path, branch_path, create_path, merge_path, path_event
@@ -112,6 +112,55 @@ def test_file_backed_store_reports_migration_needs_and_uses_atomic_json_writes(t
assert not list(tmp_path.rglob("*.tmp"))
def test_local_store_migration_apply_updates_metadata_and_audits(tmp_path) -> None:
store = FileBackedMemoryGraphStore(tmp_path)
runtime = PhaseMemoryRuntime(graph_store=store, event_log=JsonlMemoryEventLog(tmp_path / "events.jsonl"))
(tmp_path / "phase-memory.json").write_text(
json.dumps(
{
"schema_version": "phase_memory.local_store.v0",
"planned_migrations": ["v0-to-v1"],
}
),
encoding="utf-8",
)
planned = runtime.plan_store_migration(source_ref=str(tmp_path))
applied = runtime.apply_store_migration(planned["data"]["migration_plan"], actor="pytest", source_ref=str(tmp_path))
metadata = store.metadata()
audit = runtime.query_audit({"operation": "store.migration.apply", "dry_run": False})
assert planned["valid"] is True
assert [action["action"] for action in planned["data"]["migration_plan"]["actions"]] == [
"set_schema_version",
"complete_planned_migration",
]
assert applied["valid"] is True
assert applied["data"]["migration_result"]["changed"] is True
assert metadata["schema_version"] == LOCAL_STORE_SCHEMA
assert metadata["completed_migrations"] == ["v0-to-v1"]
assert metadata["last_migration"]["actor"] == "pytest"
assert audit["count"] == 1
def test_local_store_migration_noop_and_corrupt_metadata_paths(tmp_path) -> None:
store = FileBackedMemoryGraphStore(tmp_path)
runtime = PhaseMemoryRuntime(graph_store=store, event_log=JsonlMemoryEventLog(tmp_path / "events.jsonl"))
noop = runtime.apply_store_migration(source_ref=str(tmp_path))
assert noop["valid"] is True
assert noop["data"]["migration_result"]["changed"] is False
(tmp_path / "phase-memory.json").write_text("{not-json}\n", encoding="utf-8")
planned = runtime.plan_store_migration(source_ref=str(tmp_path))
failed = runtime.apply_store_migration(source_ref=str(tmp_path))
assert planned["valid"] is False
assert planned["diagnostics"][0]["code"] == "corrupt_store_metadata"
assert failed["valid"] is False
assert failed["data"]["migration_result"]["applied"] is False
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"))