Feature: Repository uncovered branches and lines
  Cover missed lines and branches in repositories.py:
  ActorRepository, ToolRepository, ValidationAttachmentRepository,
  AutomationProfileRepository, DuplicateValidationAttachmentError,
  and ToolRepository._extract_value.

  # ── ActorRepository ──────────────────────────────────────────

  Scenario: repo branch cov actor get_default returns None when no default
    Given repo branch cov an in-memory database with actor tables
    When repo branch cov I call get_default with no default actor set
    Then repo branch cov get_default returns None

  Scenario: repo branch cov actor list_by_namespace returns matching actors
    Given repo branch cov an in-memory database with actor tables
    And repo branch cov actors "ns1/alpha" and "ns1/beta" and "ns2/gamma" exist
    When repo branch cov I call list_by_namespace with "ns1"
    Then repo branch cov 2 actors are returned
    And repo branch cov the actor names are "ns1/alpha" and "ns1/beta"

  Scenario: repo branch cov actor list_by_namespace returns empty for unknown
    Given repo branch cov an in-memory database with actor tables
    When repo branch cov I call list_by_namespace with "nonexistent"
    Then repo branch cov 0 actors are returned

  Scenario: repo branch cov actor list_by_schema_version returns matching
    Given repo branch cov an in-memory database with actor tables
    And repo branch cov actors with schema versions "1.0" and "2.0" exist
    When repo branch cov I call list_by_schema_version with "2.0"
    Then repo branch cov 1 actor is returned by schema version

  # ── ToolRepository ──────────────────────────────────────────

  Scenario: repo branch cov tool repo init with factory keyword
    Given repo branch cov an in-memory database with tool tables
    When repo branch cov I create ToolRepository with factory keyword
    Then repo branch cov the ToolRepository is usable

  Scenario: repo branch cov tool repo init with no arguments fails
    When repo branch cov I create ToolRepository with no session factory
    Then repo branch cov a TypeError is raised

  Scenario: repo branch cov tool repo get returns None for missing tool
    Given repo branch cov an in-memory database with tool tables
    And repo branch cov a ToolRepository instance
    When repo branch cov I call get with "nonexistent/tool"
    Then repo branch cov get returns None

  Scenario: repo branch cov tool repo get_by_name returns None for missing
    Given repo branch cov an in-memory database with tool tables
    And repo branch cov a ToolRepository instance
    When repo branch cov I call get_by_name with "nonexistent/tool"
    Then repo branch cov get_by_name returns None

  Scenario: repo branch cov tool repo remove succeeds for existing tool
    Given repo branch cov an in-memory database with tool tables
    And repo branch cov a ToolRepository instance
    And repo branch cov a tool "local/removable" exists in the database
    When repo branch cov I call remove with "local/removable"
    Then repo branch cov remove returns True

  Scenario: repo branch cov tool repo remove raises ToolNotFoundError
    Given repo branch cov an in-memory database with tool tables
    And repo branch cov a ToolRepository instance
    When repo branch cov I call remove with "nonexistent/tool"
    Then repo branch cov ToolNotFoundError is raised

  # ── ToolRepository._extract_value (dict branch) ────────────

  Scenario: repo branch cov extract_value from dict object
    When repo branch cov I call _extract_value with a dict obj key "name" default ""
    Then repo branch cov _extract_value returns the dict value

  Scenario: repo branch cov prepare_tool_dict without capability
    Given repo branch cov an in-memory database with tool tables
    And repo branch cov a ToolRepository instance
    When repo branch cov I prepare a tool dict from an object without capability
    Then repo branch cov the prepared dict has no capability_json

  # ── DuplicateValidationAttachmentError ──────────────────────

  Scenario: repo branch cov duplicate validation error with project name
    When repo branch cov I create DuplicateValidationAttachmentError with project_name
    Then repo branch cov the error message contains the project name

  Scenario: repo branch cov duplicate validation error with project and plan
    When repo branch cov I create DuplicateValidationAttachmentError with project and plan
    Then repo branch cov the error message contains both project and plan

  Scenario: repo branch cov duplicate validation error without scoping
    When repo branch cov I create DuplicateValidationAttachmentError without scoping
    Then repo branch cov the error message has no project or plan

  # ── ValidationAttachmentRepository ─────────────────────────

  Scenario: repo branch cov validation attach creates attachment
    Given repo branch cov an in-memory database with tool tables
    And repo branch cov a validation tool "local/check-lint" exists
    When repo branch cov I attach validation "local/check-lint" to resource "res-1"
    Then repo branch cov the attachment is returned with correct fields

  Scenario: repo branch cov validation attach with swapped args auto-corrects
    Given repo branch cov an in-memory database with tool tables
    And repo branch cov a validation tool "local/check-fmt" exists
    When repo branch cov I attach with validation_name "res/123" and resource_id "local/check-fmt"
    Then repo branch cov the attachment swaps them correctly

  # ── AutomationProfileRepository schema version mismatch ────

  Scenario: repo branch cov upsert profile with schema version mismatch
    Given repo branch cov an in-memory database with automation profile tables
    And repo branch cov an existing automation profile "acme/strict" with schema "1.0"
    When repo branch cov I upsert profile "acme/strict" expecting schema "2.0"
    Then repo branch cov AutomationProfileSchemaVersionError is raised
