"""ASV benchmarks for Plan Sync client.""" from __future__ import annotations import importlib import sys from pathlib import Path from unittest.mock import MagicMock import httpx _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 cleveragents.client.http_client import ServerHttpClient # noqa: E402 from cleveragents.client.sync_client import ( # noqa: E402 ExecutionResult, PlanSyncClient, SyncScope, SyncSummary, ) def _mock_response(status: int = 200, body: dict | None = None) -> httpx.Response: return httpx.Response( status_code=status, json=body, headers={}, request=httpx.Request("GET", "http://mock"), ) class SyncScopeSuite: """Benchmark SyncScope operations.""" timeout = 60 def time_active_types_all(self) -> None: SyncScope().active_types() def time_active_types_partial(self) -> None: SyncScope(actions=True, skills=False, tools=True, projects=False).active_types() class SyncOperationSuite: """Benchmark sync operations.""" timeout = 60 def setup(self) -> None: self.mock_http = MagicMock(spec=ServerHttpClient) self.mock_http.request.return_value = _mock_response(200, {"id": "srv"}) self.client = PlanSyncClient(self.mock_http) self.items = [{"id": f"item-{i}"} for i in range(10)] def time_sync_10_items(self) -> None: self.client.sync(self.items, "actions") def time_sync_dry_run(self) -> None: self.client.sync(self.items, "actions", dry_run=True) class SyncSummarySuite: """Benchmark SyncSummary creation.""" timeout = 60 def time_summary_creation(self) -> None: SyncSummary(created=5, updated=3, skipped=1, errors=0) def time_total_processed(self) -> None: s = SyncSummary(created=5, updated=3, skipped=1, errors=1) _ = s.total_processed class ExecutionResultSuite: """Benchmark ExecutionResult creation.""" timeout = 60 def time_create_result(self) -> None: ExecutionResult(plan_id="p1", server_plan_id="sp1", status="done", message="ok")