forked from cleveragents/cleveragents-core
3bd02a7c6e
Add CLI command group `agents automation-profile` with add, remove, list, and show subcommands for managing automation profiles that control plan execution autonomy. Changes: - New `automation_profile.py` CLI module with YAML config input, schema_version guard, namespaced name validation, --update support, and all output formats (json/yaml/plain/table/rich) - Register automation-profile in main CLI app - Add deprecation warnings for --automation-level on plan use and set-automation-level commands - Update CLI reference docs with command examples, built-in profiles list, and deprecation notes - 26 Behave scenarios covering all commands and error paths - 9 Robot Framework integration smoke tests - ASV benchmarks for CLI parsing performance - Mark A6.cli items complete in implementation_plan.md
172 lines
5.1 KiB
Python
172 lines
5.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Robot Framework helper for automation-profile CLI smoke tests.
|
|
|
|
Invoked by Robot tests to exercise the automation-profile CLI commands
|
|
in isolation using the Typer CliRunner with mocked services.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
# Ensure the local source tree is importable
|
|
_SRC = str(Path(__file__).resolve().parents[1] / "src")
|
|
if _SRC not in sys.path:
|
|
sys.path.insert(0, _SRC)
|
|
|
|
from typer.testing import CliRunner # noqa: E402
|
|
|
|
import cleveragents.cli.commands.automation_profile as _ap_mod # noqa: E402
|
|
|
|
_InMemoryProfileRepository = _ap_mod._InMemoryProfileRepository
|
|
profile_app = _ap_mod.app
|
|
|
|
_runner = CliRunner()
|
|
|
|
_VALID_YAML = """\
|
|
name: acme/robot-test
|
|
description: Robot test profile
|
|
schema_version: "1.0"
|
|
auto_strategize: 0.8
|
|
auto_execute: 0.7
|
|
auto_apply: 1.0
|
|
auto_decisions_strategize: 0.6
|
|
auto_decisions_execute: 0.8
|
|
auto_validation_fix: 0.7
|
|
auto_strategy_revision: 0.8
|
|
auto_reversion_from_apply: 0.9
|
|
auto_child_plans: 0.7
|
|
auto_retry_transient: 0.0
|
|
auto_checkpoint_restore: 0.6
|
|
require_sandbox: true
|
|
require_checkpoints: true
|
|
allow_unsafe_tools: false
|
|
"""
|
|
|
|
|
|
def _reset_repo() -> None:
|
|
"""Reset the module-level in-memory repo."""
|
|
import cleveragents.cli.commands.automation_profile as ap_mod
|
|
|
|
ap_mod._repo = _InMemoryProfileRepository()
|
|
|
|
|
|
def test_add_profile() -> None:
|
|
"""Test adding a profile via YAML config."""
|
|
_reset_repo()
|
|
fd, path = tempfile.mkstemp(suffix=".yaml")
|
|
try:
|
|
with os.fdopen(fd, "w") as fh:
|
|
fh.write(_VALID_YAML)
|
|
result = _runner.invoke(profile_app, ["add", "--config", path])
|
|
assert result.exit_code == 0, f"add failed: {result.output}"
|
|
print("add-profile-ok")
|
|
finally:
|
|
Path(path).unlink(missing_ok=True)
|
|
|
|
|
|
def test_show_profile() -> None:
|
|
"""Test showing a built-in profile."""
|
|
_reset_repo()
|
|
result = _runner.invoke(profile_app, ["show", "manual"])
|
|
assert result.exit_code == 0, f"show failed: {result.output}"
|
|
assert "manual" in result.output
|
|
print("show-profile-ok")
|
|
|
|
|
|
def test_show_json() -> None:
|
|
"""Test showing a profile in JSON format."""
|
|
_reset_repo()
|
|
result = _runner.invoke(profile_app, ["show", "manual", "--format", "json"])
|
|
assert result.exit_code == 0, f"show json failed: {result.output}"
|
|
# Verify it's valid JSON
|
|
parsed = json.loads(result.output)
|
|
assert parsed["name"] == "manual"
|
|
print("show-json-ok")
|
|
|
|
|
|
def test_show_yaml() -> None:
|
|
"""Test showing a profile in YAML format."""
|
|
_reset_repo()
|
|
result = _runner.invoke(profile_app, ["show", "manual", "--format", "yaml"])
|
|
assert result.exit_code == 0, f"show yaml failed: {result.output}"
|
|
assert "name: manual" in result.output
|
|
print("show-yaml-ok")
|
|
|
|
|
|
def test_list_profiles() -> None:
|
|
"""Test listing all profiles."""
|
|
_reset_repo()
|
|
result = _runner.invoke(profile_app, ["list"])
|
|
assert result.exit_code == 0, f"list failed: {result.output}"
|
|
assert "manual" in result.output
|
|
print("list-profiles-ok")
|
|
|
|
|
|
def test_list_json() -> None:
|
|
"""Test listing profiles in JSON format."""
|
|
_reset_repo()
|
|
result = _runner.invoke(profile_app, ["list", "--format", "json"])
|
|
assert result.exit_code == 0, f"list json failed: {result.output}"
|
|
parsed = json.loads(result.output)
|
|
assert isinstance(parsed, list)
|
|
assert len(parsed) >= 8 # At least 8 built-in profiles
|
|
print("list-json-ok")
|
|
|
|
|
|
def test_remove_profile() -> None:
|
|
"""Test removing a custom profile."""
|
|
_reset_repo()
|
|
# First add a profile
|
|
fd, path = tempfile.mkstemp(suffix=".yaml")
|
|
try:
|
|
with os.fdopen(fd, "w") as fh:
|
|
fh.write(_VALID_YAML)
|
|
add_result = _runner.invoke(profile_app, ["add", "--config", path])
|
|
assert add_result.exit_code == 0, f"add failed: {add_result.output}"
|
|
finally:
|
|
Path(path).unlink(missing_ok=True)
|
|
|
|
# Then remove it
|
|
result = _runner.invoke(profile_app, ["remove", "acme/robot-test", "--yes"])
|
|
assert result.exit_code == 0, f"remove failed: {result.output}"
|
|
assert "removed" in result.output.lower()
|
|
print("remove-profile-ok")
|
|
|
|
|
|
def test_remove_builtin_fails() -> None:
|
|
"""Test that removing a built-in profile fails."""
|
|
_reset_repo()
|
|
result = _runner.invoke(profile_app, ["remove", "manual", "--yes"])
|
|
assert result.exit_code != 0, f"remove should have failed: {result.output}"
|
|
print("remove-builtin-fails-ok")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
command = sys.argv[1] if len(sys.argv) > 1 else "all"
|
|
|
|
tests = {
|
|
"add": test_add_profile,
|
|
"show": test_show_profile,
|
|
"show-json": test_show_json,
|
|
"show-yaml": test_show_yaml,
|
|
"list": test_list_profiles,
|
|
"list-json": test_list_json,
|
|
"remove": test_remove_profile,
|
|
"remove-builtin-fails": test_remove_builtin_fails,
|
|
}
|
|
|
|
if command == "all":
|
|
for _name, test_fn in tests.items():
|
|
test_fn()
|
|
print("all-tests-ok")
|
|
elif command in tests:
|
|
tests[command]()
|
|
else:
|
|
print(f"Unknown test: {command}", file=sys.stderr)
|
|
sys.exit(1)
|