Feature: TUI persona system
  Personas are TUI-only YAML records with per-session binding.

  Scenario: Persona schema auto-creates default preset
    When I build a TUI persona named "dev" with actor "local/mock-default"
    Then the persona should include exactly one default preset

  Scenario: Persona registry saves and loads YAML records
    Given a temporary TUI persona registry
    When I save a TUI persona named "reviewer" with actor "local/mock-default"
    Then loading persona "reviewer" should succeed
    And the loaded persona actor should be "local/mock-default"

  Scenario: Persona registry validates duplicate cycle order
    Given a temporary TUI persona registry
    And I save a TUI persona named "a" with actor "local/mock-default" and cycle order 1
    When I try to save a TUI persona named "b" with actor "local/mock-default" and cycle order 1
    Then saving the second persona should fail with cycle order error

  Scenario: Persona state is bound per session
    Given a temporary TUI persona registry
    And I save a TUI persona named "dev" with actor "local/mock-default"
    And I save a TUI persona named "reviewer" with actor "local/mock-default"
    When I set active persona to "dev" for session "s1"
    And I set active persona to "reviewer" for session "s2"
    Then active persona for session "s1" should be "dev"
    And active persona for session "s2" should be "reviewer"

  Scenario: Persona state cycles through presets per session
    Given a temporary TUI persona registry
    And I save TUI persona "cycler" with actor "local/mock-default" and extra preset "focused"
    When I set active persona to "cycler" for session "s1"
    And I cycle persona preset for session "s1"
    Then current preset for session "s1" should be "focused"
    When I cycle persona preset for session "s1"
    Then current preset for session "s1" should be "default"

  Scenario: Malformed persona YAML does not break registry operations
    Given a temporary TUI persona registry
    And I save a TUI persona named "good" with actor "local/mock-default"
    And I create malformed TUI persona file "broken"
    When I list TUI personas
    Then TUI persona list should include "good"
    When I save a TUI persona named "stillworks" with actor "local/mock-default"
    Then loading persona "stillworks" should succeed

  Scenario: TUI registry rejects unsafe export and import paths
    Given a temporary TUI persona registry
    And I save a TUI persona named "safe" with actor "local/mock-default"
    When I export TUI persona "safe" to "../escape.yaml"
    Then TUI export should fail with "stay within working directory"
    When I import TUI persona from "../escape.yaml"
    Then TUI import should fail with "stay within working directory"

  Scenario: TUI registry state writes tolerate concurrent updates
    Given a temporary TUI persona registry
    When I concurrently set TUI last persona names
      | name |
      | a    |
      | b    |
      | c    |
      | d    |
    Then TUI concurrent update should complete without errors
