@tdd_issue @tdd_issue_4328
Feature: Automation Profile Gates - Issue #4328 Regression Tests
  Regression tests for manual automation profile being disrespected during phase
  completion. Verifies that complete_strategize() and complete_execute() respect
  automation profile gates and do NOT auto-progress when thresholds are 1.0.

  Background:
    Given I have a plan lifecycle service with automation level support

  # ========================================================================
  # Issue #4328: Manual profile (all thresholds = 1.0) should NOT auto-progress
  # These scenarios verify the fix - that complete_strategize/execute do NOT
  # unconditionally call auto_progress()
  # ========================================================================

  Scenario: Manual profile create_tool=1.0 blocks strategize to execute transition
    Given I have a plan with automation level "manual" in strategize phase with processing state
    When I complete strategize on the automated plan
    Then the automated plan phase should be "strategize"
    And the automated plan processing state should be "complete"
    And should_auto_progress should return false

  Scenario: Manual profile select_tool=1.0 blocks execute to apply transition
    Given I have a plan with automation level "manual" in execute phase with processing state
    When I complete execute on the automated plan
    Then the automated plan phase should be "execute"
    And the automated plan processing state should be "complete"
    And should_auto_progress should return false

  # ========================================================================
  # Verify auto_progress() IS called when should_auto_progress() returns true
  # ========================================================================

  Scenario: Full-auto profile create_tool=0.0 allows strategize to execute auto-progress
    Given I have a plan with automation level "full_automation" in strategize phase with processing state
    When I complete strategize on the automated plan
    Then the automated plan phase should be "execute"
    And the automated plan processing state should be "queued"

  Scenario: Full-auto profile select_tool=0.0 allows execute to apply auto-progress
    Given I have a plan with automation level "full_automation" in execute phase with processing state
    When I complete execute on the automated plan
    Then the automated plan phase should be "apply"
    And the automated plan processing state should be "applied"

  # ========================================================================
  # Supervised profile: create_tool=1.0 (blocks execute), select_tool=1.0 (blocks apply)
  # ========================================================================

  Scenario: Supervised profile create_tool=1.0 blocks strategize to execute auto-progress
    Given I have a plan with automation level "supervised" in strategize phase with processing state
    When I complete strategize on the automated plan
    Then the automated plan phase should be "strategize"
    And the automated plan processing state should be "complete"
    And should_auto_progress should return false

  Scenario: Supervised profile select_tool=1.0 blocks execute to apply transition
    Given I have a plan with automation level "supervised" in execute phase with processing state
    When I complete execute on the automated plan
    Then the automated plan phase should be "execute"
    And the automated plan processing state should be "complete"
    And should_auto_progress should return false

  # ========================================================================
  # Review-before-apply (auto) profile: create_tool=0.0, select_tool=1.0
  # ========================================================================

  Scenario: Auto profile create_tool=0.0 allows strategize to execute auto-progress
    Given I have a plan with automation level "review_before_apply" in strategize phase with processing state
    When I complete strategize on the automated plan
    Then the automated plan phase should be "execute"
    And the automated plan processing state should be "queued"

  Scenario: Auto profile select_tool=1.0 blocks execute to apply transition
    Given I have a plan with automation level "review_before_apply" in execute phase with processing state
    When I complete execute on the automated plan
    Then the automated plan phase should be "execute"
    And the automated plan processing state should be "complete"
    And should_auto_progress should return false

  # ========================================================================
  # CI profile: all thresholds=0.0 (auto-progresses everything)
  # ========================================================================

  Scenario: CI profile blocks neither strategize nor execute transitions
    Given I have a plan with automation level "ci" in strategize phase with processing state
    When I complete strategize on the automated plan
    Then the automated plan phase should be "execute"
    And the automated plan processing state should be "queued"

  Scenario: CI profile execute phase auto-progresses to apply
    Given I have a plan with automation level "ci" in execute phase with processing state
    When I complete execute on the automated plan
    Then the automated plan phase should be "apply"
    And the automated plan processing state should be "applied"

  # ========================================================================
  # Trusted profile: create_tool=0.0, select_tool=1.0 (same as auto for strategize/execute)
  # ========================================================================

  Scenario: Trusted profile allows strategize to execute auto-progress
    Given I have a plan with automation level "trusted" in strategize phase with processing state
    When I complete strategize on the automated plan
    Then the automated plan phase should be "execute"
    And the automated plan processing state should be "queued"

  Scenario: Trusted profile select_tool=1.0 blocks execute to apply transition
    Given I have a plan with automation level "trusted" in execute phase with processing state
    When I complete execute on the automated plan
    Then the automated plan phase should be "execute"
    And the automated plan processing state should be "complete"
    And should_auto_progress should return false

  # ========================================================================
  # Cautious profile: intermediate thresholds (0.0 < v < 1.0)
  # Tests the spec's Threshold Semantics for probabilistic gates:
  # "0.0 < v < 1.0 → system may proceed if confidence >= threshold"
  # With default confidence=0.5, thresholds > 0.5 should block.
  # ========================================================================

  Scenario: Cautious profile create_tool=0.7 blocks strategize to execute with default confidence
    Given I have a plan with automation level "cautious" in strategize phase with complete state for query
    Then should_auto_progress should return false

  Scenario: Cautious profile select_tool=1.0 blocks execute to apply transition
    Given I have a plan with automation level "cautious" in execute phase with complete state for query
    Then should_auto_progress should return false
