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 non-string config keys without a traceback (#354)

Andrew Barnesbd0ed65f035f
diff --git a/ifixai/cli/config_file.py b/ifixai/cli/config_file.py
index c4f3692..5192afc 100644
--- a/ifixai/cli/config_file.py
+++ b/ifixai/cli/config_file.py
@@ -65,6 +65,8 @@ def load_config(start_dir: Path | None = None) -> RunConfig | None:
if not isinstance(raw, dict):
# All config-load failures surface as ValueError so callers catch one type.
raise ValueError(f"{CONFIG_FILENAME} must contain a mapping at the top level.") # noqa: TRY004
+ if any(not isinstance(key, str) for key in raw):
+ raise ValueError(f"{CONFIG_FILENAME} must contain only string keys at the top level.")
try:
return RunConfig(**raw)
except ValidationError as exc:
diff --git a/ifixai/tests/test_cli_config_read_errors.py b/ifixai/tests/test_cli_config_read_errors.py
index a0e3167..6840c97 100644
--- a/ifixai/tests/test_cli_config_read_errors.py
+++ b/ifixai/tests/test_cli_config_read_errors.py
@@ -78,3 +78,16 @@ def test_yaml_validation_keeps_its_existing_error(tmp_path):
(tmp_path / "ifixai.yaml").write_text("provider: [\n", encoding="utf-8")
with pytest.raises(ValueError, match="is not valid YAML"):
load_config(tmp_path)
+
+
[email protected]("key", ["1", "true", "null"])
+def test_nonstring_config_keys_report_config_error(tmp_path, key):
+ (tmp_path / "ifixai.yaml").write_text(
+ f"provider: mock\n{key}: unexpected\n", encoding="utf-8"
+ )
+ result = _run(tmp_path)
+ assert result.returncode == 1
+ assert "Config error: ifixai.yaml" in result.stderr
+ assert "string keys at the top level" in result.stderr
+ assert "Traceback" not in result.stderr
+ assert "Dry run" not in result.stdout
diff --git a/ifixai/tests/test_config_empty_nonmapping.py b/ifixai/tests/test_config_empty_nonmapping.py
index 8f81843..7434bc6 100644
--- a/ifixai/tests/test_config_empty_nonmapping.py
+++ b/ifixai/tests/test_config_empty_nonmapping.py
@@ -16,3 +16,12 @@ def test_falsey_nonmapping_config_is_rejected(tmp_path: Path, document: str) ->
def test_empty_config_remains_supported(tmp_path: Path, document: str) -> None:
(tmp_path / 'ifixai.yaml').write_text(document, encoding='utf-8')
assert load_config(tmp_path) is not None
+
+
[email protected]('key', ['1', 'true', 'null'])
+def test_nonstring_config_keys_are_rejected(tmp_path: Path, key: str) -> None:
+ (tmp_path / 'ifixai.yaml').write_text(
+ f'provider: mock\n{key}: unexpected\n', encoding='utf-8'
+ )
+ with pytest.raises(ValueError, match='string keys at the top level'):
+ load_config(tmp_path)