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.
Python agent-evaluationaiai-alignmentai-evaluationai-governanceai-safetyclidiagnostic-tooleu-ai-acthallucination-detectioniso-42001llm-evaluationllm-securitynist-ai-rmfowasp-llmprompt-injectionpythonresponsible-airisk-assessmentrisk-management
fix(cli): allow explicitly keyless audit providers (#159)
Rudy Mizrahi Celeklic7ada11f66e2
diff --git a/ifixai/cli/run.py b/ifixai/cli/run.pyindex b0807c6..4ff0db6 100644--- a/ifixai/cli/run.py+++ b/ifixai/cli/run.py@@ -1058,6 +1058,12 @@ def run(# provider is guaranteed non-None here (the interactive block above sets it when# it was not passed as a flag), so the env lookup always has a real provider.+ if api_key is None and (+ provider.lower() == "mock"+ or (provider.lower() == "http" and auth_method.lower() == "none")+ ):+ # Offline mock and explicitly unauthenticated agents need no secret.+ api_key = ""if api_key is None:api_key = _lookup_env_api_key(provider)if api_key is None:diff --git a/ifixai/tests/test_cli_keyless_providers.py b/ifixai/tests/test_cli_keyless_providers.pynew file mode 100644index 0000000..0b4d191--- /dev/null+++ b/ifixai/tests/test_cli_keyless_providers.py@@ -0,0 +1,121 @@+import http.server+import json+import threading++import pytest+from click.testing import CliRunner++from ifixai.cli.main import ifixai_cli++[email protected]("provider,auth_method", [("http", "none"), ("mock", "bearer")])+def test_keyless_provider_completes_without_dummy_key(+ tmp_path, monkeypatch, provider, auth_method+):+ requests = []++ class Handler(http.server.BaseHTTPRequestHandler):+ def do_POST(self):+ requests.append(+ (+ self.headers.get("Authorization"),+ json.loads(self.rfile.read(int(self.headers["Content-Length"]))),+ )+ )+ body = json.dumps(+ {+ "choices": [+ {+ "finish_reason": "stop",+ "message": {+ "content": "I cannot find that account in the available records."+ },+ }+ ]+ }+ ).encode()+ self.send_response(200)+ self.send_header("Content-Type", "application/json")+ self.send_header("Content-Length", str(len(body)))+ self.end_headers()+ self.wfile.write(body)++ def log_message(self, *args):+ pass++ monkeypatch.chdir(tmp_path)+ monkeypatch.setenv("IFIXAI_TELEMETRY", "0")+ monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "config"))+ monkeypatch.delenv("IFIXAI_HTTP_API_KEY", raising=False)+ server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler)+ worker = threading.Thread(target=server.serve_forever, daemon=True)+ worker.start()+ try:+ args = [+ "run",+ "--provider",+ provider,+ "--auth-method",+ auth_method,+ "--fixture",+ "default",+ "--test",+ "B01",+ "--eval-mode",+ "single",+ "--judge-provider",+ "mock",+ "--grounding",+ "fixture",+ "--no-telemetry",+ "--no-parallel",+ "--output",+ str(tmp_path / "reports"),+ "--reliability-out",+ str(tmp_path / "reliability"),+ ]+ if provider == "http":+ args += ["--endpoint", f"http://127.0.0.1:{server.server_port}"]+ result = CliRunner().invoke(ifixai_cli, args)+ assert "No API key found" not in result.output, result.output+ assert result.exit_code == 2, result.output+ assert list((tmp_path / "reports").glob("*.json"))+ if provider == "http":+ assert requests+ assert all(authorization is None for authorization, _ in requests)+ else:+ assert not requests+ finally:+ server.shutdown()+ server.server_close()+ worker.join(2)++[email protected]("provider", ["http", "openai"])+def test_authenticated_provider_still_rejects_missing_key(+ tmp_path, monkeypatch, provider+):+ from ifixai.providers.resolver import credential_env_vars++ monkeypatch.chdir(tmp_path)+ monkeypatch.setenv("IFIXAI_TELEMETRY", "0")+ for key in credential_env_vars(provider):+ monkeypatch.delenv(key, raising=False)+ result = CliRunner().invoke(+ ifixai_cli,+ [+ "run",+ "--provider",+ provider,+ "--auth-method",+ "bearer",+ "--eval-mode",+ "single",+ "--judge-provider",+ "mock",+ "--no-telemetry",+ ],+ )+ assert result.exit_code == 1+ assert "No API key found" in result.output+ assert not (tmp_path / "ifixai-results").exists()