@phase1 @database @models @missing_coverage
Feature: Database models missing coverage for lines 1666, 1921, 2131-2132
  As a developer
  I want to exercise the remaining uncovered lines in database models
  So that code coverage reaches 100%

  Background:
    Given the missing coverage database is ready
    And a missing coverage database session is open

  # -------------------------------------------------------------------
  # ToolModel.from_domain() with a dict (covers line 1666)
  # -------------------------------------------------------------------

  @tool @from_domain @dict_input
  Scenario: ToolModel.from_domain creates model from a plain dict
    Given a tool definition provided as a plain dict
    When the tool dict is converted to a ToolModel via from_domain
    Then the ToolModel should have the correct name from the dict
    And the ToolModel should have the correct description from the dict
    And the ToolModel should have the correct tool_type from the dict
    And the ToolModel should have the correct source from the dict

  @tool @from_domain @dict_input @resource_bindings
  Scenario: ToolModel.from_domain populates resource bindings from dict input
    Given a tool definition provided as a plain dict with resource bindings
    When the tool dict with bindings is converted to a ToolModel via from_domain
    Then the ToolModel should have resource binding child records
    And each resource binding should have the correct slot_name
    And each resource binding should have the correct resource_type

  @tool @from_domain @dict_input @namespace
  Scenario: ToolModel.from_domain correctly splits namespaced name from dict
    Given a tool definition dict with a namespaced name
    When the namespaced tool dict is converted to a ToolModel via from_domain
    Then the ToolModel namespace should be extracted from the dict name
    And the ToolModel short_name should be extracted from the dict name

  # -------------------------------------------------------------------
  # SessionModel.from_domain() with messages (covers line 1921)
  # -------------------------------------------------------------------

  @session @from_domain @messages
  Scenario: SessionModel.from_domain populates message child models
    Given a Session domain object with two messages
    When the Session domain object is converted to a SessionModel via from_domain
    Then the SessionModel should have two message child records
    And the first message record should have role "user"
    And the second message record should have role "assistant"
    And each message record should have the correct content

  @session @from_domain @messages @single
  Scenario: SessionModel.from_domain handles a session with a single message
    Given a Session domain object with one message
    When the single-message Session is converted to a SessionModel via from_domain
    Then the SessionModel should have one message child record
    And the single message record should have the correct message_id

  # -------------------------------------------------------------------
  # SkillModel.from_domain() exercises column definitions (covers 2131-2132)
  # -------------------------------------------------------------------

  @skill @from_domain @columns
  Scenario: SkillModel.from_domain creates model with description and version
    Given a skill definition dict with description and version
    When the skill dict is converted to a SkillModel via from_domain
    Then the SkillModel should have the correct description
    And the SkillModel should have the correct version
    And the SkillModel should have the correct namespace
    And the SkillModel should have the correct short_name

  @skill @from_domain @no_version
  Scenario: SkillModel.from_domain handles skill without version
    Given a skill definition dict without a version field
    When the versionless skill dict is converted to a SkillModel via from_domain
    Then the SkillModel version should be None
    And the SkillModel description should still be set
