Skip to content

Refactor ConfigureCommandHandler to Use EnvironmentName Instead of Environment<Provisioned> #178

Closed

Description

@josecelano

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

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::Error for domain errors

Implementation Plan

Phase 1: Update Command Handler Signature (estimated: 30 minutes)

  • Update ConfigureCommandHandler::execute signature to accept &EnvironmentName
  • Add environment loading logic at the start of execute method
  • Add state verification logic (downcast to Provisioned state)
  • Update error handling to include new error variants
  • Ensure instrumentation and logging reflect new signature

Phase 2: Update Error Types (estimated: 15 minutes)

  • Add EnvironmentNotFound error variant to ConfigureCommandHandlerError
  • Add InvalidEnvironmentState error 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 use ConfigureCommandHandler
  • 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::execute accepts &EnvironmentName as 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

Activity

  1. changed the title [-]Refactor ConfigureCommandHandler to Use EnvironmentName Instead of Environment&lt;Provisioned&gt;[/-] [+]Refactor `ConfigureCommandHandler` to Use `EnvironmentName` Instead of `Environment<Provisioned>`[/+] on Nov 18, 2025
  2. self-assigned this
    on Nov 18, 2025
  3. added 2 commits that reference this issue on Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions