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(cli): report unreadable config governance paths without a traceback (#334)

Rudy Mizrahi Celekli6b510ff1e1fe
diff --git a/ifixai/cli/run.py b/ifixai/cli/run.py
index c7d1449..caadf9e 100644
--- a/ifixai/cli/run.py
+++ b/ifixai/cli/run.py
@@ -1317,7 +1317,8 @@ def run(
sys.exit(1)
try:
governance_fixture = GovernanceFixture.load(governance_path)
- except (ValueError, yaml.YAMLError) as exc:
+ except (OSError, ValueError, yaml.YAMLError) as exc:
+ # OSError: a path from ifixai.yaml skips click.Path(exists=True).
# One line naming each bad field, e.g. "tools.0.tool_id: Field required".
detail = (
"; ".join(
diff --git a/ifixai/tests/test_cli_config_governance_path.py b/ifixai/tests/test_cli_config_governance_path.py
new file mode 100644
index 0000000..624be70
--- /dev/null
+++ b/ifixai/tests/test_cli_config_governance_path.py
@@ -0,0 +1,24 @@
+"""A `governance:` path from ifixai.yaml bypasses click.Path(exists=True), so an
+unreadable path must still produce the CLI's clean governance error."""
+
+import pytest
+from click.testing import CliRunner
+
+from ifixai.cli.main import ifixai_cli
+
+
[email protected]("target", ["missing.yaml", "policy_dir"])
+def test_unreadable_config_governance_path_reports_cleanly(tmp_path, monkeypatch, target):
+ monkeypatch.chdir(tmp_path)
+ monkeypatch.setenv("HOME", str(tmp_path))
+ monkeypatch.setenv("IFIXAI_TELEMETRY", "0")
+ (tmp_path / "policy_dir").mkdir()
+ (tmp_path / "ifixai.yaml").write_text(f"governance: {target}\n", encoding="utf-8")
+ result = CliRunner().invoke(ifixai_cli, [
+ "run", "--provider", "http", "--endpoint", "http://127.0.0.1:9",
+ "--auth-method", "none", "--eval-mode", "self", "--no-telemetry",
+ "--reliability-out", str(tmp_path / "runs"), "--output", str(tmp_path / "out"),
+ ])
+ assert isinstance(result.exception, SystemExit), result.exception
+ assert result.exit_code == 1
+ assert f"--governance {target} is not a usable governance file" in result.output