@database @migration @plan_phase_rebaseline
Feature: Plan phase/state constraint rebaseline
  As the system operator
  I want the v3_plans table to accept the Action phase and Apply terminal states
  So that plans can follow the four-phase lifecycle: Action -> Strategize -> Execute -> Apply

  Background:
    Given the plan phase rebaseline database is initialized

  Scenario: Phase constraint accepts 'action' phase
    When I insert a plan with phase "action" and state "queued"
    Then the plan should be persisted successfully with phase "action"

  Scenario: Phase constraint rejects 'applied' as a phase
    When I try to insert a plan with phase "applied" and state "queued"
    Then the insert should fail with a constraint violation

  Scenario: Processing state accepts 'applied' state
    When I insert a plan with phase "apply" and state "applied"
    Then the plan should be persisted successfully with state "applied"

  Scenario: Processing state accepts 'constrained' state
    When I insert a plan with phase "apply" and state "constrained"
    Then the plan should be persisted successfully with state "constrained"

  Scenario: Default phase is 'action'
    When I insert a plan using default phase
    Then the rebaselined plan phase should be "action"

  Scenario: Phase constraint rejects legacy 'applied' phase value
    When I try to insert a plan with phase "applied" and state "complete"
    Then the insert should fail with a constraint violation
