test_data_research_reconciliation.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from __future__ import annotations
  2. class ControlPlane:
  3. def published_versions(self):
  4. return [
  5. {"ontology_uid": "ontology-1", "version_uid": "version-2", "content_hash": "hash-2"}
  6. ]
  7. def artifacts(self):
  8. return [
  9. {"uid": "artifact-1", "storage_ref": "minio://bucket/present"},
  10. {"uid": "artifact-2", "storage_ref": "minio://bucket/missing"},
  11. ]
  12. def governance_documents(self):
  13. return [{"object_uid": "ontology-1", "object_version": 2, "content_hash": "old-hash"}]
  14. class Graph:
  15. def active_versions(self):
  16. return {"ontology-1": "version-1"}
  17. def repair_projection(self, issue):
  18. self.repaired = issue
  19. class Storage:
  20. def exists(self, ref):
  21. return not ref.endswith("missing")
  22. class Knowledge:
  23. def expected_hash(self, ontology_uid, version_uid):
  24. return "hash-2"
  25. def repair_document(self, issue):
  26. self.repaired = issue
  27. def test_read_only_reconciliation_builds_explicit_repair_plan():
  28. from app.core.data_research.operations import DataResearchReconciler
  29. graph = Graph()
  30. knowledge = Knowledge()
  31. reconciler = DataResearchReconciler(ControlPlane(), graph, Storage(), knowledge)
  32. report = reconciler.reconcile(repair=False)
  33. assert {issue["type"] for issue in report["issues"]} == {
  34. "projection_mismatch",
  35. "artifact_missing",
  36. "knowledge_mismatch",
  37. }
  38. assert report["repair_mode"] is False
  39. assert not hasattr(graph, "repaired") and not hasattr(knowledge, "repaired")
  40. def test_explicit_repair_mode_repairs_rebuildable_projections_only():
  41. from app.core.data_research.operations import DataResearchReconciler
  42. graph = Graph()
  43. knowledge = Knowledge()
  44. report = DataResearchReconciler(ControlPlane(), graph, Storage(), knowledge).reconcile(
  45. repair=True
  46. )
  47. assert report["repaired"] == 2
  48. assert graph.repaired["type"] == "projection_mismatch"
  49. assert knowledge.repaired["type"] == "knowledge_mismatch"
  50. assert all(issue["type"] != "artifact_missing" for issue in report["repair_plan"])