@phase1 @domain @repository @tool_add_persist
Feature: Tool Add Persistence across sessions
  As a system operator adding tools via the CLI
  I want tool registrations to be committed to the database
  So that a subsequent "tool list" invocation sees the added tools

  # Uses file-based SQLite to reproduce the cross-session persistence
  # issue described in issue #621.

  # ---------------------------------------------------------------------------
  # Single tool add/list round-trip
  # ---------------------------------------------------------------------------

  @tool_persist_single
  Scenario: Tool add followed by tool list shows the added tool
    Given a tool-persist file-based SQLite database
    And a tool-persist registry repository backed by the file database
    When a tool-persist tool named "local/my-widget" is created
    And a fresh tool-persist registry repository is opened against the same file
    And all tools are listed via the fresh tool-persist repository
    Then the tool-persist list should contain "local/my-widget"

  # ---------------------------------------------------------------------------
  # Multiple tools
  # ---------------------------------------------------------------------------

  @tool_persist_multi
  Scenario: Multiple tools added and listed
    Given a tool-persist file-based SQLite database
    And a tool-persist registry repository backed by the file database
    When a tool-persist tool named "local/alpha" is created
    And a tool-persist tool named "local/beta" is created
    And a fresh tool-persist registry repository is opened against the same file
    And all tools are listed via the fresh tool-persist repository
    Then the tool-persist list should contain "local/alpha"
    And the tool-persist list should contain "local/beta"
    And the tool-persist list should have 2 entries

  # ---------------------------------------------------------------------------
  # Duplicate rejection
  # ---------------------------------------------------------------------------

  @tool_persist_dup
  Scenario: Tool add with duplicate name produces error
    Given a tool-persist file-based SQLite database
    And a tool-persist registry repository backed by the file database
    When a tool-persist tool named "local/dup-tool" is created
    And a tool-persist tool named "local/dup-tool" is created expecting a duplicate error
    Then a tool-persist DuplicateToolError should have been raised
