Feature: DecompositionService uncovered code path coverage
  As a developer
  I want to exercise the uncovered branches in decomposition_service.py
  So that clustering fallback chains and decision recording edge cases are tested

  Background:
    Given a fresh decomposition service instance

  # --- Lines 236-239: Language clustering fallback ---
  # When cluster_by_directory returns a single cluster, the service
  # should fall through to cluster_by_language.

  Scenario: Falls back to language clustering when directory clustering yields one cluster
    Given a file set that directory-clusters into one group but language-clusters into many
    When I run decomposition on those files
    Then at least one node should use the language clustering strategy

  # --- Lines 242-245: Size clustering fallback ---
  # When both directory and language clustering return a single cluster,
  # the service should fall through to cluster_by_size.

  Scenario: Falls back to size clustering when directory and language clustering both yield one cluster
    Given a file set where directory and language clustering each yield one group
    When I run decomposition on those files
    Then at least one node should use the size clustering strategy

  # --- Lines 249-264: Complete fallback with warning ---
  # When ALL clustering strategies produce zero clusters, the service
  # emits a warning log and creates a single FALLBACK node.

  Scenario: Creates fallback node with warning when all clustering strategies return empty
    Given a file set where all clustering strategies return empty lists
    When I run decomposition on those files
    Then the result should contain a fallback strategy node
    And a decomposition fallback warning should have been logged

  # --- Line 320: record_decisions early return when decision_service is None ---

  Scenario: record_decisions returns immediately when no decision service is injected
    Given a decomposition service without a decision service
    And a trivial decomposition result
    When I call record_decisions with plan id "plan-00001"
    Then no exception should be raised from record_decisions

  # --- Combined: language fallback produces correct strategy label ---

  Scenario: Language fallback strategy label appears in result metrics
    Given a file set that directory-clusters into one group but language-clusters into many
    When I run decomposition on those files and collect metrics
    Then the result total_nodes metric should be present
    And the result leaf_nodes metric should be present

  # --- Combined: size fallback with deep recursion is bounded by max_depth ---

  Scenario: Size clustering fallback respects max_depth limit
    Given a file set where directory and language clustering each yield one group
    When I run decomposition with max_depth 1 on those files
    Then the result max_depth_reached should be at most 1
