From e26af22e10b45030b91860c75b7cd53f02bff39b Mon Sep 17 00:00:00 2001 From: nia-sg-bot Date: Sat, 28 Nov 2026 15:04:02 +0530 Subject: [PATCH 1/2] test(structural): require parser provenance for findings --- tests/test_structural.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_structural.py b/tests/test_structural.py index 6da5555..8e5d03b 100644 --- a/tests/test_structural.py +++ b/tests/test_structural.py @@ -1,6 +1,7 @@ import hashlib import json import os +import re import subprocess from pathlib import Path @@ -96,12 +97,31 @@ def test_staged_add_modify_delete_rename_import_is_schema_valid_and_golden(tmp_p ("contains", "sym::add.py::added", "sym::add.py::added.child"), ("calls", "sym::add.py::added", "sym::add.py::added.child"), } + blob_ids_by_path = {} for file_entry in artifact["files"]: provenance = json.loads(file_entry["evidence"][0]["detail"]) assert provenance["old_oid"] is None or len(provenance["old_oid"]) == 40 assert provenance["new_oid"] is None or len(provenance["new_oid"]) == 40 assert provenance["old_sha256"] is None or len(provenance["old_sha256"]) == 64 assert provenance["new_sha256"] is None or len(provenance["new_sha256"]) == 64 + blob_ids_by_path[file_entry["path"]] = { + item for item in (provenance["old_oid"], provenance["new_oid"]) if item + } + + # Every Tree-sitter-derived symbol and relationship must identify the exact + # immutable blob and analyzer/query that produced it. This prevents a + # renderer or optional prose layer from turning structural findings into + # untraceable claims. + for finding in [*artifact["symbols"], *artifact["relationships"]]: + for evidence in finding["evidence"]: + detail = evidence["detail"] + match = re.fullmatch( + r"analyzer=diffgraph-python-tree-sitter;parser=tree-sitter-language-pack@[^;]+;" + r"query=python-structure-v2;blob=([0-9a-f]{40})", + detail, + ) + assert match, detail + assert match.group(1) in blob_ids_by_path[evidence["file"]] golden_path = Path(__file__).parent / "fixtures/python_topology.json" expected = json.loads(golden_path.read_text()) From bcc61cca73885aa6895fb97c6c09a713d54bb956 Mon Sep 17 00:00:00 2001 From: nia-sg-bot Date: Sun, 29 Nov 2026 21:01:46 +0530 Subject: [PATCH 2/2] test(structural): bind deleted findings to old blobs --- tests/test_structural.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/test_structural.py b/tests/test_structural.py index 8e5d03b..a119c23 100644 --- a/tests/test_structural.py +++ b/tests/test_structural.py @@ -97,21 +97,20 @@ def test_staged_add_modify_delete_rename_import_is_schema_valid_and_golden(tmp_p ("contains", "sym::add.py::added", "sym::add.py::added.child"), ("calls", "sym::add.py::added", "sym::add.py::added.child"), } - blob_ids_by_path = {} + blob_provenance_by_path = {} for file_entry in artifact["files"]: provenance = json.loads(file_entry["evidence"][0]["detail"]) assert provenance["old_oid"] is None or len(provenance["old_oid"]) == 40 assert provenance["new_oid"] is None or len(provenance["new_oid"]) == 40 assert provenance["old_sha256"] is None or len(provenance["old_sha256"]) == 64 assert provenance["new_sha256"] is None or len(provenance["new_sha256"]) == 64 - blob_ids_by_path[file_entry["path"]] = { - item for item in (provenance["old_oid"], provenance["new_oid"]) if item - } + blob_provenance_by_path[file_entry["path"]] = provenance # Every Tree-sitter-derived symbol and relationship must identify the exact - # immutable blob and analyzer/query that produced it. This prevents a - # renderer or optional prose layer from turning structural findings into - # untraceable claims. + # immutable blob and analyzer/query that produced it. Deleted symbols must + # retain their pre-change blob; all other symbols must retain post-change + # provenance. Relationships may span files, so they retain file-membership + # validation rather than being forced to one revision. for finding in [*artifact["symbols"], *artifact["relationships"]]: for evidence in finding["evidence"]: detail = evidence["detail"] @@ -121,7 +120,12 @@ def test_staged_add_modify_delete_rename_import_is_schema_valid_and_golden(tmp_p detail, ) assert match, detail - assert match.group(1) in blob_ids_by_path[evidence["file"]] + provenance = blob_provenance_by_path[evidence["file"]] + if finding in artifact["symbols"]: + expected_blob = provenance["old_oid"] if finding["change_kind"] == "deleted" else provenance["new_oid"] + assert match.group(1) == expected_blob + else: + assert match.group(1) in {provenance["old_oid"], provenance["new_oid"]} golden_path = Path(__file__).parent / "fixtures/python_topology.json" expected = json.loads(golden_path.read_text())