"""Unit-Tests für die DSE Shadow-Verdrahtung (compute_obligation_shadow, pure).""" from compliance.services.specialist_agents.dse._obligation_shadow import ( compute_obligation_shadow, ) def _markers(n, ob, cond=None): return {f"C{i}": {"obl": [ob], "cond": cond} for i in range(n)} class TestComputeShadow: def test_collapse_and_delta(self): results = [{"control_id": f"C{i}", "passed": False} for i in range(5)] s = compute_obligation_shadow(results, "x", _markers(5, "recipients_disclosed")) assert s["legacy_control_findings"] == 5 assert s["obligation_findings"] == 1 # 5 → 1 assert s["collapse_factor"] == 5.0 assert s["met_failed_delta"] == 4 top = s["top_collapsed_obligations"][0] assert top["obligation"] == "recipients_disclosed" and top["fehlt"] == 5 def test_fp_correction_one_passed_collapses_to_met(self): results = [{"control_id": f"C{i}", "passed": i == 0} for i in range(5)] s = compute_obligation_shadow(results, "x", _markers(5, "recipients_disclosed")) assert s["legacy_control_findings"] == 4 assert s["obligation_findings"] == 0 # MET (anderswo erfüllt) assert s["met_failed_delta"] == 4 def test_na_when_predicate_false(self): results = [{"control_id": "C0", "passed": False}] m = {"C0": {"obl": ["third_country_transfer_disclosed"], "cond": "has_third_country_transfer"}} s = compute_obligation_shadow(results, "nur innerhalb der eu", m) assert s["na_count"] == 1 assert s["obligation_findings"] == 0 # NA statt FEHLT def test_na_predicate_true_keeps_finding(self): results = [{"control_id": "C0", "passed": False}] m = {"C0": {"obl": ["third_country_transfer_disclosed"], "cond": "has_third_country_transfer"}} s = compute_obligation_shadow(results, "übermittlung in ein drittland", m) assert s["na_count"] == 0 assert s["obligation_findings"] == 1 def test_no_markers_returns_status(self): s = compute_obligation_shadow([{"control_id": "C0", "passed": False}], "x", {}) assert "no obligation" in s["status"] def test_does_not_mutate_results(self): results = [{"control_id": "C0", "passed": False}] compute_obligation_shadow(results, "x", _markers(1, "recipients_disclosed")) assert set(results[0].keys()) == {"control_id", "passed"} # unverändert