fix(cli): resolve lint errors and step name conflict in command bus
CI / push-validation (pull_request) Successful in 33s
CI / helm (pull_request) Successful in 36s
CI / lint (pull_request) Successful in 44s
CI / quality (pull_request) Successful in 51s
CI / build (pull_request) Successful in 47s
CI / typecheck (pull_request) Successful in 1m10s
CI / security (pull_request) Successful in 1m27s
CI / unit_tests (pull_request) Successful in 6m15s
CI / docker (pull_request) Successful in 1m46s
CI / integration_tests (pull_request) Successful in 9m40s
CI / coverage (pull_request) Successful in 8m29s
CI / status-check (pull_request) Successful in 3s

- Replace deprecated typing imports (Dict, Callable, Generic) with
  collections.abc.Callable and built-in dict
- Convert Command from ABC to plain base class (B024: no abstract methods)
- Convert CommandHandler to PEP 695 type parameter syntax (UP046)
- Remove unused PlanService/ProjectService imports from command_registry
- Fix ruff format: blank line before nested defs in command_registry and steps
- Rename @then('a ValueError should be raised') to domain-specific suffix
  to avoid AmbiguousStep collision with lsp_registry_steps.py

ISSUES CLOSED: #8880
This commit is contained in:
2026-06-04 10:18:40 -04:00
committed by Forgejo
parent a185069070
commit 7ed9c1279f
4 changed files with 8 additions and 18 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ Feature: CLI Command Bus Decoupling
Scenario: Dispatch fails for unregistered command
Given a command bus with no handlers
When I dispatch a command without a registered handler
Then a ValueError should be raised
Then a ValueError should be raised for unregistered command dispatch
And the error message should mention the command type
Scenario: Handler check
+2 -1
View File
@@ -57,6 +57,7 @@ def step_given_command_bus(context):
@when("I register a handler for a command type")
def step_register_handler(context):
"""Register a handler for a command type."""
def handler(cmd: TestCommand) -> str:
return f"Handled: {cmd.value}"
@@ -124,7 +125,7 @@ def step_dispatch_unregistered(context):
context.error = e
@then("a ValueError should be raised")
@then("a ValueError should be raised for unregistered command dispatch")
def step_value_error_raised(context):
"""Verify a ValueError was raised."""
assert context.error_raised
+5 -8
View File
@@ -12,14 +12,11 @@ This ensures:
"""
from abc import ABC, abstractmethod
from typing import Any, Callable, Dict, Generic, TypeVar
# Type variables for command and result
TCommand = TypeVar("TCommand", bound="Command")
TResult = TypeVar("TResult")
from collections.abc import Callable
from typing import Any
class Command(ABC):
class Command:
"""Base class for all commands dispatched through the command bus.
Commands represent requests from the CLI layer to the application layer.
@@ -29,7 +26,7 @@ class Command(ABC):
pass
class CommandHandler(ABC, Generic[TCommand, TResult]):
class CommandHandler[TCommand: Command, TResult](ABC):
"""Base class for command handlers.
A handler processes a specific command type and returns a result.
@@ -61,7 +58,7 @@ class CommandBus:
def __init__(self) -> None:
"""Initialize the command bus with an empty handler registry."""
self._handlers: Dict[type, Callable[[Any], Any]] = {}
self._handlers: dict[type, Callable[[Any], Any]] = {}
def register_handler(
self, command_type: type, handler: Callable[[Any], Any]
-8
View File
@@ -21,14 +21,6 @@ def register_command_handlers(bus: "CommandBus") -> None:
Args:
bus: The CommandBus instance to register handlers with
"""
# Import handlers from application services
# This is the only place where CLI imports from application services
from cleveragents.application.services.plan_service import (
PlanService,
)
from cleveragents.application.services.project_service import (
ProjectService,
)
# Register handlers for plan commands
# These handlers wrap service calls and are registered with the bus