Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
test: strengthen KG provenance coverage and avoid duplicate deprecation warnings
Sameer6305fd7ac7465cc6
diff --git a/semantica/kg/provenance_tracker.py b/semantica/kg/provenance_tracker.pyindex 2cd0c79e..d58e18bc 100644--- a/semantica/kg/provenance_tracker.py+++ b/semantica/kg/provenance_tracker.py@@ -137,6 +137,14 @@ class ProvenanceTracker:DeprecationWarning,stacklevel=2,)+ return self._revision_history_no_warn(fact_id)++ def _revision_history_no_warn(self, fact_id: str) -> List[Dict[str, Any]]:+ """Internal, warning-free implementation of revision_history().++ Used by other deprecated methods (e.g. export_audit_log()) that need+ this logic without emitting a second DeprecationWarning per call.+ """records = self._records.get(fact_id, [])if not records:return []@@ -186,7 +194,7 @@ class ProvenanceTracker:)rows = []for fact_id in fact_ids:- for entry in self.revision_history(fact_id):+ for entry in self._revision_history_no_warn(fact_id):rows.append({"fact_id": fact_id, **entry})if format == "json":diff --git a/tests/provenance/test_all_modules.py b/tests/provenance/test_all_modules.pyindex 783003e8..2d517138 100644--- a/tests/provenance/test_all_modules.py+++ b/tests/provenance/test_all_modules.py@@ -60,11 +60,18 @@ class TestKGModule:assert tracker is not None# Test basic functionality- tracker.track_entity("test_entity", source="test_source")# NOTE: tracker.get_lineage() was never implemented on# kg.ProvenanceTracker; this tested an intended unified-backend# migration that never happened (#744). ProvenanceTracker is now# deprecated in favor of semantica.provenance.ProvenanceManager.+ # Instead, verify the observable behavior of the still-supported+ # track_entity()/get_all_sources() pair.+ tracker.track_entity("test_entity", source="test_source")+ sources = tracker.get_all_sources("test_entity")+ assert len(sources) > 0+ last_entry = sources[-1]+ assert last_entry["source"] == "test_source"+ assert "recorded_at" in last_entry# NOTE: test_kg_uses_unified_backend removed; it only asserted the# presence of _use_unified/_unified_manager attributes, which were@@ -402,7 +409,14 @@ class TestCrossModuleIntegration:"""Test provenance tracking across multiple modules."""def test_kg_and_split_integration(self):- """Test provenance tracking between kg and split modules."""+ """Test provenance tracking between kg and split modules.++ NOTE: this no longer asserts kg.ProvenanceTracker uses a unified+ backend (kg_tracker.get_lineage() was never implemented; see #744).+ It instead verifies, independent of unified-backend behavior, that+ kg tracking actually produced a record via the still-supported+ track_entity()/get_all_sources() pair.+ """from semantica.kg import ProvenanceTracker as KGTrackerfrom semantica.split import ProvenanceTracker as SplitTrackerfrom semantica.split.semantic_chunker import Chunk@@ -410,10 +424,13 @@ class TestCrossModuleIntegration:# Track with kgkg_tracker = KGTracker()kg_tracker.track_entity("entity_1", source="doc_1")- # NOTE: kg_tracker.get_lineage() was never implemented on- # kg.ProvenanceTracker; this tested an intended unified-backend- # migration that never happened (#744). ProvenanceTracker is now- # deprecated in favor of semantica.provenance.ProvenanceManager.++ # Verify kg tracking produced a record+ kg_sources = kg_tracker.get_all_sources("entity_1")+ assert len(kg_sources) > 0+ last_kg_entry = kg_sources[-1]+ assert last_kg_entry["source"] == "doc_1"+ assert "recorded_at" in last_kg_entry# Track with splitsplit_tracker = SplitTracker()diff --git a/tests/provenance/test_backward_compat.py b/tests/provenance/test_backward_compat.pyindex 3e97d094..16268aeb 100644--- a/tests/provenance/test_backward_compat.py+++ b/tests/provenance/test_backward_compat.py@@ -15,16 +15,26 @@ class TestKGProvenanceBackwardCompat:"""Test kg.ProvenanceTracker backward compatibility."""def test_existing_code_unchanged(self):- """Test that existing kg.ProvenanceTracker code works unchanged."""+ """Test that existing kg.ProvenanceTracker code works unchanged.++ NOTE: this no longer asserts on tracker.get_lineage(), which was+ never implemented on kg.ProvenanceTracker (see #744). It instead+ verifies the observable behavior of the still-supported+ track_entity()/get_all_sources() pair.+ """# Existing code patterntracker = KGProvenanceTracker()# Track entity (existing API)tracker.track_entity("entity_1", source="doc_1", metadata={"confidence": 0.9})- # NOTE: tracker.get_lineage() was never implemented on- # kg.ProvenanceTracker; this tested an intended unified-backend- # migration that never happened (#744). ProvenanceTracker is now- # deprecated in favor of semantica.provenance.ProvenanceManager.++ # Verify the entity was actually tracked+ sources = tracker.get_all_sources("entity_1")+ assert len(sources) > 0+ last_entry = sources[-1]+ assert last_entry["source"] == "doc_1"+ assert "recorded_at" in last_entry+ assert last_entry["confidence"] == 0.9# NOTE: test_track_relationship_unchanged removed; it only exercised# tracker.track_relationship(), which was never implemented ondiff --git a/tests/provenance/test_integration.py b/tests/provenance/test_integration.pyindex 173d077f..a228b554 100644--- a/tests/provenance/test_integration.py+++ b/tests/provenance/test_integration.py@@ -31,16 +31,25 @@ class TestEndToEndProvenance:assert entity_prov is not Noneassert chunk_prov is not None- def test_kg_to_unified_integration(self):- """Test kg.ProvenanceTracker uses unified backend."""+ def test_kg_tracker_records_provenance(self):+ """Test kg.ProvenanceTracker records provenance via its supported API.++ NOTE: this no longer asserts kg.ProvenanceTracker uses a unified+ backend (kg_tracker.get_lineage() was never implemented; see #744).+ It instead verifies the observable behavior of the still-supported+ track_entity()/get_all_sources() pair.+ """kg_tracker = KGTracker()# Track with kg trackerkg_tracker.track_entity("kg_entity_1", source="kg_doc_1")- # NOTE: kg_tracker.get_lineage() was never implemented on- # kg.ProvenanceTracker; this tested an intended unified-backend- # migration that never happened (#744). ProvenanceTracker is now- # deprecated in favor of semantica.provenance.ProvenanceManager.++ # Verify it was tracked+ sources = kg_tracker.get_all_sources("kg_entity_1")+ assert len(sources) > 0+ last_entry = sources[-1]+ assert last_entry["source"] == "kg_doc_1"+ assert "recorded_at" in last_entrydef test_split_to_unified_integration(self):"""Test split.ProvenanceTracker uses unified backend."""