Files
cleveragents-core/benchmarks/plan_cli_bench.py
T
freemo 65988669a6
CI / coverage (push) Blocked by required conditions
CI / build (push) Waiting to run
CI / lint (push) Waiting to run
CI / typecheck (push) Waiting to run
CI / docker (push) Blocked by required conditions
CI / security (push) Waiting to run
CI / quality (push) Waiting to run
CI / unit_tests (push) Waiting to run
CI / integration_tests (push) Waiting to run
CI / lint (pull_request) Successful in 16s
CI / typecheck (pull_request) Successful in 26s
CI / security (pull_request) Successful in 22s
CI / quality (pull_request) Successful in 15s
CI / integration_tests (pull_request) Successful in 4m31s
CI / build (pull_request) Successful in 16s
CI / unit_tests (pull_request) Successful in 9m18s
CI / coverage (pull_request) Successful in 6m54s
CI / docker (pull_request) Successful in 39s
feat(cli): align plan use/list/status flags
- plan use: accept positional PROJECT args, add --automation-profile,
  --invariant (repeatable), and actor override flags
- lifecycle-list: add --state/--processing-state, --action filters,
  optional positional REGEX for name filtering, Action column in output
- plan status: enhanced detail view with processing state, project
  links, arguments order, automation profile provenance, actor
  overrides, automation level, and full timestamps
- Add docs/reference/plan_cli.md reference documentation
- Add Behave feature (17 scenarios) with mock service steps
- Add Robot smoke test (7 cases) with import-safe helper
- Add ASV benchmarks for plan use/list/status commands
2026-02-14 13:42:02 -05:00

199 lines
5.9 KiB
Python

"""ASV benchmarks for Plan CLI command throughput.
Measures the performance of:
- Plan use with multiple projects and flags
- Lifecycle-list with various filters
- Plan status rendering
- Plan cancel with reason
"""
from __future__ import annotations
import importlib
import sys
from datetime import datetime
from pathlib import Path
from unittest.mock import MagicMock, patch
# 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.plan import app as plan_app # noqa: E402
from cleveragents.domain.models.core.action import Action, ActionState # noqa: E402
from cleveragents.domain.models.core.plan import ( # noqa: E402
AutomationLevel,
AutomationProfileProvenance,
AutomationProfileRef,
NamespacedName,
Plan,
PlanIdentity,
PlanPhase,
PlanTimestamps,
ProcessingState,
ProjectLink,
)
_runner = CliRunner()
_PLAN_ULID = "01KHDE6WWS2171PWW3GJEBXZ8S"
def _mock_action(name: str = "local/bench-action") -> Action:
return Action(
namespaced_name=NamespacedName.parse(name),
description="Benchmark action",
long_description=None,
definition_of_done="Benchmarks pass",
strategy_actor="openai/gpt-4",
execution_actor="openai/gpt-4",
reusable=True,
read_only=False,
state=ActionState.AVAILABLE,
created_by=None,
created_at=datetime.now(),
updated_at=datetime.now(),
)
def _mock_plan(
name: str = "local/bench-plan",
project_links: list[ProjectLink] | None = None,
) -> Plan:
now = datetime.now()
return Plan(
identity=PlanIdentity(plan_id=_PLAN_ULID),
namespaced_name=NamespacedName.parse(name),
description="Benchmark plan",
definition_of_done="Benchmarks pass",
action_name="local/bench-action",
phase=PlanPhase.STRATEGIZE,
processing_state=ProcessingState.QUEUED,
automation_level=AutomationLevel.MANUAL,
project_links=project_links or [],
arguments={"target_coverage": 80},
arguments_order=["target_coverage"],
automation_profile=AutomationProfileRef(
profile_name="trusted",
provenance=AutomationProfileProvenance.PLAN,
),
strategy_actor="openai/gpt-4",
execution_actor="openai/gpt-4",
estimation_actor="openai/gpt-4",
invariant_actor="openai/gpt-4",
reusable=True,
read_only=False,
created_by=None,
timestamps=PlanTimestamps(created_at=now, updated_at=now),
)
class PlanCLIUseSuite:
"""Benchmark plan use command throughput."""
def setup(self) -> None:
"""Set up mock service."""
self._mock_service = MagicMock()
self._mock_service.get_action_by_name.return_value = _mock_action()
self._mock_service.use_action.return_value = _mock_plan(
project_links=[
ProjectLink(project_name="proj-a"),
ProjectLink(project_name="proj-b"),
]
)
self._patcher = patch(
"cleveragents.cli.commands.plan._get_lifecycle_service",
return_value=self._mock_service,
)
self._patcher.start()
def teardown(self) -> None:
self._patcher.stop()
def time_use_with_projects(self) -> None:
"""Benchmark plan use with multiple projects."""
_runner.invoke(
plan_app,
["use", "local/bench-action", "proj-a", "proj-b", "--arg", "coverage=80"],
)
def time_use_with_all_flags(self) -> None:
"""Benchmark plan use with all flags."""
_runner.invoke(
plan_app,
[
"use",
"local/bench-action",
"proj-a",
"--automation-profile",
"trusted",
"--invariant",
"No warnings",
"--strategy-actor",
"openai/gpt-4",
"--execution-actor",
"openai/gpt-4",
"--arg",
"coverage=80",
],
)
class PlanCLIListSuite:
"""Benchmark plan lifecycle-list throughput."""
def setup(self) -> None:
self._mock_service = MagicMock()
self._mock_service.list_plans.return_value = [
_mock_plan(f"local/plan-{i}") for i in range(50)
]
self._patcher = patch(
"cleveragents.cli.commands.plan._get_lifecycle_service",
return_value=self._mock_service,
)
self._patcher.start()
def teardown(self) -> None:
self._patcher.stop()
def time_list_all(self) -> None:
"""Benchmark listing all plans."""
_runner.invoke(plan_app, ["lifecycle-list"])
def time_list_with_phase(self) -> None:
"""Benchmark listing with phase filter."""
_runner.invoke(plan_app, ["lifecycle-list", "--phase", "strategize"])
def time_list_with_state(self) -> None:
"""Benchmark listing with state filter."""
_runner.invoke(plan_app, ["lifecycle-list", "--state", "queued"])
class PlanCLIStatusSuite:
"""Benchmark plan status rendering."""
def setup(self) -> None:
self._mock_service = MagicMock()
self._mock_service.get_plan.return_value = _mock_plan(
project_links=[ProjectLink(project_name="proj-a", alias="api")]
)
self._patcher = patch(
"cleveragents.cli.commands.plan._get_lifecycle_service",
return_value=self._mock_service,
)
self._patcher.start()
def teardown(self) -> None:
self._patcher.stop()
def time_status(self) -> None:
"""Benchmark rendering plan status."""
_runner.invoke(plan_app, ["status", _PLAN_ULID])