Feature: M4 correction and subplan lifecycle smoke tests
  As a developer working with the CleverAgents M4 milestone
  I want to verify correction flows and subplan execution end-to-end
  So that decision tree corrections and parallel subplan merges work correctly

  Background:
    Given a m4 smoke test runner
    And a m4 smoke mocked lifecycle service

  # --- Fixture loading ---

  Scenario: M4 smoke load correction flows fixture
    When I m4 smoke load the correction flows fixture
    Then the m4 smoke correction fixture should have a revert entry
    And the m4 smoke correction fixture should have an append entry

  Scenario: M4 smoke load subplan execution fixture
    When I m4 smoke load the subplan execution fixture
    Then the m4 smoke subplan fixture should have a sequential entry
    And the m4 smoke subplan fixture should have a parallel entry

  Scenario: M4 smoke load conflict simulations fixture
    When I m4 smoke load the conflict simulations fixture
    Then the m4 smoke conflict fixture should have a no-conflict entry
    And the m4 smoke conflict fixture should have a conflict entry

  # --- Correction flows ---

  Scenario: M4 smoke correction revert via CLI
    Given a m4 smoke plan exists with a decision tree
    When I m4 smoke invoke plan correct with mode "revert" and guidance "Use FastAPI instead"
    Then the m4 smoke correction should succeed
    And the m4 smoke output should contain "revert"

  Scenario: M4 smoke correction append via CLI
    Given a m4 smoke plan exists with a decision tree
    When I m4 smoke invoke plan correct with mode "append" and guidance "Add caching layer"
    Then the m4 smoke correction should succeed
    And the m4 smoke output should contain "applied"

  Scenario: M4 smoke correction dry-run shows impact
    Given a m4 smoke plan exists with a decision tree
    When I m4 smoke invoke plan correct with dry-run
    Then the m4 smoke correction should succeed
    And the m4 smoke output should contain "impact"

  Scenario: M4 smoke correction with invalid mode fails
    Given a m4 smoke plan exists with a decision tree
    When I m4 smoke invoke plan correct with mode "invalid-mode" and guidance "test"
    Then the m4 smoke correction should fail

  # --- Subplan execution ---

  Scenario: M4 smoke subplan sequential execution
    Given a m4 smoke parent plan with sequential subplan config
    When I m4 smoke invoke plan status for the parent
    Then the m4 smoke status should succeed
    And the m4 smoke output should contain "plan_id"

  Scenario: M4 smoke subplan parallel execution with merge
    Given a m4 smoke parent plan with parallel subplan config
    When I m4 smoke invoke plan status for the parent
    Then the m4 smoke status should succeed
    And the m4 smoke output should contain "plan_id"

  Scenario: M4 smoke subplan failure handler stop-others
    Given a m4 smoke subplan config with fail-fast enabled
    When I m4 smoke evaluate failure handler should-stop-others
    Then the m4 smoke failure handler should return true for stop-others

  Scenario: M4 smoke subplan failure handler retry retriable
    Given a m4 smoke subplan config with retry enabled
    And a m4 smoke subplan status with retriable error "ValidationError"
    When I m4 smoke evaluate failure handler should-retry
    Then the m4 smoke failure handler should return true for retry

  Scenario: M4 smoke subplan failure handler skip non-retriable
    Given a m4 smoke subplan config with retry enabled
    And a m4 smoke subplan status with non-retriable error "ConfigurationError"
    When I m4 smoke evaluate failure handler should-retry
    Then the m4 smoke failure handler should return false for retry

  # --- Conflict simulations ---

  Scenario: M4 smoke merge strategy git-three-way no conflict
    Given a m4 smoke conflict fixture with strategy "git_three_way" and no overlap
    Then the m4 smoke conflict fixture should expect no conflict

  Scenario: M4 smoke merge strategy fail-on-conflict detects overlap
    Given a m4 smoke conflict fixture with strategy "fail_on_conflict" and overlap
    Then the m4 smoke conflict fixture should expect a conflict
    And the m4 smoke conflict fixture should expect error "MergeConflictError"

  Scenario: M4 smoke merge strategy last-wins resolves overlap
    Given a m4 smoke conflict fixture with strategy "last_wins" and overlap
    Then the m4 smoke conflict fixture should expect no conflict
    And the m4 smoke conflict fixture should expect result "last_wins_applied"

  # --- Negative cases ---

  Scenario: M4 smoke correction on non-existent plan fails
    When I m4 smoke invoke plan correct on non-existent plan
    Then the m4 smoke correction should fail

  Scenario: M4 smoke correction with empty decision ID fails
    When I m4 smoke invoke plan correct with empty decision id
    Then the m4 smoke correction should fail
