80f1664a0d
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 23s
CI / lint (pull_request) Successful in 3m20s
CI / typecheck (pull_request) Successful in 3m54s
CI / security (pull_request) Successful in 4m13s
CI / quality (pull_request) Successful in 4m17s
CI / integration_tests (pull_request) Successful in 9m21s
CI / unit_tests (pull_request) Successful in 9m42s
CI / docker (pull_request) Successful in 14s
CI / e2e_tests (pull_request) Successful in 12m1s
CI / coverage (pull_request) Successful in 11m41s
CI / status-check (pull_request) Successful in 1s
CI / build (push) Successful in 26s
CI / lint (push) Successful in 3m19s
CI / quality (push) Successful in 3m41s
CI / typecheck (push) Successful in 3m56s
CI / benchmark-regression (push) Has been skipped
CI / security (push) Successful in 4m2s
CI / integration_tests (push) Successful in 9m3s
CI / unit_tests (push) Successful in 9m24s
CI / docker (push) Successful in 1m9s
CI / e2e_tests (push) Successful in 13m51s
CI / coverage (push) Successful in 11m25s
CI / status-check (push) Successful in 1s
CI / benchmark-publish (push) Failing after 24m52s
CI / benchmark-regression (pull_request) Failing after 37m6s
Implemented Robot Framework integration test suite validating the CI/CD workflow (Specification Example 7). Tests cover ci-profile configuration (automation-profile, format, log level), idempotent resource and project registration with duplicate-detection assertions, three validation tools (ci-lint, ci-typecheck, ci-tests) registration and resource attachment via ToolRegistryService, action creation with typed arguments and invariants per spec Step 2, plan lifecycle with phase-by-phase completion through all phases (strategize, execute, apply) until terminal applied state, and JSON output structure verification including plan_id, phase, state, action, projects, and arguments fields. Post-review fixes applied (round 1): - H1: Fix truncated invariant #2 text to match spec line 39051 - H2: Fix definition_of_done to match spec's 5-bullet-point format - M1: Register all 3 spec validations (ci-lint, ci-typecheck, ci-tests) - M3: Add branch property to resource registration per spec Step 3 - M4: Replace phantom resource_id with real registered resource - M5: Add projects and arguments field assertions to JSON output test - M7: Replace 'polling-based' with 'phase-by-phase' in docs/comments - L1: Use timezone-aware datetime (timezone.utc) - L2: Use tempfile for resource path instead of hardcoded /tmp - L3: Clarify json_output() docstring to reflect as_cli_dict() scope - L4: Tighten attachment count assertion from >= 1 to == 1 (now == 3) Post-review fixes applied (round 2): - M2: Use Setup Test Environment With Database Isolation for pabot safety - L1: Replace remaining hardcoded /tmp paths with tempfile (validation_attach, resource_idempotent duplicate registration) - L2: Fix stale 'Polling-based' comment missed in round 1 - L5: Align action description with spec line 39027 - M1/L3/L6: Document automation_profile propagation gap in use_action() with TODO for when production code wires the field onto Plan - L4: Add comment explaining local actor name deviation from spec Includes CHANGELOG update describing the integration test scope. ISSUES CLOSED: #771
175 lines
5.4 KiB
Python
175 lines
5.4 KiB
Python
"""ASV benchmarks for Resource CLI tree/inspect command overhead.
|
|
|
|
Measures the performance of:
|
|
- Tree rendering for a resource with no children
|
|
- Tree rendering for a resource with multiple children
|
|
- Inspect command rendering
|
|
- Link-child / unlink-child command throughput
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
import sys
|
|
from datetime import UTC, 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.resource import app as resource_app # noqa: E402
|
|
from cleveragents.domain.models.core.resource import ( # noqa: E402
|
|
PhysVirt,
|
|
Resource,
|
|
ResourceCapabilities,
|
|
)
|
|
|
|
_runner = CliRunner()
|
|
|
|
|
|
def _mock_resource(
|
|
resource_id: str = "01HBENCH0000000000RES0RCE0",
|
|
name: str = "local/bench-res",
|
|
type_name: str = "git-checkout",
|
|
) -> Resource:
|
|
return Resource(
|
|
resource_id=resource_id,
|
|
name=name,
|
|
resource_type_name=type_name,
|
|
classification=PhysVirt.PHYSICAL,
|
|
description="Benchmark resource",
|
|
properties={"path": "/tmp/bench"},
|
|
location="/tmp/bench",
|
|
content_hash=None,
|
|
sandbox_strategy=None,
|
|
capabilities=ResourceCapabilities(),
|
|
created_at=datetime.now(tz=UTC),
|
|
updated_at=datetime.now(tz=UTC),
|
|
)
|
|
|
|
|
|
def _mock_tree_node(
|
|
resource: Resource,
|
|
children: list[dict[str, object]] | None = None,
|
|
) -> dict[str, object]:
|
|
return {
|
|
"resource": resource,
|
|
"children": children or [],
|
|
}
|
|
|
|
|
|
class ResourceTreeSuite:
|
|
"""Benchmark resource tree command throughput."""
|
|
|
|
def setup(self) -> None:
|
|
"""Set up mock service."""
|
|
root = _mock_resource()
|
|
child1 = _mock_resource(
|
|
"01HBENCH0000000000CHJKD001", "local/child-1", "fs-directory"
|
|
)
|
|
child2 = _mock_resource(
|
|
"01HBENCH0000000000CHJKD002", "local/child-2", "fs-directory"
|
|
)
|
|
tree = [
|
|
_mock_tree_node(
|
|
root,
|
|
[
|
|
_mock_tree_node(child1),
|
|
_mock_tree_node(child2),
|
|
],
|
|
)
|
|
]
|
|
self._mock_service = MagicMock()
|
|
self._mock_service.get_resource_tree.return_value = tree
|
|
self._mock_service.show_resource.return_value = root
|
|
self._patcher = patch(
|
|
"cleveragents.cli.commands.resource._get_registry_service",
|
|
return_value=self._mock_service,
|
|
)
|
|
self._patcher.start()
|
|
|
|
def teardown(self) -> None:
|
|
self._patcher.stop()
|
|
|
|
def time_tree_default(self) -> None:
|
|
"""Benchmark tree with default settings."""
|
|
_runner.invoke(resource_app, ["tree", "local/bench-res"])
|
|
|
|
def time_tree_json(self) -> None:
|
|
"""Benchmark tree with JSON output."""
|
|
_runner.invoke(resource_app, ["tree", "local/bench-res", "--format", "json"])
|
|
|
|
def time_tree_depth(self) -> None:
|
|
"""Benchmark tree with depth limit."""
|
|
_runner.invoke(resource_app, ["tree", "local/bench-res", "--depth", "1"])
|
|
|
|
|
|
class ResourceInspectSuite:
|
|
"""Benchmark resource inspect command throughput."""
|
|
|
|
def setup(self) -> None:
|
|
"""Set up mock service."""
|
|
res = _mock_resource()
|
|
tree = [_mock_tree_node(res)]
|
|
self._mock_service = MagicMock()
|
|
self._mock_service.show_resource.return_value = res
|
|
self._mock_service.get_resource_tree.return_value = tree
|
|
self._patcher = patch(
|
|
"cleveragents.cli.commands.resource._get_registry_service",
|
|
return_value=self._mock_service,
|
|
)
|
|
self._patcher.start()
|
|
|
|
def teardown(self) -> None:
|
|
self._patcher.stop()
|
|
|
|
def time_inspect_default(self) -> None:
|
|
"""Benchmark inspect with default settings."""
|
|
_runner.invoke(resource_app, ["inspect", "local/bench-res"])
|
|
|
|
def time_inspect_json(self) -> None:
|
|
"""Benchmark inspect with JSON output."""
|
|
_runner.invoke(resource_app, ["inspect", "local/bench-res", "--format", "json"])
|
|
|
|
def time_inspect_with_tree(self) -> None:
|
|
"""Benchmark inspect with --tree flag."""
|
|
_runner.invoke(resource_app, ["inspect", "local/bench-res", "--tree"])
|
|
|
|
|
|
class ResourceLinkSuite:
|
|
"""Benchmark resource link-child/unlink-child command throughput."""
|
|
|
|
def setup(self) -> None:
|
|
"""Set up mock service."""
|
|
self._mock_service = MagicMock()
|
|
self._mock_service.link_child.return_value = None
|
|
self._mock_service.unlink_child.return_value = None
|
|
self._patcher = patch(
|
|
"cleveragents.cli.commands.resource._get_registry_service",
|
|
return_value=self._mock_service,
|
|
)
|
|
self._patcher.start()
|
|
|
|
def teardown(self) -> None:
|
|
self._patcher.stop()
|
|
|
|
def time_link_child(self) -> None:
|
|
"""Benchmark link-child command."""
|
|
_runner.invoke(resource_app, ["link-child", "local/parent", "local/child"])
|
|
|
|
def time_unlink_child(self) -> None:
|
|
"""Benchmark unlink-child command."""
|
|
_runner.invoke(
|
|
resource_app, ["unlink-child", "--yes", "local/parent", "local/child"]
|
|
)
|