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
23 changes: 23 additions & 0 deletions tests/fixtures/python_parser_failure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"files": [
{
"path": "broken.py",
"old_path": null,
"language": "python",
"change_kind": "modified"
}
],
"symbols": [],
"relationships": [],
"metadata": {
"files_analyzed": 0,
"files_skipped": 1,
"warnings": [
{
"code": "PARSE_FAILURE",
"file": "broken.py",
"detail": "post-change: ValueError: Tree-sitter reported a syntax error"
}
]
}
}
25 changes: 18 additions & 7 deletions tests/test_structural.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,30 @@ def test_file_fallback_reports_structural_line_statistics(tmp_path, monkeypatch)
assert "notes.txt +2 / -1" in result.stdout


def test_parse_failure_is_scoped_and_does_not_invent_symbol_changes(tmp_path):
def test_parse_failure_is_scoped_and_matches_the_golden_fixture(tmp_path):
"""A syntax error has a stable, scoped artifact instead of false topology."""
root = repo(tmp_path)
write(root, "broken.py", "def valid():\n return 1\n")
commit(root)
write(root, "broken.py", "def broken(:\n")

artifact = analyze_local_diff(str(root))
assert_valid(artifact)
assert artifact["symbols"] == []
assert artifact["relationships"] == []
warning = artifact["metadata"]["warnings"][0]
assert warning["code"] == "PARSE_FAILURE"
assert warning["file"] == "broken.py"
assert warning["detail"].startswith("post-change:")
golden_path = Path(__file__).parent / "fixtures/python_parser_failure.json"
expected = json.loads(golden_path.read_text())
actual = {
"files": [{
key: file_entry[key]
for key in ("path", "old_path", "language", "change_kind")
} for file_entry in artifact["files"]],
"symbols": artifact["symbols"],
"relationships": artifact["relationships"],
"metadata": {
key: artifact["metadata"][key]
for key in ("files_analyzed", "files_skipped", "warnings")
},
}
assert actual == expected


def test_no_network_calls(monkeypatch, tmp_path):
Expand Down
Loading