@unit @database @models @new_coverage
Feature: Database models new coverage for missed lines and branches
  As a developer
  I want comprehensive coverage for database model conversions
  So that all code paths including edge cases are tested

  # -------------------------------------------------------------------
  # ToolModel.from_domain: object (non-dict) access via getattr
  # -------------------------------------------------------------------

  @tool @from_domain @object_access
  Scenario: ToolModel from_domain with object attribute access pattern
    Given a domain tool object with attribute access
    When I create a ToolModel from the domain object
    Then the ToolModel should have the correct name
    And the ToolModel should have the correct description
    And the ToolModel should have the correct tool_type
    And the ToolModel should have the correct source

  @tool @from_domain @object_access_namespaced
  Scenario: ToolModel from_domain with namespaced object splits name correctly
    Given a domain tool object with a namespaced name attribute
    When I create a ToolModel from the namespaced domain object
    Then the ToolModel namespace should be extracted correctly
    And the ToolModel short_name should be extracted correctly

  @tool @from_domain @object_defaults
  Scenario: ToolModel from_domain with object falling back to defaults
    Given a domain tool object with minimal attributes
    When I create a ToolModel from the minimal domain object
    Then the ToolModel should use default values for missing attributes

  # -------------------------------------------------------------------
  # SessionModel.from_domain: non-empty messages list
  # -------------------------------------------------------------------

  @session @from_domain @messages
  Scenario: SessionModel from_domain with non-empty messages list
    Given a domain session object with two messages
    When I create a SessionModel from the domain session
    Then the SessionModel should have two message child models
    And the first message model should have the correct role and content
    And the second message model should have the correct sequence

  @session @from_domain @single_message
  Scenario: SessionModel from_domain with a single message
    Given a domain session object with one message
    When I create a SessionModel from the single-message domain session
    Then the SessionModel should have exactly one message child model
    And the message model should preserve the message_id

  # -------------------------------------------------------------------
  # SkillModel: instantiation exercises short_name and description columns
  # -------------------------------------------------------------------

  @skill @instantiation
  Scenario: SkillModel instantiation covers short_name and description columns
    Given a SkillModel is created with short_name and description values
    Then the SkillModel short_name should match the provided value
    And the SkillModel description should match the provided value
    And the SkillModel namespace should be set correctly

  @skill @instantiation @with_items
  Scenario: SkillModel instantiation with child SkillItemModel records
    Given a SkillModel is created with a child SkillItemModel
    Then the SkillModel should have one item in items_rel
    And the SkillItemModel should have the correct item_type and item_name

  # -------------------------------------------------------------------
  # LifecyclePlanModel.from_domain: arguments_order with missing key
  # -------------------------------------------------------------------

  @plan @from_domain @arguments_order_missing_key
  @tdd_issue @tdd_issue_4247 @tdd_expected_fail
  Scenario: Plan from_domain skips arguments_order entries not in arguments_dict
    Given a plan domain object with arguments_order containing a missing key
    When I convert the plan domain object to a database model
    Then the database plan model should only have arguments for keys present in arguments_dict
    And the missing key should not appear in the argument child records

  @plan @from_domain @arguments_order_mixed
  @tdd_issue @tdd_issue_4247 @tdd_expected_fail
  Scenario: Plan from_domain handles mix of present and missing argument keys
    Given a plan domain object with three ordered keys but only two in arguments_dict
    When I convert the mixed-arguments plan to a database model
    Then the database plan model should have exactly two argument child records
    And the argument positions should reflect their order in arguments_order
