Files
cleveragents-core/robot/helper_action_schema.py

57 lines
1.6 KiB
Python

"""Robot Framework helper for action YAML schema validation.
Provides a CLI-style interface for Robot to invoke schema validation
on action YAML files. Exit code 0 = success, 1 = failure.
Usage:
python robot/helper_action_schema.py validate <yaml_file>
python robot/helper_action_schema.py validate-invalid <yaml_file>
"""
from __future__ import annotations
import sys
from pathlib import Path
# Ensure the src directory is on the import path.
_SRC = str(Path(__file__).resolve().parents[1] / "src")
if _SRC not in sys.path:
sys.path.insert(0, _SRC)
from cleveragents.action.schema import ActionConfigSchema # noqa: E402
def main() -> int:
"""Entry point called by Robot Framework ``Run Process``."""
if len(sys.argv) < 3:
print("Usage: helper_action_schema.py <validate|validate-invalid> <file>")
return 1
command = sys.argv[1]
yaml_path = sys.argv[2]
if command == "validate":
try:
config = ActionConfigSchema.from_yaml_file(yaml_path)
print(f"action-schema-ok: {config.name}")
return 0
except Exception as exc:
print(f"action-schema-fail: {exc}")
return 1
if command == "validate-invalid":
try:
ActionConfigSchema.from_yaml_file(yaml_path)
print("action-schema-unexpected-success")
return 1
except Exception as exc:
print(f"action-schema-expected-fail: {exc}")
return 0
print(f"Unknown command: {command}")
return 1
if __name__ == "__main__":
sys.exit(main())