From 54c274e02cfc9396e83d99d1b87d324e1717e6fc Mon Sep 17 00:00:00 2001 From: Shubham Srivastava Date: Thu, 20 Aug 2026 13:40:22 +0100 Subject: [PATCH] test(ingest): track relationship provenance via ProvenanceManager (#1071) * test(ingest): track relationship provenance via ProvenanceManager kg.ProvenanceTracker has no track_relationship and never did, so patch.object raised AttributeError before the test body ran. Closes #1055 * test(ingest): disambiguate relationship keys and pin provenance storage Addresses review feedback on #1071. --------- --- tests/ingest/test_notebook_06.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/ingest/test_notebook_06.py b/tests/ingest/test_notebook_06.py index 61a46201..ec857e64 100644 --- a/tests/ingest/test_notebook_06.py +++ b/tests/ingest/test_notebook_06.py @@ -5,6 +5,7 @@ from unittest.mock import MagicMock, patch from semantica.ingest import FileIngestor, WebIngestor, DBIngestor, StreamIngestor, FeedIngestor from semantica.kg import GraphBuilder, EntityResolver, ProvenanceTracker +from semantica.provenance import InMemoryStorage, ProvenanceManager from semantica.conflicts import ConflictDetector pytestmark = pytest.mark.integration @@ -75,13 +76,30 @@ class TestNotebook06MultiSourceIntegration: for entity in all_entities: provenance_tracker.track_entity(entity.get("id"), entity.get("source"), entity) + # Endpoints stay on "source"/"target", which is what GraphBuilder's + # dict normalization expects; the originating document moves to + # "document". The literal previously set "source" twice, so the + # endpoint id was silently overwritten by the document name. relationships = [ - {"source": "e2", "target": "e1", "type": "CEO_of", "source": "file1"} + {"id": "r1", "source": "e2", "target": "e1", + "type": "CEO_of", "document": "file1"} ] - - with patch.object(provenance_tracker, 'track_relationship'): - for rel in relationships: - provenance_tracker.track_relationship(rel.get("source"), rel.get("target"), rel.get("source"), rel) + + # kg.ProvenanceTracker has no track_relationship and never did; that + # lives on ProvenanceManager, which is where ProvenanceTracker's own + # DeprecationWarning points callers. Called for real rather than + # patched, so this step actually exercises something. + # + # Storage is pinned to in-memory: with no argument, ProvenanceManager + # falls back to the mutable class-level _default_storage_path, so an + # earlier test setting it would make this write SQLite to disk and + # turn the result order-dependent. + provenance_manager = ProvenanceManager(storage=InMemoryStorage()) + for rel in relationships: + entry = provenance_manager.track_relationship( + rel["id"], rel["document"], metadata=rel + ) + assert entry is not None # --- Step 5: Build Unified KG --- builder = GraphBuilder()