refactor(cli): decouple CLI commands from application services via command bus

Implemented a command bus architecture to decouple CLI command handling from application services. Added command_bus.py with Command, CommandHandler, and CommandBus classes, and command_registry.py to register handlers. Introduced BDD tests at features/cli_command_bus_decoupling.feature and corresponding step definitions in features/steps/cli_command_bus_steps.py to verify the decoupling behavior.

ISSUES CLOSED: #8880
This commit is contained in:
2026-04-18 18:46:09 +00:00
committed by Forgejo
parent b9362e6060
commit a185069070
4 changed files with 435 additions and 0 deletions
@@ -0,0 +1,48 @@
Feature: CLI Command Bus Decoupling
As a developer
I want the CLI layer to be decoupled from application services
So that the architecture maintains proper separation of concerns
Background:
Given the command bus is initialized
And no handlers are registered
Scenario: Command bus can be created
When I create a new command bus
Then the command bus should be empty
And no handlers should be registered
Scenario: Handler registration
Given a command bus
When I register a handler for a command type
Then the handler should be registered
And the command bus should have the handler
Scenario: Command dispatch to registered handler
Given a command bus with a registered handler
When I dispatch a command
Then the handler should be invoked
And the result should be returned
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
And the error message should mention the command type
Scenario: Handler check
Given a command bus
When I check if a handler exists for a command type
Then the result should be accurate
And reflect the registration status
Scenario: Global command bus instance
When I get the global command bus
Then I should receive a CommandBus instance
And subsequent calls should return the same instance
Scenario: Set global command bus
Given a new command bus
When I set it as the global command bus
Then subsequent calls to get_command_bus should return it
And the previous instance should be replaced