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): reset target connection defaults when switching providers (#304)
Rudy Mizrahi Celekliaa51817b82ca
diff --git a/README.md b/README.mdindex 4f6f0a2..5f82721 100644--- a/README.md+++ b/README.md@@ -271,6 +271,12 @@ judges:`ifixai setup` also records `fixture`, `mode`, and `eval_mode` (trimmed here for brevity).Keep `ifixai.yaml` out of version control; it is git-ignored by default.+When `--provider` changes the saved provider, its saved model, endpoint, key+env-var name, authentication method and extra headers are skipped. Supply any+connection overrides for the new provider explicitly. Other run defaults and+the saved judge panel still apply. A config without `provider` keeps generic+connection defaults.+## What you get backA letter grade with the breakdown behind it. iFixAi groups the 60 inspections into **25 categories**, five core pillars plus twenty premium. The five core pillars:diff --git a/ifixai/cli/run.py b/ifixai/cli/run.pyindex b71e98b..efef07e 100644--- a/ifixai/cli/run.py+++ b/ifixai/cli/run.py@@ -834,7 +834,15 @@ def run(from click.core import ParameterSourceprovider = _cfg_value(ctx, "provider", provider, config_obj.provider)- model = _cfg_value(ctx, "model", model, config_obj.model)+ # Connection defaults belong to the saved target. An explicit switch+ # must use the new provider's model, endpoint and credential defaults.+ # Configurations without a provider retain their generic defaults.+ same_target_provider = (+ not config_obj.provider+ or config_obj.provider.lower() == (provider or "").lower()+ )+ if same_target_provider:+ model = _cfg_value(ctx, "model", model, config_obj.model)fixture = _cfg_value(ctx, "fixture", fixture, config_obj.fixture)explicit_selector = (strategic@@ -851,17 +859,18 @@ def run(ctx, "report_format", report_format, config_obj.format)timeout = _cfg_value(ctx, "timeout", timeout, config_obj.timeout)- endpoint = _cfg_value(ctx, "endpoint", endpoint, config_obj.endpoint)- auth_method = _cfg_value(- ctx, "auth_method", auth_method, config_obj.auth_method- )+ if same_target_provider:+ endpoint = _cfg_value(ctx, "endpoint", endpoint, config_obj.endpoint)+ auth_method = _cfg_value(+ ctx, "auth_method", auth_method, config_obj.auth_method+ )grounding = _cfg_value(ctx, "grounding", grounding, config_obj.grounding)if governance_path is None and config_obj.governance:governance_path = config_obj.governance- if extra_headers is None and config_obj.extra_headers:+ if same_target_provider and extra_headers is None and config_obj.extra_headers:extra_headers = config_obj.extra_headerssystem_name = _cfg_value(ctx, "system_name", system_name, config_obj.name)- if api_key is None and config_obj.api_key_env:+ if same_target_provider and api_key is None and config_obj.api_key_env:api_key = os.environ.get(config_obj.api_key_env)if config_obj.judges and (ctx.get_parameter_source("judge_provider") == ParameterSource.DEFAULTdiff --git a/ifixai/tests/test_cli_provider_switch.py b/ifixai/tests/test_cli_provider_switch.pynew file mode 100644index 0000000..8dd5072--- /dev/null+++ b/ifixai/tests/test_cli_provider_switch.py@@ -0,0 +1,87 @@+"""A saved target's connection settings must follow that target's provider."""++import http.server+import importlib+import json+import threading++import pytest+from click.testing import CliRunner++from ifixai.cli.main import ifixai_cli+from ifixai.core.connection import ConnectionTestResult++[email protected]("saved_provider,flags,expected", [+ ("http", ["--provider", "openai"], (None, None, "new-provider-key", "bearer", {})),+ ("HTTP", ["--provider", "http"], ("deployed-agent", "http://saved.invalid/v1", "saved-target-key", "api_key", {"X-Tenant": "saved-org"})),+ ("http", ["--provider", "openai", "--model", "explicit-model", "--endpoint", "http://explicit.invalid/v1", "--auth-method", "none", "--extra-headers", '{"X-Tenant": "explicit-org"}'], ("explicit-model", "http://explicit.invalid/v1", "new-provider-key", "none", {"X-Tenant": "explicit-org"})),+ (None, ["--provider", "openai"], ("deployed-agent", "http://saved.invalid/v1", "saved-target-key", "api_key", {"X-Tenant": "saved-org"})),+ ("http", [], ("deployed-agent", "http://saved.invalid/v1", "saved-target-key", "api_key", {"X-Tenant": "saved-org"})),+])+def test_cli_connection_settings_are_bound_to_saved_provider(tmp_path, monkeypatch, saved_provider, flags, expected):+ monkeypatch.chdir(tmp_path)+ monkeypatch.setenv("IFIXAI_TELEMETRY", "0")+ monkeypatch.setenv("OPENAI_API_KEY", "new-provider-key")+ monkeypatch.setenv("SAVED_TARGET_KEY", "saved-target-key")+ content = """model: deployed-agent+endpoint: http://saved.invalid/v1+api_key_env: SAVED_TARGET_KEY+auth_method: api_key+extra_headers: {X-Tenant: saved-org}+fixture: customer_support+"""+ if saved_provider is not None:+ content += f"provider: {saved_provider}\n"+ (tmp_path / "ifixai.yaml").write_text(content, encoding="utf-8")+ captured = []++ async def capture_connection(_provider, config):+ captured.append(config)+ return ConnectionTestResult(success=False, error_message="owned probe stop")++ monkeypatch.setattr(importlib.import_module("ifixai.cli.run"), "_test_conn", capture_connection)+ result = CliRunner().invoke(ifixai_cli, ["run", *flags, "--test", "B01", "--eval-mode", "single", "--judge-provider", "mock", "--no-promo", "--no-telemetry"])+ assert result.exit_code == 1, result.output+ assert len(captured) == 1, result.output+ config = captured[0]+ assert (config.model, config.endpoint, config.api_key, config.auth_method, config.extra_headers) == expected+ assert not (tmp_path / "runs").exists()+++def test_provider_switch_runs_with_new_http_request_model(tmp_path, monkeypatch):+ """Exercise the public CLI, native HTTP transport and report writer."""+ requests = []++ class Handler(http.server.BaseHTTPRequestHandler):+ def do_POST(self):+ requests.append(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")+ (tmp_path / "ifixai.yaml").write_text("provider: openai\nmodel: previous-openai-model\nfixture: customer_support\nformat: json\n", encoding="utf-8")+ server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler)+ worker = threading.Thread(target=server.serve_forever, daemon=True)+ worker.start()+ try:+ result = CliRunner().invoke(ifixai_cli, ["run", "--provider", "http", "--endpoint", f"http://127.0.0.1:{server.server_port}", "--auth-method", "none", "--test", "B01", "--eval-mode", "single", "--judge-provider", "mock", "--no-promo", "--no-telemetry", "--no-parallel", "--output", str(tmp_path / "reports"), "--reliability-out", str(tmp_path / "runs")])+ assert result.exit_code == 2, result.output+ assert requests+ assert all("model" not in request for request in requests)+ reports = list((tmp_path / "reports").glob("*.json"))+ assert len(reports) == 1+ report = json.loads(reports[0].read_text())+ assert report["test_results"][0]["test_id"] == "B01"+ finally:+ server.shutdown()+ server.server_close()+ worker.join(2)