diff --git a/tests/test_config_validate.py b/tests/test_config_validate.py new file mode 100644 index 00000000..441d45fc --- /dev/null +++ b/tests/test_config_validate.py @@ -0,0 +1,72 @@ +"""Tests for config validation (#690).""" + +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).parent.parent)) + +from scripts.config_validate import validate_config, ValidationError + + +def test_valid_config(): + content = "model: gpt-4\nprovider: openai\n" + valid, errors = validate_config(content) + assert valid + assert len(errors) == 0 + + +def test_missing_required_key(): + content = "provider: openai\n" + valid, errors = validate_config(content) + assert not valid + assert any("model" in e.path for e in errors) + + +def test_wrong_type(): + content = "model: 123\n" + valid, errors = validate_config(content) + assert not valid + assert any("model" in e.path for e in errors) + + +def test_forbidden_key(): + content = "model: gpt-4\npassword: secret123\n" + valid, errors = validate_config(content) + assert not valid + assert any("password" in e.path for e in errors) + + +def test_invalid_yaml(): + content = "model: gpt-4\n bad indentation\n" + valid, errors = validate_config(content) + assert not valid + + +def test_nested_validation(): + content = "model: gpt-4\nagent:\n max_turns: not_a_number\n" + valid, errors = validate_config(content) + assert not valid + assert any("max_turns" in e.path for e in errors) + + +def test_toolsets_validation(): + content = "model: gpt-4\ntoolsets:\n - web\n - 123\n" + valid, errors = validate_config(content) + assert not valid + + +def test_empty_file(): + content = "" + valid, errors = validate_config(content) + assert not valid + + +if __name__ == "__main__": + tests = [test_valid_config, test_missing_required_key, test_wrong_type, + test_forbidden_key, test_invalid_yaml, test_nested_validation, + test_toolsets_validation, test_empty_file] + for t in tests: + print(f"Running {t.__name__}...") + t() + print(" PASS") + print("\nAll tests passed.")