Files
cleveragents-core/benchmarks/automation_profile_cli_bench.py
CoreRasurae 66b9a4279f feat(security): add safety profile model and enforcement stubs
Add SafetyProfile domain model with configurable safety constraints
(checkpoint, human approval, cost limits, retry limits, skill
categories, sandbox requirement).  Integrate into Action model with
from_config/as_cli_dict support, and persist via LifecycleActionModel
safety_profile_json column.

Include resolve_safety_profile() stub that raises NotImplementedError
for local mode, signalling that real enforcement is deferred.

Add comprehensive test coverage:
- 20 BDD scenarios in features/safety_profile.feature
- 6 Robot Framework smoke tests
- 5 ASV benchmark suites (11 timing functions)

Add docs/reference/safety_profile.md reference documentation.

ISSUES CLOSED: #332
2026-03-02 17:44:18 +00:00

126 lines
3.4 KiB
Python

"""ASV benchmarks for Automation Profile CLI command throughput.
Measures the performance of:
- Add profile from YAML config
- List profiles rendering
- Show profile rendering
- Remove profile
"""
from __future__ import annotations
import importlib
import os
import sys
import tempfile
from pathlib import Path
# Ensure the local *source* tree is importable even when ASV has an
# older build of the package installed.
_SRC = str(Path(__file__).resolve().parents[1] / "src")
if _SRC not in sys.path:
sys.path.insert(0, _SRC)
import cleveragents # noqa: E402
importlib.reload(cleveragents)
from typer.testing import CliRunner # noqa: E402
from cleveragents.cli.commands.automation_profile import ( # noqa: E402
_InMemoryProfileRepository,
)
from cleveragents.cli.commands.automation_profile import ( # noqa: E402
app as profile_app,
)
_VALID_YAML = """\
name: bench/test-profile
description: Benchmark test profile
schema_version: "1.0"
auto_strategize: 0.5
auto_execute: 0.5
auto_apply: 1.0
auto_decisions_strategize: 0.5
auto_decisions_execute: 0.5
auto_validation_fix: 0.5
auto_strategy_revision: 0.5
auto_reversion_from_apply: 0.5
auto_child_plans: 0.5
auto_retry_transient: 0.0
auto_checkpoint_restore: 0.5
safety:
require_sandbox: true
require_checkpoints: true
allow_unsafe_tools: false
"""
_runner = CliRunner()
def _reset_repo() -> None:
"""Reset the module-level in-memory repo."""
import cleveragents.cli.commands.automation_profile as ap_mod
ap_mod._repo = _InMemoryProfileRepository()
class AutomationProfileCLIAddSuite:
"""Benchmark automation-profile add --config throughput."""
def setup(self) -> None:
"""Write a temporary YAML file."""
_reset_repo()
fd, self._path = tempfile.mkstemp(suffix=".yaml")
with os.fdopen(fd, "w") as fh:
fh.write(_VALID_YAML)
def teardown(self) -> None:
"""Clean up."""
Path(self._path).unlink(missing_ok=True)
def time_add_from_config(self) -> None:
"""Benchmark add --config end-to-end."""
_reset_repo()
_runner.invoke(profile_app, ["add", "--config", self._path])
class AutomationProfileCLIListSuite:
"""Benchmark automation-profile list throughput."""
def setup(self) -> None:
"""Set up with built-in profiles."""
_reset_repo()
def time_list_all(self) -> None:
"""Benchmark listing all profiles."""
_runner.invoke(profile_app, ["list"])
def time_list_json(self) -> None:
"""Benchmark listing profiles as JSON."""
_runner.invoke(profile_app, ["list", "--format", "json"])
def time_list_with_regex(self) -> None:
"""Benchmark listing with regex filter."""
_runner.invoke(profile_app, ["list", "caut.*"])
class AutomationProfileCLIShowSuite:
"""Benchmark automation-profile show throughput."""
def setup(self) -> None:
"""Set up."""
_reset_repo()
def time_show_rich(self) -> None:
"""Benchmark showing a profile in rich format."""
_runner.invoke(profile_app, ["show", "manual"])
def time_show_json(self) -> None:
"""Benchmark showing a profile in JSON format."""
_runner.invoke(profile_app, ["show", "manual", "--format", "json"])
def time_show_yaml(self) -> None:
"""Benchmark showing a profile in YAML format."""
_runner.invoke(profile_app, ["show", "manual", "--format", "yaml"])