@mock_only
Feature: Plan CLI coverage round 3
  Exercise uncovered lines in cleveragents/cli/commands/plan.py that are
  not yet hit by existing test suites.  Each scenario uses the "plcov3"
  step prefix to avoid Behave AmbiguousStep collisions.

  # ── validate_namespaced_actor (lines 104, 107-108) ──────────────

  Scenario: validate_namespaced_actor rejects invalid actor name
    Given a plcov3 CLI runner
    When I plcov3 call validate_namespaced_actor with value "BAD_NAME" and flag "--strategy-actor"
    Then the plcov3 error should be a ValidationError with message containing "namespace/name"

  Scenario: validate_namespaced_actor accepts valid actor name
    Given a plcov3 CLI runner
    When I plcov3 call validate_namespaced_actor with value "openai/gpt-4" and flag "--strategy-actor"
    Then the plcov3 result should equal "openai/gpt-4"

  # ── _plan_spec_dict with execution_environment (line 184) ───────

  Scenario: _plan_spec_dict includes execution_environment when set
    Given a plcov3 CLI runner
    And a plcov3 v3 plan with execution_environment "container"
    When I plcov3 call _plan_spec_dict
    Then the plcov3 spec dict should contain key "execution_environment" with value "container"

  # ── apply command v3 path with plan_id (lines 799-824) ─────────

  Scenario: apply command with plan_id delegates to v3 lifecycle
    Given a plcov3 CLI runner
    And a plcov3 mocked lifecycle service for apply happy path
    When I plcov3 invoke apply with plan_id "01ARZ3NDEKTSV4RRFFQ69G5FAA"
    Then the plcov3 CLI exit code should be 0

  # ── apply command no eligible plans path ─────────────────────────

  Scenario: apply command legacy path with pending changes
    Given a plcov3 CLI runner
    And a plcov3 mocked lifecycle service with no eligible apply plans
    When I plcov3 invoke apply without plan_id
    Then the plcov3 CLI output should contain "No plans ready for apply"

  Scenario: apply command legacy path with no pending changes
    Given a plcov3 CLI runner
    And a plcov3 mocked lifecycle service with no eligible apply plans
    When I plcov3 invoke apply without plan_id
    Then the plcov3 CLI output should contain "No plans ready for apply"

  # ── use_action with strategy_actor (lines 1529-1542, 1631-1633, 1751-1752) ─

  Scenario: use command with strategy-actor override
    Given a plcov3 CLI runner
    And a plcov3 mocked use_action environment
    When I plcov3 invoke use with action "local/test" and strategy-actor "openai/gpt-4"
    Then the plcov3 CLI exit code should be 0

  # ── use_action with execution_env_priority valid (lines 1789-1792) ──

  Scenario: use command with valid execution-env-priority
    Given a plcov3 CLI runner
    And a plcov3 mocked use_action environment
    When I plcov3 invoke use with action "local/test" and execution-environment "host" and priority "fallback"
    Then the plcov3 CLI exit code should be 0

  # ── use_action with invalid execution_env_priority (line 1794) ──

  Scenario: use command with invalid execution-env-priority
    Given a plcov3 CLI runner
    And a plcov3 mocked use_action environment
    When I plcov3 invoke use with action "local/test" and execution-environment "host" and priority "INVALID"
    Then the plcov3 CLI output should contain "Invalid execution env priority"

  # ── plan diff command (lines 2740-2741, 2743) ──────────────────

  Scenario: diff command invokes apply service
    Given a plcov3 CLI runner
    And a plcov3 mocked apply service for diff
    When I plcov3 invoke diff with plan_id "PLAN-001"
    Then the plcov3 CLI exit code should be 0

  # ── correct_decision ValidationError handler (lines 3047-3048) ──

  Scenario: correct command handles ValidationError
    Given a plcov3 CLI runner
    And a plcov3 mocked correction environment that raises ValidationError
    When I plcov3 invoke correct with identifier "DEC-001" mode "revert" guidance "fix it"
    Then the plcov3 CLI output should contain "Validation Error"

  # ── correct_decision CleverAgentsError handler (line 3051) ──────

  Scenario: correct command handles CleverAgentsError
    Given a plcov3 CLI runner
    And a plcov3 mocked correction environment that raises CleverAgentsError
    When I plcov3 invoke correct with identifier "DEC-001" mode "revert" guidance "fix it"
    Then the plcov3 CLI output should contain "Error"
