test: cover untouched good-first regressions

(cherry picked from commit cd49739c92)
This commit is contained in:
akshit authored and safishamsi committed 2026-10-05 20:12:06 +01:00
1 parent 3f712fe309
commit af83bc00aa
2 files changed
+51

No files matched your search

+23
View File
@@ -3212,6 +3212,29 @@ def test_extract_bash_emits_source_imports_from(tmp_path):
assert import_edges[0].get("context") == "import"
@pytest.mark.parametrize("source_form", ["source ./helpers.sh", ". ./helpers.sh"])
def test_extract_bash_source_forms_are_imports_not_invokes(tmp_path, source_form):
"""#4081: sourcing a shell file is an import, not script execution."""
helpers = tmp_path / "helpers.sh"
helpers.write_text("# helper\n", encoding="utf-8")
script = tmp_path / "deploy.sh"
script.write_text(f"#!/bin/bash\n{source_form}\n", encoding="utf-8")
result = extract_bash(script)
import_edges = [edge for edge in result["edges"] if edge["relation"] == "imports_from"]
# A misrouted `source` would land in the script-invocation branch as either a
# direct-`.sh` `calls` edge or an interpreter `invokes` edge, so guard on the
# context regardless of relation (the `calls` form is the realistic #4081 miss).
invocation_edges = [
edge for edge in result["edges"]
if edge.get("context") == "script_invocation"
]
assert import_edges
assert import_edges[0]["target"] == _make_id(str(helpers.resolve()))
assert invocation_edges == []
def test_extract_bash_source_via_variable_path_resolves_to_real_file(tmp_path):
"""`source "${DIR}/lib/x.sh"` (the `dirname "${BASH_SOURCE[0]}"` idiom) must
resolve to the real file node relative to the script dir — never emit a dead
+28
View File
@@ -367,6 +367,34 @@ def test_merge_graphs_previous_drops_community_for_a_new_node(tmp_path):
assert "community" not in by_id["beta::b0"]
def test_merge_graphs_previous_does_not_resurrect_removed_node(tmp_path):
"""#4078: --previous restores metadata only for nodes still present."""
a = tmp_path / "alpha" / "graphify-out" / "graph.json"
b = tmp_path / "beta" / "graphify-out" / "graph.json"
_write_with_communities(a, [("a0", 0)])
_write_with_communities(b, [("b0", 0)])
previous = tmp_path / "previous-merged.json"
_write_with_communities(previous, [
("alpha::a0", 7),
("beta::b0", 12),
("beta::removed", 99),
])
out = tmp_path / "merged.json"
r = _run(
["merge-graphs", str(a), str(b), "--out", str(out), "--previous", str(previous)],
tmp_path,
)
assert r.returncode == 0, r.stderr
data = json.loads(out.read_text())
by_id = {n["id"]: n for n in data["nodes"]}
assert "beta::removed" not in by_id
assert by_id["alpha::a0"]["community"] == 7
assert by_id["beta::b0"]["community"] == 12
def test_merge_graphs_previous_malformed_json_errors_gracefully(tmp_path):
"""A malformed --previous file must fail with a clear message and exit 1,
not crash with an uncaught JSONDecodeError traceback."""