@phase1 @domain @repository @coverage_boost
Feature: Database repositories coverage boost for uncovered branches
  As a developer ensuring high test coverage
  I want to exercise previously uncovered code paths in repositories.py
  So that persistence-layer branch coverage improves

  Background:
    Given a fresh in-memory database for repo coverage boost
    And an action repository for coverage boost
    And a lifecycle plan repository for coverage boost
    And a resource type repository for coverage boost

  # ---------------------------------------------------------------------------
  # ActionRepository.update – arg_type/requirement as plain strings (lines 1080, 1083)
  # ---------------------------------------------------------------------------

  @action_update @string_enums
  Scenario: Updating an action with plain-string arg_type and requirement hits else branches
    Given a valid action named "local/string-enum-action" for coverage boost
    And the action is persisted for coverage boost
    When the action arguments are replaced with plain-string arg_type and requirement
    And the action is updated for coverage boost
    Then the update should succeed for coverage boost
    And the retrieved action should have the string-typed arguments

  # ---------------------------------------------------------------------------
  # LifecyclePlanRepository.update – automation_profile truthy (line 1340)
  # ---------------------------------------------------------------------------

  @plan_update @automation_profile
  Scenario: Updating a plan with a truthy automation_profile serializes it
    Given a valid action named "local/auto-profile-action" for coverage boost
    And the action is persisted for coverage boost
    And a lifecycle plan linked to "local/auto-profile-action" with automation profile
    And the lifecycle plan is persisted for coverage boost
    When the plan automation profile is updated to a new profile ref
    And the lifecycle plan is updated for coverage boost
    Then the plan update should succeed for coverage boost
    And the retrieved plan should have the automation profile set

  # ---------------------------------------------------------------------------
  # LifecyclePlanRepository.update – validation_summary not None (line 1357)
  # ---------------------------------------------------------------------------

  @plan_update @validation_summary
  Scenario: Updating a plan with validation_summary serializes it to JSON
    Given a valid action named "local/val-summary-action" for coverage boost
    And the action is persisted for coverage boost
    And a lifecycle plan linked to "local/val-summary-action" with validation summary
    And the lifecycle plan is persisted for coverage boost
    When the plan validation summary is set to a non-None value
    And the lifecycle plan is updated for coverage boost
    Then the plan update should succeed for coverage boost
    And the retrieved plan should have the validation summary

  # ---------------------------------------------------------------------------
  # LifecyclePlanRepository.update – execution_env_priority not None (line 1367)
  # ---------------------------------------------------------------------------

  @plan_update @execution_env
  Scenario: Updating a plan with execution_env_priority serializes its value
    Given a valid action named "local/env-priority-action" for coverage boost
    And the action is persisted for coverage boost
    And a lifecycle plan linked to "local/env-priority-action" with env priority
    And the lifecycle plan is persisted for coverage boost
    When the plan execution env priority is set
    And the lifecycle plan is updated for coverage boost
    Then the plan update should succeed for coverage boost
    And the retrieved plan should have execution env priority set

  # ---------------------------------------------------------------------------
  # LifecyclePlanRepository.list_all – DatabaseError branch (lines 1472-1473)
  # ---------------------------------------------------------------------------

  @plan_list @error_handling
  Scenario: list_all raises DatabaseError on OperationalError
    Given a lifecycle plan repository with a broken session factory
    When list_all is called on the broken plan repository
    Then a DatabaseError mentioning "Failed to list plans" should be raised for coverage boost

  # ---------------------------------------------------------------------------
  # ResourceTypeRepository.create – name with "/" namespace extraction (line 1730)
  # and plain-string resource_kind (line 1734) and sandbox_strategy (line 1737)
  # ---------------------------------------------------------------------------

  @resource_type @create @namespaced
  Scenario: Creating a resource type with namespaced name and string enums
    Given a resource type spec with namespaced name "custom/my-db-type" and string enums
    When the resource type is created for coverage boost
    Then the resource type creation should succeed for coverage boost
    And the retrieved resource type should have namespace "custom"

  # ---------------------------------------------------------------------------
  # ResourceTypeRepository.update – plain-string resource_kind (line 1857)
  # and sandbox_strategy (line 1862) and cli_args serialization (lines 1867-1872)
  # ---------------------------------------------------------------------------

  @resource_type @update @string_enums
  Scenario: Updating a resource type with string enums and cli_args
    Given a resource type spec with name "custom/updatable-type" and string enums
    And the resource type is persisted for coverage boost
    When the resource type is updated with new description and cli_args
    Then the resource type update should succeed for coverage boost
    And the retrieved resource type should have updated cli_args

  # ---------------------------------------------------------------------------
  # ResourceTypeRepository.create – builtin name without "/" (line 1730 else)
  # ---------------------------------------------------------------------------

  @resource_type @create @builtin
  Scenario: Creating a resource type with builtin name uses "builtin" namespace
    Given a resource type spec with builtin name "test-builtin-type" and string enums
    When the resource type is created for coverage boost
    Then the resource type creation should succeed for coverage boost
    And the retrieved builtin resource type should have namespace "builtin"
