Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion diffgraph/structural.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,18 @@ def _parse_failure_warning(
)


def _unsupported_language_warning(entry: SnapshotEntry, path: str) -> Dict[str, str]:
"""Record the immutable snapshots outside the deterministic baseline."""
return _warning(
"UNSUPPORTED_LANGUAGE",
path,
"Deterministic extraction currently supports Python (.py) only; "
"pre-change blob {}; post-change blob {}.".format(
entry.old_oid or "absent", entry.new_oid or "absent",
),
)


def _symbol_id(path: str, qualified_name: str) -> str:
return "sym::{}::{}".format(path, qualified_name)

Expand Down Expand Up @@ -966,7 +978,7 @@ def analyze_local_diff(
continue
if file_entry["language"] != "python":
skipped += 1
warnings.append(_warning("UNSUPPORTED_LANGUAGE", path, "Deterministic extraction currently supports Python (.py) only."))
warnings.append(_unsupported_language_warning(entry, path))
continue
if (old is None and entry.old_oid is not None) or (
new is None and entry.new_oid is not None
Expand Down
32 changes: 31 additions & 1 deletion tests/test_structural.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,46 @@ def test_pathspec_scope_is_not_widened(tmp_path):


def test_unsupported_language_is_explicit_and_not_overclaimed(tmp_path):
"""Unsupported snapshots keep their explicit capability boundary and blobs."""
root = repo(tmp_path)
write(root, "main.js", "export function value() { return 1; }\n")
commit(root)
write(root, "main.js", "export function value() { return 2; }\n")
old_oid = git(root, "rev-parse", "HEAD:main.js")
new_oid = git(root, "hash-object", "main.js")
artifact = analyze_local_diff(str(root))
assert_valid(artifact)
assert artifact["symbols"] == []
assert artifact["metadata"]["files_skipped"] == 1
assert artifact["metadata"]["warnings"][0]["code"] == "UNSUPPORTED_LANGUAGE"
assert "Python" in artifact["metadata"]["warnings"][0]["detail"]
assert artifact["metadata"]["warnings"][0]["detail"] == (
"Deterministic extraction currently supports Python (.py) only; "
"pre-change blob {}; post-change blob {}."
).format(old_oid, new_oid)


@pytest.mark.parametrize("change_kind", ["added", "deleted"])
def test_unsupported_language_one_sided_blob_is_absent(tmp_path, change_kind):
"""Added and deleted unsupported snapshots identify their missing blob side."""
root = repo(tmp_path)
write(root, "main.js", "export function value() { return 1; }\n")
commit(root)

if change_kind == "added":
write(root, "added.js", "export function value() { return 2; }\n")
old_oid = "absent"
new_oid = git(root, "hash-object", "added.js")
else:
old_oid = git(root, "rev-parse", "HEAD:main.js")
(root / "main.js").unlink()
new_oid = "absent"

artifact = analyze_local_diff(str(root))
assert_valid(artifact)
assert artifact["metadata"]["warnings"][0]["detail"] == (
"Deterministic extraction currently supports Python (.py) only; "
"pre-change blob {}; post-change blob {}."
).format(old_oid, new_oid)


@pytest.mark.parametrize("staged", [False, True])
Expand Down
Loading