Feature: Session, Tool, and Project model branch coverage (round 2)
  As a developer maintaining the ORM layer
  I want every branch in the domain-conversion helpers tested
  So that models.py achieves near-100 % branch coverage

  # ===================================================================
  # SessionModel.to_domain() — lines 1858-1896
  # Targets: None branches on linked_plan_ids_json, token_usage_json,
  #          metadata_json, messages_rel
  # ===================================================================

  Scenario: r2mod- SessionModel.to_domain with all None JSON fields
    Given a r2mod-SessionModel with all JSON fields as None
    When I r2mod-convert the SessionModel to domain
    Then the r2mod-session linked_plan_ids should be empty
    And the r2mod-session token_usage input_tokens should be 0
    And the r2mod-session metadata should be empty
    And the r2mod-session messages should be empty

  # ===================================================================
  # SessionMessageModel.to_domain() — line 1983
  # Targets: None metadata_json branch
  # ===================================================================

  Scenario: r2mod- SessionMessageModel.to_domain with None metadata_json
    Given a r2mod-SessionMessageModel with None metadata_json
    When I r2mod-convert the SessionMessageModel to domain
    Then the r2mod-message metadata should be empty

  # ===================================================================
  # ToolModel.to_domain() / from_domain() — lines 1612-1718
  # Targets: None resource_bindings_rel branch, dict-vs-object input,
  #          no-slash name branch
  # ===================================================================

  Scenario: r2mod- ToolModel.to_domain with None resource_bindings_rel
    Given a r2mod-ToolModel with no resource bindings
    When I r2mod-convert the ToolModel to domain
    Then the r2mod-tool resource_bindings should be empty

  Scenario: r2mod- ToolModel.from_domain with dict input and no slash in name
    When I r2mod-create ToolModel from dict with name "nonamespace"
    Then the r2mod-created ToolModel namespace should be empty string
    And the r2mod-created ToolModel short_name should be "nonamespace"

  Scenario: r2mod- ToolModel.from_domain with dict input and slash in name
    When I r2mod-create ToolModel from dict with name "ns/tool-name"
    Then the r2mod-created ToolModel namespace should be "ns"
    And the r2mod-created ToolModel short_name should be "tool-name"

  Scenario: r2mod- ToolModel.from_domain with object input
    When I r2mod-create ToolModel from object with name "ns/objtool"
    Then the r2mod-created ToolModel namespace should be "ns"

  Scenario: r2mod- ToolModel.from_domain with resource_bindings as None
    When I r2mod-create ToolModel from dict with no resource_bindings
    Then the r2mod-created ToolModel resource_bindings_rel should be empty

  # ===================================================================
  # NamespacedProjectModel.to_domain() — lines 1109-1153
  # Targets: no context_policy_json, no resource_links, no-slash name
  # ===================================================================

  Scenario: r2mod- ProjectModel.to_domain with no context policy and no-slash name
    Given a r2mod-ProjectModel with no context_policy_json and name "simplename"
    When I r2mod-convert the ProjectModel to domain
    Then the r2mod-project name should be "simplename"
    And the r2mod-project linked_resources should be empty

  Scenario: r2mod- ProjectModel.to_domain with None resource_links
    Given a r2mod-ProjectModel with None resource_links
    When I r2mod-convert the ProjectModel to domain
    Then the r2mod-project linked_resources should be empty

  # ===================================================================
  # NamespacedProjectModel.from_domain() — lines 1156-1187
  # Targets: None context_config branch
  # ===================================================================

  Scenario: r2mod- ProjectModel.from_domain with None context_config
    When I r2mod-create ProjectModel from domain with None context_config
    Then the r2mod-created ProjectModel context_policy_json should be None

  # ===================================================================
  # SessionMessageModel.from_domain() — lines 1996-2014
  # Targets: role with value attr vs plain string
  # ===================================================================

  Scenario: r2mod- SessionMessageModel.from_domain with string role
    When I r2mod-create SessionMessageModel from domain with string role
    Then the r2mod-created SessionMessageModel role should be "user"
