Feature: Plan lifecycle persistence via repositories
  The PlanLifecycleService persists actions and plans via
  ActionRepository and LifecyclePlanRepository (via UnitOfWork)
  instead of relying solely on in-memory maps.

  Background:
    Given a persisted plan lifecycle service backed by SQLite

  Scenario: Create action via service persists to DB
    When I create a persisted action "local/persist-act" with definition "All tests pass"
    Then the action "local/persist-act" should be retrievable from a fresh DB session

  Scenario: Create plan via use_action persists to DB
    Given a persisted action "local/plan-persist" exists
    When I use the persisted action "local/plan-persist" to create a plan
    Then the plan should be retrievable from a fresh DB session

  Scenario: Phase transition strategize to execute persists
    Given a persisted plan in strategize-complete state
    When I execute the persisted plan
    Then the persisted plan phase should be "execute"
    And the persisted plan processing state should be "queued"

  Scenario: Phase transition execute to apply persists
    Given a persisted plan in execute-complete state
    When I apply the persisted plan
    Then the persisted plan phase should be "apply"
    And the persisted plan processing state should be "queued"

  Scenario: List plans from DB matches in-memory
    Given a persisted action "local/list-act" exists
    When I use the persisted action "local/list-act" to create a plan
    Then listing plans should return 1 plan

  Scenario: Duplicate action name rejected by persistence layer
    Given a persisted action "local/dup-action" exists
    When I try to create another persisted action "local/dup-action"
    Then the duplicate action creation should fail with an error

  Scenario: Missing action error surfaced clearly
    When I try to use a non-existent persisted action "local/no-such-action"
    Then the missing action error should mention "local/no-such-action"
