Feature: CLI Legacy Removal Coverage Boost
  As a developer working on CLI legacy removal
  I want comprehensive coverage of safe initialization and cleanup paths
  So that code coverage meets the 97% threshold

  Background:
    Given a clean test environment for CLI plan coverage

  # =============================================================================
  # Safe Initialization and Cleanup - Plan Envelope Building
  # =============================================================================

  Scenario: Build execute envelope with estimation result
    Given CLI plan command module is available for testing
    And a mock plan with estimation result for envelope testing
    When I build execute envelope for the mock plan
    Then the envelope contains estimation data
    And all test objects are properly cleaned up

  Scenario: Build execute envelope without estimation result
    Given CLI plan command module is available for testing
    And a mock plan without estimation result
    When I build execute envelope for plan without estimation
    Then the envelope contains default strategy summary
    And all test objects are properly cleaned up

  Scenario: Build execute envelope for legacy plan
    Given CLI plan command module is available for testing
    And a legacy plan object (not LifecyclePlan)
    When I build execute envelope for legacy plan
    Then the envelope contains legacy fallback data
    And all test objects are properly cleaned up

  # =============================================================================
  # Safe Initialization and Cleanup - Sandbox Cleanup
  # =============================================================================

  Scenario: Cleanup sandbox with empty plan ID
    Given CLI plan command module is available for testing
    And a mock PlanLifecycleService for cleanup testing
    When I call cleanup sandbox with empty plan ID
    Then cleanup completes without error for empty plan ID
    And all test objects are properly cleaned up

  Scenario: Cleanup sandbox with whitespace-only plan ID
    Given CLI plan command module is available for testing
    And a mock PlanLifecycleService for cleanup testing
    When I call cleanup sandbox with whitespace-only plan ID
    Then cleanup completes without error for whitespace plan ID
    And all test objects are properly cleaned up

  Scenario: Cleanup sandbox for non-existent plan
    Given CLI plan command module is available for testing
    And a mock PlanLifecycleService for cleanup testing
    When I call cleanup sandbox for non-existent plan
    Then cleanup completes without error for non-existent plan
    And all test objects are properly cleaned up

  # =============================================================================
  # Safe Initialization and Cleanup - Project Retrieval
  # =============================================================================

  Scenario: Get current project when no project exists
    Given CLI plan command module is available for testing
    And the container returns no current project
    When I attempt to get current project
    Then typer Abort is raised
    And all test objects are properly cleaned up

  # =============================================================================
  # Safe Initialization and Cleanup - Status Building
  # =============================================================================

  Scenario: Build status result with validation summary
    Given CLI plan command module is available for testing
    And a mock plan with validation summary
    When I build status result for plan with validation
    Then the status contains DoD evaluation data
    And all test objects are properly cleaned up

  Scenario: Build status result with error message
    Given CLI plan command module is available for testing
    And a mock plan with error message
    When I build status result for plan with error
    Then the status contains error message
    And all test objects are properly cleaned up

  Scenario: Build status result with step information
    Given CLI plan command module is available for testing
    And a mock plan with last completed step
    When I build status result for plan with step info
    Then the status contains last completed step
    And all test objects are properly cleaned up

  # =============================================================================
  # Safe Initialization and Cleanup - Plan Display
  # =============================================================================

  Scenario: Print lifecycle plan with project links
    Given CLI plan command module is available for testing
    And a mock lifecycle plan with project links
    When I print lifecycle plan with project links
    Then the output contains project link with alias
    And the output contains read-only indicator
    And all test objects are properly cleaned up

  Scenario: Print lifecycle plan for legacy plan
    Given CLI plan command module is available for testing
    And a legacy plan object (not LifecyclePlan)
    When I print lifecycle plan details for legacy plan
    Then the legacy plan is displayed in a panel
    And all test objects are properly cleaned up

  # =============================================================================
  # Safe Initialization and Cleanup - Progress Status
  # =============================================================================

  Scenario: Progress steps show error for errored plan
    Given CLI plan command module is available for testing
    And a mock plan in errored state
    When I build execute envelope for errored plan
    Then the progress shows error status for first step
    And all test objects are properly cleaned up

  Scenario: Progress steps show complete for applied plan
    Given CLI plan command module is available for testing
    And a mock plan in completed state
    When I build execute envelope for completed plan
    Then all progress steps show complete status
    And all test objects are properly cleaned up
