Feature: Fix-then-Revalidate orchestration loop
  As an execution actor
  I want a bounded retry loop that diagnoses, fixes, and re-validates
  So that recoverable validation failures are resolved automatically

  Background:
    Given a fix-revalidate orchestrator with max_retries 3

  # Happy path: first fix attempt resolves the validation failure
  Scenario: Fix succeeds on first attempt
    Given a required validation "check-syntax" that fails initially
    And a fix callback that always succeeds
    And a revalidate callback that passes after 1 fix
    When the fix-revalidate loop runs for plan "PLAN001"
    Then the fix-revalidate result should have validation_attempts 1
    And the fix-revalidate result should have final_passed True
    And the fix-revalidate result should not be escalated
    And the fix-revalidate result should not be terminal failure

  # Multiple attempts needed before the fix works
  Scenario: Fix succeeds after multiple attempts
    Given a required validation "check-lint" that fails initially
    And a fix callback that always succeeds
    And a revalidate callback that passes after 2 fixes
    When the fix-revalidate loop runs for plan "PLAN002"
    Then the fix-revalidate result should have validation_attempts 2
    And the fix-revalidate result should have final_passed True
    And the validation fix history should have 2 records

  # Retry limit reached, auto_strategy_revision triggers escalation
  Scenario: Retry limit exhausted with strategy revision
    Given a fix-revalidate orchestrator with auto_strategy_revision enabled
    And a required validation "check-security" that fails initially
    And a fix callback that always succeeds
    And a revalidate callback that never passes
    When the fix-revalidate loop runs for plan "PLAN003"
    Then the fix-revalidate result should have final_passed False
    And the fix-revalidate result should be escalated
    And the fix-revalidate result should not be terminal failure
    And the fix-revalidate result should have validation_attempts 3

  # Terminal failure when all attempts fail and no strategy revision
  Scenario: Terminal failure when all attempts fail
    Given a required validation "check-deploy" that fails initially
    And a fix callback that always succeeds
    And a revalidate callback that never passes
    When the fix-revalidate loop runs for plan "PLAN004"
    Then the fix-revalidate result should have final_passed False
    And the fix-revalidate result should need user escalation
    And the fix-revalidate result should not be terminal failure
    And the validation fix history should have 3 records

  # Informational validations do not trigger the fix loop
  Scenario: Informational validations do not trigger fix loop
    Given an informational validation "check-style" that fails
    And a fix callback that always succeeds
    And a revalidate callback that passes after 1 fix
    When the fix-revalidate loop runs for plan "PLAN005"
    Then the fix-revalidate result should have validation_attempts 0
    And the fix-revalidate result should have final_passed True
    And the validation fix history should have 0 records
