Files
temp/features/steps/a2a_facade_coverage_boost_steps.py
T
freemo ec0b7631d0 refactor(a2a): rename ACP module and symbols to A2A standard
Renamed src/cleveragents/acp/ to src/cleveragents/a2a/ and all 13
Acp* classes to A2a* per ADR-047 (A2A Standard Adoption). Updated
all imports, structlog event names (acp.* → a2a.*), field names
(acp_version → a2a_version), and test references across the entire
codebase. This is a cosmetic rename only — no behavioral changes.

ISSUES CLOSED: #688
2026-03-12 14:38:57 +00:00

130 lines
4.6 KiB
Python

"""Step definitions for A2A facade coverage-boost scenarios.
Targets uncovered lines in ``src/cleveragents/a2a/facade.py``:
| Line | Code path |
|------|--------------------------------------------------------|
| 82 | TypeError when ``services`` is not a dict or None |
| 256 | ValueError in plan.execute when plan_id is empty |
| 266 | ValueError in plan.status when plan_id is empty |
| 281 | ValueError in plan.diff when plan_id is empty |
| 295 | ValueError in plan.apply when plan_id is empty |
"""
from __future__ import annotations
import json
from typing import Any
from unittest.mock import MagicMock
from behave import given, then, use_step_matcher, when
from behave.runner import Context
from cleveragents.a2a.facade import A2aLocalFacade
from cleveragents.a2a.models import A2aRequest
use_step_matcher("re")
# ---------------------------------------------------------------------------
# Mock helpers (mirrors wiring steps — kept local to avoid coupling)
# ---------------------------------------------------------------------------
class _MockPlanIdentity:
def __init__(self, plan_id: str = "MOCK-PLAN-001") -> None:
self.plan_id = plan_id
class _MockPlan:
def __init__(self, plan_id: str = "MOCK-PLAN-001") -> None:
self.identity = _MockPlanIdentity(plan_id)
self.phase = MagicMock()
self.phase.value = "strategize"
self.state = MagicMock()
self.state.value = "queued"
def _build_mock_plan_lifecycle_service() -> MagicMock:
svc = MagicMock()
svc.use_action.return_value = _MockPlan()
svc.execute_plan.return_value = _MockPlan()
svc.get_plan.return_value = _MockPlan()
svc.apply_plan.return_value = _MockPlan()
return svc
# ---------------------------------------------------------------------------
# Given steps
# ---------------------------------------------------------------------------
@given(r"a coverage-boost facade with a mock PlanLifecycleService")
def step_cb_facade_plan(context: Context) -> None:
context.cb_facade = A2aLocalFacade(
services={"plan_lifecycle_service": _build_mock_plan_lifecycle_service()}
)
# ---------------------------------------------------------------------------
# When steps
# ---------------------------------------------------------------------------
@when(r"I try to create an A2aLocalFacade with a non-dict services argument")
def step_cb_create_facade_non_dict(context: Context) -> None:
context.cb_caught_error = None
try:
A2aLocalFacade(services=["not", "a", "dict"]) # type: ignore[arg-type]
except TypeError as exc:
context.cb_caught_error = exc
@when(
r'I dispatch coverage-boost operation "(?P<operation>[^"]+)" '
r"with params (?P<params_json>.+)"
)
def step_cb_dispatch(context: Context, operation: str, params_json: str) -> None:
params: dict[str, Any] = json.loads(params_json)
request = A2aRequest(operation=operation, params=params)
context.cb_response = context.cb_facade.dispatch(request)
# ---------------------------------------------------------------------------
# Then steps
# ---------------------------------------------------------------------------
@then(r'a TypeError should be raised with message "(?P<msg>[^"]+)"')
def step_cb_type_error_raised(context: Context, msg: str) -> None:
assert isinstance(context.cb_caught_error, TypeError), (
f"Expected TypeError, got {type(context.cb_caught_error)}"
)
assert msg in str(context.cb_caught_error), (
f"Expected message containing '{msg}', got '{context.cb_caught_error}'"
)
@then(r'the coverage-boost response status should be "(?P<status>[^"]+)"')
def step_cb_response_status(context: Context, status: str) -> None:
assert context.cb_response.status == status, (
f"Expected '{status}', got '{context.cb_response.status}'"
)
@then(r'the coverage-boost response error code should be "(?P<code>[^"]+)"')
def step_cb_error_code(context: Context, code: str) -> None:
assert context.cb_response.error is not None, "No error in response"
assert context.cb_response.error.code == code, (
f"Expected error code '{code}', got '{context.cb_response.error.code}'"
)
@then(r'the coverage-boost response error message should contain "(?P<fragment>[^"]+)"')
def step_cb_error_message_contains(context: Context, fragment: str) -> None:
assert context.cb_response.error is not None, "No error in response"
assert fragment in context.cb_response.error.message, (
f"Expected message containing '{fragment}', "
f"got '{context.cb_response.error.message}'"
)