Feature: Plan CLI uncovered region coverage (lines 1950-2273)
  As a developer
  I want targeted tests for the uncovered lines and branches in plan.py
  So that coverage gaps at lines 1950-1954, 1956-1957, 2132, 2135-2143,
  2146-2184, 2202-2233, and 2231-2273 are closed

  # ===================================================================
  # list_plans — empty result after filtering (lines 1950-1954)
  # ===================================================================

  Scenario: uncov-rgn list shows "No plans found" when action filter excludes all
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn lifecycle service returns plans that do not match an action filter
    When I uncov-rgn invoke list with action filter "nonexistent/action"
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "No plans found"

  # ===================================================================
  # list_plans — non-rich format output (lines 1956-1957)
  # ===================================================================

  Scenario: uncov-rgn list outputs JSON when format is json
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn lifecycle service returns a single plan for listing
    When I uncov-rgn invoke list with format "json"
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "plan_id"

  Scenario: uncov-rgn list outputs YAML when format is yaml
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn lifecycle service returns a single plan for listing
    When I uncov-rgn invoke list with format "yaml"
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "plan_id"

  # ===================================================================
  # revert_plan — CleverAgentsError handler (line 2132)
  # ===================================================================

  Scenario: uncov-rgn revert_plan raises CleverAgentsError
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn lifecycle service revert raises CleverAgentsError
    When I uncov-rgn invoke revert for plan "01ARZ3NDEKTSV4RRFFQ69G5FAA"
    Then the uncov-rgn command should abort
    And the uncov-rgn output should contain "Error"

  # ===================================================================
  # _get_apply_service — function body (lines 2136-2143)
  # ===================================================================

  Scenario: uncov-rgn _get_apply_service creates a PlanApplyService instance
    Given an uncov-rgn mocked lifecycle service for apply service creation
    When I uncov-rgn call _get_apply_service directly
    Then the uncov-rgn apply service should be returned successfully

  # ===================================================================
  # plan_diff — correction parameter branch (lines 2149-2184)
  # ===================================================================

  Scenario: uncov-rgn plan diff with correction flag shows stub panel
    Given an uncov-rgn CLI runner and mocked lifecycle service
    When I uncov-rgn invoke diff for plan "PLAN-001" with correction "CORR-001"
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "Correction Attempt"
    And the uncov-rgn output should contain "CORR-001"

  Scenario: uncov-rgn plan diff without correction calls apply service
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn apply service diff returns formatted output "--- a/main.py"
    When I uncov-rgn invoke diff for plan "PLAN-002" without correction
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "main.py"

  Scenario: uncov-rgn plan diff raises PlanError
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn apply service diff raises PlanError "missing changeset"
    When I uncov-rgn invoke diff for plan "PLAN-003" without correction
    Then the uncov-rgn command should abort
    And the uncov-rgn output should contain "Diff Error"

  Scenario: uncov-rgn plan diff raises CleverAgentsError
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn apply service diff raises CleverAgentsError "service down"
    When I uncov-rgn invoke diff for plan "PLAN-004" without correction
    Then the uncov-rgn command should abort
    And the uncov-rgn output should contain "Error"

  # ===================================================================
  # plan_artifacts — full command coverage (lines 2202-2233)
  # ===================================================================

  Scenario: uncov-rgn plan artifacts success in rich format
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn apply service artifacts returns "changeset-id: cs-100"
    When I uncov-rgn invoke artifacts for plan "PLAN-005" in rich format
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "cs-100"

  Scenario: uncov-rgn plan artifacts success in json format
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn apply service artifacts returns '{"changeset": "cs-200"}'
    When I uncov-rgn invoke artifacts for plan "PLAN-006" with format "json"
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "cs-200"

  Scenario: uncov-rgn plan artifacts raises PlanError
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn apply service artifacts raises PlanError "no changeset"
    When I uncov-rgn invoke artifacts for plan "PLAN-007" in rich format
    Then the uncov-rgn command should abort
    And the uncov-rgn output should contain "Artifacts Error"

  Scenario: uncov-rgn plan artifacts raises CleverAgentsError
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn apply service artifacts raises CleverAgentsError "timeout"
    When I uncov-rgn invoke artifacts for plan "PLAN-008" in rich format
    Then the uncov-rgn command should abort
    And the uncov-rgn output should contain "Error"

  # ===================================================================
  # correct_decision — full command coverage (lines 2231-2273+)
  # ===================================================================

  Scenario: uncov-rgn correct revert with --yes succeeds in rich format
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn correction service returns a revert result with reverted decisions
    When I uncov-rgn invoke correct in revert mode with --yes and guidance "Use Flask instead"
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "Correction applied"
    And the uncov-rgn output should contain "Reverted"

  Scenario: uncov-rgn correct append with --yes succeeds in rich format
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn correction service returns an append result with new decisions
    When I uncov-rgn invoke correct in append mode with --yes and guidance "Add caching layer"
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "Correction applied"
    And the uncov-rgn output should contain "New decisions"

  Scenario: uncov-rgn correct revert with --yes succeeds in json format
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn correction service returns a revert result with reverted decisions
    When I uncov-rgn invoke correct in revert mode with --yes, format "json", and guidance "Refactor"
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "correction_id"
    And the uncov-rgn output should contain "reverted_decisions"

  Scenario: uncov-rgn correct dry-run in rich format shows impact panel
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn correction service returns an impact analysis
    When I uncov-rgn invoke correct in dry-run mode with rich format and guidance "Preview changes"
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "Correction Impact"
    And the uncov-rgn output should contain "Dry Run"

  Scenario: uncov-rgn correct dry-run in json format shows impact data
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn correction service returns an impact analysis
    When I uncov-rgn invoke correct in dry-run mode with format "json" and guidance "Check impact"
    Then the uncov-rgn command should exit normally
    And the uncov-rgn output should contain "correction_id"
    And the uncov-rgn output should contain "risk_level"

  Scenario: uncov-rgn correct raises ResourceNotFoundError
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn correction service request raises ResourceNotFoundError
    When I uncov-rgn invoke correct in revert mode with --yes and guidance "Fix something"
    Then the uncov-rgn command should abort
    And the uncov-rgn output should contain "Not found"

  Scenario: uncov-rgn correct raises ValidationError
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn correction service request raises ValidationError
    When I uncov-rgn invoke correct in revert mode with --yes and guidance "Validate me"
    Then the uncov-rgn command should abort
    And the uncov-rgn output should contain "Validation Error"

  Scenario: uncov-rgn correct raises CleverAgentsError
    Given an uncov-rgn CLI runner and mocked lifecycle service
    And the uncov-rgn correction service request raises CleverAgentsError
    When I uncov-rgn invoke correct in revert mode with --yes and guidance "General error"
    Then the uncov-rgn command should abort
    And the uncov-rgn output should contain "Error"

  Scenario: uncov-rgn correct with invalid mode aborts
    Given an uncov-rgn CLI runner and mocked lifecycle service
    When I uncov-rgn invoke correct with invalid mode "rollback" and guidance "test"
    Then the uncov-rgn command should abort
    And the uncov-rgn output should contain "Invalid mode"

  Scenario: uncov-rgn correct with empty guidance aborts
    Given an uncov-rgn CLI runner and mocked lifecycle service
    When I uncov-rgn invoke correct with valid mode "revert" and empty guidance
    Then the uncov-rgn command should abort
    And the uncov-rgn output should contain "guidance"
