Feature: Retry Policy Wiring – Settings and Async Coverage
  As a developer
  I want settings overrides and async edge-cases tested
  So that service retry wiring is fully covered

  Background:
    Given I have the retry policy wiring module imported

  Scenario: Structured logging captures actual log output on retry
    Given I have a ServiceRetryWiring instance
    And I have a function that fails once then succeeds
    When I execute the function through the wiring with structlog captured
    Then the captured log should contain a retry warning message

  Scenario: Settings apply individual retry max_attempts override
    Given I have Settings with non-default retry_max_attempts 5
    When I create a ServiceRetryWiring from those max-attempts Settings
    Then the plan_service policy should have max_attempts 5

  Scenario: Settings apply circuit breaker failure_threshold override
    Given I have Settings with non-default circuit_breaker_failure_threshold 10
    When I create a ServiceRetryWiring from those cb-threshold Settings
    Then the plan_service circuit breaker should have failure_threshold 10

  Scenario: is_circuit_open returns False for unknown service
    Given I have a ServiceRetryWiring instance
    When I check is_circuit_open for "nonexistent_service"
    Then the circuit should report not open

  Scenario: Async ServiceRetryWiring execute with circuit breaker retries
    Given I have a ServiceRetryWiring instance
    And I have an async function that fails once then succeeds
    When I async_execute the function with circuit breaker enabled
    Then the async function should succeed after retry

  Scenario: Settings apply retry base_delay override
    Given I have Settings with non-default retry_base_delay 2.5
    When I create a ServiceRetryWiring from those base-delay Settings
    Then the plan_service policy should have base_delay 2.5

  Scenario: Settings apply circuit breaker recovery_timeout override
    Given I have Settings with non-default circuit_breaker_recovery_timeout 120.0
    When I create a ServiceRetryWiring from those recovery-timeout Settings
    Then the plan_service circuit breaker should have recovery_timeout 120.0

  Scenario: Settings apply circuit breaker cooldown override
    Given I have Settings with non-default circuit_breaker_cooldown 60.0
    When I create a ServiceRetryWiring from those cooldown Settings
    Then the plan_service circuit breaker should have cooldown_seconds 60.0

  Scenario: _build_cached_wait handles string backoff strategy
    Given I have a ServiceRetryWiring instance with string backoff policy
    When I request the wait strategy for the string-backoff service
    Then the wait strategy should be built successfully

  Scenario: Settings apply retry max_delay override
    Given I have Settings with non-default retry_max_delay 120.0
    When I create a ServiceRetryWiring from those max-delay Settings
    Then the plan_service policy should have max_delay 120.0

  Scenario: Settings apply retry jitter override
    Given I have Settings with non-default retry_jitter False
    When I create a ServiceRetryWiring from those jitter Settings
    Then the plan_service policy should have jitter False

  Scenario: Async ServiceRetryWiring execute without circuit breaker
    Given I have a ServiceRetryWiring instance for a service without circuit breaker
    And I have an async function that fails once then succeeds
    When I async_execute the function for the unprotected service
    Then the async function should succeed after retry

  Scenario: Sync ServiceRetryWiring nesting guard without circuit breaker
    Given I have a ServiceRetryWiring instance for a service without circuit breaker
    When I execute a nested sync operation for the unprotected service
    Then the nested inner function should execute directly without CB
