Feature: Plan CLI cancel, revert, and list rich coverage
  As a developer
  I want to exercise the uncovered cancel_plan, revert_plan,
  and list_plans rich table rendering paths
  So that coverage for plan.py lines 1817, 1821-1822, 1845-1855, 1878-1888 is achieved

  Background:
    Given a CLI runner for cancel-revert coverage
    And a mocked lifecycle service for cancel-revert coverage

  # ---------- list rich table rendering (lines 1817, 1820-1822) ----------

  Scenario: list in rich format renders created_at timestamp
    Given the service returns plans with project links and timestamps for rich list
    When I invoke list in rich format for cancel-revert coverage
    Then the cancel-revert command should succeed
    And the cancel-revert output should contain "Plans"

  Scenario: list in rich format renders automation profile column
    Given the service returns plans with an automation profile for rich list
    When I invoke list in rich format for cancel-revert coverage
    Then the cancel-revert command should succeed
    And the cancel-revert output should contain "Plans"

  Scenario: list in rich format renders multiple project links
    Given the service returns a plan with three project links for rich list
    When I invoke list in rich format for cancel-revert coverage
    Then the cancel-revert command should succeed
    And the cancel-revert output should contain "more"

  Scenario: list in rich format renders invariant count
    Given the service returns plans with invariants for rich list
    When I invoke list in rich format for cancel-revert coverage
    Then the cancel-revert command should succeed

  # ---------- cancel_plan (lines 1845-1855) ----------

  Scenario: cancel_plan succeeds in rich format without reason
    Given the service can cancel a plan for cancel-revert coverage
    When I invoke cancel in rich format without reason for cancel-revert coverage
    Then the cancel-revert command should succeed
    And the cancel-revert output should contain "Plan cancelled"

  Scenario: cancel_plan succeeds in rich format with reason
    Given the service can cancel a plan for cancel-revert coverage
    When I invoke cancel in rich format with reason "no longer needed" for cancel-revert coverage
    Then the cancel-revert command should succeed
    And the cancel-revert output should contain "Plan cancelled"
    And the cancel-revert output should contain "no longer needed"

  Scenario: cancel_plan succeeds in JSON format without reason
    Given the service can cancel a plan for cancel-revert coverage
    When I invoke cancel with format "json" and no reason for cancel-revert coverage
    Then the cancel-revert command should succeed
    And the cancel-revert output should contain "plan_id"
    And the cancel-revert output should not contain "cancel_reason"

  Scenario: cancel_plan succeeds in JSON format with reason
    Given the service can cancel a plan for cancel-revert coverage
    When I invoke cancel with format "json" and reason "obsolete" for cancel-revert coverage
    Then the cancel-revert command should succeed
    And the cancel-revert output should contain "cancel_reason"
    And the cancel-revert output should contain "obsolete"

  # ---------- revert_plan (lines 1878-1888) ----------

  Scenario: revert_plan succeeds in rich format with default phase
    Given the service can revert a plan for cancel-revert coverage
    When I invoke revert in rich format with default phase for cancel-revert coverage
    Then the cancel-revert command should succeed
    And the cancel-revert output should contain "Plan Reverted"
    And the cancel-revert output should contain "Reversion count"

  Scenario: revert_plan succeeds in rich format with reason
    Given the service can revert a plan for cancel-revert coverage
    When I invoke revert in rich format with reason "constraints too strict" for cancel-revert coverage
    Then the cancel-revert command should succeed
    And the cancel-revert output should contain "Plan Reverted"

  Scenario: revert_plan succeeds in JSON format
    Given the service can revert a plan for cancel-revert coverage
    When I invoke revert with format "json" for cancel-revert coverage
    Then the cancel-revert command should succeed
    And the cancel-revert output should contain "plan_id"
    And the cancel-revert output should contain "reversion_reason"

  Scenario: revert_plan rejects invalid phase
    Given the service can revert a plan for cancel-revert coverage
    When I invoke revert with invalid phase "bogus" for cancel-revert coverage
    Then the cancel-revert command should abort
    And the cancel-revert output should contain "Invalid phase"
