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): reject nonfinite and out-of-range minimum scores (#196)

Rudy Mizrahi Celeklibeb5537d5cdb
diff --git a/ifixai/cli/run.py b/ifixai/cli/run.py
index ea74b7f..46ce79c 100644
--- a/ifixai/cli/run.py
+++ b/ifixai/cli/run.py
@@ -333,6 +333,12 @@ async def _probe_then_close(
await _aclose_provider(provider)
+def _validate_min_score(ctx: click.Context, param: click.Parameter, value: float) -> float:
+ if not 0 <= value <= 1:
+ raise click.BadParameter("must be a finite number between 0 and 1", ctx=ctx, param=param)
+ return value
+
+
@click.command()
@click.option(
"--provider",
@@ -495,6 +501,7 @@ async def _probe_then_close(
@click.option(
"--min-score",
type=float,
+ callback=_validate_min_score,
default=0.85,
show_default=True,
help="Minimum overall score; exit code 2 if below (default: 0.85 per ifixai spec).",
diff --git a/ifixai/tests/test_cli_keyless_providers.py b/ifixai/tests/test_cli_keyless_providers.py
index 0b4d191..51e914e 100644
--- a/ifixai/tests/test_cli_keyless_providers.py
+++ b/ifixai/tests/test_cli_keyless_providers.py
@@ -119,3 +119,33 @@ def test_authenticated_provider_still_rejects_missing_key(
assert result.exit_code == 1
assert "No API key found" in result.output
assert not (tmp_path / "ifixai-results").exists()
+
+
[email protected]("threshold", ["nan", "inf", "-inf", "-0.1", "1.1"])
+def test_invalid_minimum_score_fails_before_run(tmp_path, monkeypatch, threshold):
+ monkeypatch.chdir(tmp_path)
+ result = CliRunner().invoke(ifixai_cli, [
+ "run", "--provider", "mock", "--fixture", "customer_support",
+ "--test", "B01", "--test", "B08", "--test", "P01", "--test", "B25",
+ "--eval-mode", "single", "--judge-provider", "mock",
+ "--min-score", threshold, "--no-telemetry", "--no-parallel",
+ ])
+ assert result.exit_code == 2, result.output
+ assert "Invalid value for '--min-score'" in result.output
+ assert not (tmp_path / "ifixai-results").exists()
+ assert not (tmp_path / "runs").exists()
+
+
[email protected]("threshold,expected_exit", [("0", 0), ("1", 2)])
+def test_valid_minimum_score_preserves_offline_ci_gate(tmp_path, monkeypatch, threshold, expected_exit):
+ monkeypatch.chdir(tmp_path)
+ result = CliRunner().invoke(ifixai_cli, [
+ "run", "--provider", "mock", "--fixture", "customer_support",
+ "--test", "B01", "--test", "B08", "--test", "P01", "--test", "B25",
+ "--eval-mode", "single", "--judge-provider", "mock",
+ "--min-score", threshold, "--no-telemetry", "--no-parallel",
+ ])
+ assert result.exit_code == expected_exit, result.output
+ reports = list((tmp_path / "ifixai-results").glob("*.json"))
+ assert len(reports) == 1
+ assert 0 < json.loads(reports[0].read_text())["overall"]["score"] < 1