Files
cleveragents-core/robot/helper_actor_schema.py
aditya 2764fcef5c
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 16s
CI / build (pull_request) Successful in 25s
CI / quality (pull_request) Successful in 34s
CI / typecheck (pull_request) Successful in 39s
CI / security (pull_request) Successful in 52s
CI / unit_tests (pull_request) Successful in 2m51s
CI / integration_tests (pull_request) Successful in 3m41s
CI / docker (pull_request) Successful in 56s
CI / e2e_tests (pull_request) Successful in 3m56s
CI / coverage (pull_request) Successful in 6m28s
CI / benchmark-regression (pull_request) Successful in 38m39s
fix(actor,preflight,tests): resolve PR #975 review findings and stabilize full-suite coverage runs
Address review-driven fixes across actor schema, preflight guardrails, docs/examples,
and Behave/Robot coverage: unify preflight warning behavior with shared role-warning logic,
resolve actor-name to config payloads in production preflight flow, harden response_format
validation/coercion edge cases, extract duplicated helper logic, and expand negative-path
test coverage. Also fix cross-scenario patcher leakage in step modules to eliminate
full-run-only coverage failures.
2026-03-18 06:58:39 +00:00

139 lines
4.3 KiB
Python

"""Robot Framework helper for actor YAML schema validation.
Provides a CLI-style interface for Robot to invoke schema validation
on actor YAML files. Exit code 0 = success, 1 = failure.
Usage:
python robot/helper_actor_schema.py validate <yaml_file>
python robot/helper_actor_schema.py validate-invalid <yaml_file>
"""
from __future__ import annotations
import io
import logging
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.actor.schema import ( # noqa: E402
ActorConfigSchema,
actor_role_warnings,
)
def main() -> int:
"""Entry point called by Robot Framework ``Run Process``."""
if len(sys.argv) < 3:
print(
"Usage: helper_actor_schema.py "
"<validate|validate-invalid|role-warning-model|role-warning-payload|"
"role-warning-uppercase|role-warning-invalid-role-log> <file-or-dummy>"
)
return 1
command = sys.argv[1]
yaml_path = sys.argv[2]
if command == "validate":
try:
config = ActorConfigSchema.from_yaml_file(yaml_path)
print(f"actor-schema-ok: {config.name}")
return 0
except Exception as exc:
print(f"actor-schema-fail: {exc}")
return 1
if command == "validate-invalid":
try:
ActorConfigSchema.from_yaml_file(yaml_path)
print("actor-schema-unexpected-success")
return 1
except Exception as exc:
print(f"actor-schema-expected-fail: {exc}")
return 0
if command == "role-warning-model":
actor = ActorConfigSchema(
name="local/robot-model-warning",
type="llm",
description="Robot model warning check",
model="gpt-4",
role_hint="estimation",
context_view="strategist",
)
warnings = actor_role_warnings(actor)
if any("response_format" in warning for warning in warnings):
print("actor-role-warning-model-ok")
return 0
print(f"actor-role-warning-model-fail: {warnings}")
return 1
if command == "role-warning-payload":
payload = {
"name": "local/robot-payload-warning",
"type": "llm",
"model": "gpt-4",
"role_hint": "estimation",
"context_view": "plannerish",
"response_format": {"type": "object"},
}
warnings = actor_role_warnings(payload)
if any("context_view" in warning for warning in warnings):
print("actor-role-warning-payload-ok")
return 0
print(f"actor-role-warning-payload-fail: {warnings}")
return 1
if command == "role-warning-uppercase":
payload = {
"name": "local/robot-uppercase-warning",
"type": "llm",
"model": "gpt-4",
"role_hint": "ESTIMATION",
"context_view": "strategist",
}
warnings = actor_role_warnings(payload)
if any("response_format" in warning for warning in warnings):
print("actor-role-warning-uppercase-ok")
return 0
print(f"actor-role-warning-uppercase-fail: {warnings}")
return 1
if command == "role-warning-invalid-role-log":
stream = io.StringIO()
handler = logging.StreamHandler(stream)
schema_logger = logging.getLogger("cleveragents.actor.role_validation")
schema_logger.addHandler(handler)
schema_logger.setLevel(logging.WARNING)
try:
payload = {
"name": "local/robot-invalid-role-warning",
"type": "llm",
"model": "gpt-4",
"role_hint": "estmation",
}
warnings = actor_role_warnings(payload)
finally:
schema_logger.removeHandler(handler)
logs = stream.getvalue()
if "Unrecognized role_hint value" in logs and warnings == []:
print("actor-role-warning-invalid-role-log-ok")
return 0
print(
f"actor-role-warning-invalid-role-log-fail: warnings={warnings} logs={logs}"
)
return 1
print(f"Unknown command: {command}")
return 1
if __name__ == "__main__":
sys.exit(main())