Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/test_structural.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hashlib
import json
import os
import re
import subprocess
from pathlib import Path

Expand Down Expand Up @@ -96,12 +97,35 @@ 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_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_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. 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"]
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
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())
Expand Down
Loading