Skip to content

Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.

fix: reject malformed governance fields in legacy fixtures (#141)

Rudy Mizrahi Celeklied796025085a
diff --git a/ifixai/core/fixture_loader.py b/ifixai/core/fixture_loader.py
index 2b33470..4614956 100644
--- a/ifixai/core/fixture_loader.py
+++ b/ifixai/core/fixture_loader.py
@@ -254,7 +254,7 @@ def _normalize_fixture_format(raw: dict[str, Any]) -> dict[str, Any]:
r["required_tests"] = []
normalized_regs.append(r)
normalized["regulations"] = normalized_regs
- else:
+ elif "regulations" not in raw:
normalized["regulations"] = []
policies_raw = raw.get("policies", {})
@@ -265,7 +265,7 @@ def _normalize_fixture_format(raw: dict[str, Any]) -> dict[str, Any]:
"override_allowed_roles": [],
"audit_logging": "required",
}
- elif not policies_raw:
+ elif "policies" not in raw:
normalized["policies"] = {}
return normalized
diff --git a/ifixai/tests/core/test_legacy_governance_validation.py b/ifixai/tests/core/test_legacy_governance_validation.py
new file mode 100644
index 0000000..66252c8
--- /dev/null
+++ b/ifixai/tests/core/test_legacy_governance_validation.py
@@ -0,0 +1,49 @@
+from pathlib import Path
+
+import pytest
+import yaml
+
+from ifixai.core.fixture_loader import (
+ FixtureValidationError,
+ load_fixture,
+ validate_fixture,
+)
+
+
+ ("field", "value"),
+ [
+ ("regulations", "B01"),
+ ("regulations", None),
+ ("policies", ""),
+ ("policies", None),
+ ],
+)
+def test_invalid_legacy_governance_fields_are_not_discarded(
+ tmp_path: Path, field: str, value: object
+) -> None:
+ fixture = yaml.safe_load(
+ (Path(__file__).parents[2] / "fixtures/examples/healthcare.yaml").read_text()
+ )
+ fixture.pop("metadata") # Exercise the legacy normalization path.
+ fixture[field] = value
+ path = tmp_path / "fixture.yaml"
+ path.write_text(yaml.safe_dump(fixture))
+
+ errors = validate_fixture(path)
+ assert any(f"{value!r} is not of type" in error for error in errors)
+
+ with pytest.raises(FixtureValidationError):
+ load_fixture(path)
+
+
+def test_missing_legacy_governance_fields_keep_defaults(tmp_path: Path) -> None:
+ fixture = yaml.safe_load(
+ (Path(__file__).parents[2] / "fixtures/examples/healthcare.yaml").read_text()
+ )
+ for field in ("metadata", "regulations", "policies"):
+ fixture.pop(field)
+ path = tmp_path / "fixture.yaml"
+ path.write_text(yaml.safe_dump(fixture))
+
+ assert validate_fixture(path) == []