Repository navigation
Description
Overview
Refactor the ConfigureCommandHandler in the Application layer to accept EnvironmentName instead of Environment<Provisioned> as its input parameter. This change aligns the configure command handler with the provision command handler's interface pattern, simplifying the implementation of presentation layer controllers by reducing the number of Application layer dependencies that need to be constructed.
This is a preparatory refactor required before implementing the configure console subcommand in the presentation layer.
Specification
See detailed specification: docs/issues/178-refactor-configure-command-handler-to-use-environment-name.md
🏗️ Architecture Requirements
DDD Layer: Application
Module Path: src/application/command_handlers/configure/
Pattern: Command Handler
Module Structure Requirements
- Follow DDD layer separation (see docs/codebase-architecture.md)
- Respect dependency flow rules (Application layer can depend on Domain and Infrastructure)
- Use appropriate module organization (see docs/contributing/module-organization.md)
Architectural Constraints
- Command handler must handle environment loading and state verification internally
- Error handling follows project conventions (see docs/contributing/error-handling.md)
- Must return explicit enum errors (not
anyhow::Error) for better pattern matching - Errors must be actionable with specific fix instructions
- Maintain type-state pattern for environment lifecycle management
Anti-Patterns to Avoid
- ❌ Passing complex Application layer types through presentation layer
- ❌ Forcing presentation layer to handle Application layer concerns
- ❌ Using
anyhow::Errorfor domain errors
Implementation Plan
Phase 1: Update Command Handler Signature (estimated: 30 minutes)
- Update
ConfigureCommandHandler::executesignature to accept&EnvironmentName - Add environment loading logic at the start of
executemethod - Add state verification logic (downcast to
Provisionedstate) - Update error handling to include new error variants
- Ensure instrumentation and logging reflect new signature
Phase 2: Update Error Types (estimated: 15 minutes)
- Add
EnvironmentNotFounderror variant toConfigureCommandHandlerError - Add
InvalidEnvironmentStateerror variant with detailed state information - Ensure error messages are actionable and user-friendly
- Add context to errors for traceability
Phase 3: Update Unit Tests (estimated: 30 minutes)
- Update unit tests in
src/application/command_handlers/configure/handler.rs - Add test cases for environment not found scenario
- Add test cases for invalid environment state
- Verify error messages are clear and actionable
Phase 4: Update Integration Tests (estimated: 30 minutes)
- Update E2E tests in
tests/directory that useConfigureCommandHandler - Update test fixtures if needed
- Verify all tests pass with new signature
Phase 5: Update Documentation (estimated: 15 minutes)
- Update command handler documentation comments
- Update any relevant guides in
docs/directory - Update examples if they reference the old signature
Acceptance Criteria
Note for Contributors: These criteria define what the PR reviewer will check. Use this as your pre-review checklist before submitting the PR to minimize back-and-forth iterations.
Quality Checks:
- Pre-commit checks pass:
./scripts/pre-commit.sh
Functional Requirements:
-
ConfigureCommandHandler::executeaccepts&EnvironmentNameas parameter - Environment loading is handled internally by the command handler
- State verification (Provisioned state) is handled internally
- Appropriate errors are returned for environment not found and wrong state
- Error messages are clear, actionable, and follow project conventions
- Type-state pattern is preserved (Environment<Provisioned> → Environment<Configured>)
Code Quality:
- Follows the pattern established by
ProvisionCommandHandler - Maintains separation of concerns (Application vs Presentation layer)
- Error handling uses explicit enum types (not
anyhow::Error) - Code is well-documented with clear examples
- Instrumentation (
tracing) is properly configured
Testing:
- All existing unit tests updated and passing
- New test cases added for error scenarios
- Integration tests updated and passing
- E2E tests updated and passing
Documentation:
- Command handler documentation updated
- Method documentation includes examples
- Error variant documentation is clear and actionable
Related
- Parent: #TBD (Epic: Implement Configure Console Subcommand)
- Related: Implement Provision Console Command #174 (Provision Console Subcommand)
- Roadmap: Roadmap #1 (Project Roadmap)
- Specification: docs/issues/178-refactor-configure-command-handler-to-use-environment-name.md
Activity
[-]Refactor ConfigureCommandHandler to Use EnvironmentName Instead of Environment<Provisioned>[/-][+]Refactor `ConfigureCommandHandler` to Use `EnvironmentName` Instead of `Environment<Provisioned>`[/+]docs: add issue specification for ConfigureCommandHandler refactor
refactor: [#178] refactor ConfigureCommandHandler to use EnvironmentName
chore: remove completed issue spec #178