Feature: TUI Persona Cycling
  Personas can be cycled through in order using cycle_order field.

  Scenario: cycle_persona cycles through personas with cycle_order > 0
    Given a temporary TUI persona registry
    And I save TUI persona "first" with actor "local/mock-default" and cycle order 1
    And I save TUI persona "second" with actor "local/mock-default" and cycle order 2
    And I save TUI persona "third" with actor "local/mock-default" and cycle order 3
    When I set active persona to "first" for session "s1"
    And I cycle persona for session "s1"
    Then active persona for session "s1" should be "second"
    When I cycle persona for session "s1"
    Then active persona for session "s1" should be "third"
    When I cycle persona for session "s1"
    Then active persona for session "s1" should be "first"

  Scenario: cycle_persona returns current persona when no cyclic personas exist
    Given a temporary TUI persona registry
    And I save TUI persona "noncyclic" with actor "local/mock-default" and cycle order 0
    When I set active persona to "noncyclic" for session "s1"
    And I cycle persona for session "s1"
    Then active persona for session "s1" should be "noncyclic"

  Scenario: cycle_persona starts from first when current is not in cycle
    Given a temporary TUI persona registry
    And I save TUI persona "cyclic1" with actor "local/mock-default" and cycle order 1
    And I save TUI persona "noncyclic" with actor "local/mock-default" and cycle order 0
    When I set active persona to "noncyclic" for session "s1"
    And I cycle persona for session "s1"
    Then active persona for session "s1" should be "cyclic1"

  Scenario: cycle_persona respects cycle_order field ordering
    Given a temporary TUI persona registry
    And I save TUI persona "alpha" with actor "local/mock-default" and cycle order 3
    And I save TUI persona "beta" with actor "local/mock-default" and cycle order 1
    And I save TUI persona "gamma" with actor "local/mock-default" and cycle order 2
    When I set active persona to "beta" for session "s1"
    And I cycle persona for session "s1"
    Then active persona for session "s1" should be "gamma"
    When I cycle persona for session "s1"
    Then active persona for session "s1" should be "alpha"
    When I cycle persona for session "s1"
    Then active persona for session "s1" should be "beta"

  Scenario: cycle_persona updates last persona in registry
    Given a temporary TUI persona registry
    And I save TUI persona "p1" with actor "local/mock-default" and cycle order 1
    And I save TUI persona "p2" with actor "local/mock-default" and cycle order 2
    When I set active persona to "p1" for session "s1"
    And I cycle persona for session "s1"
    Then the registry last persona should be set to "p2"
