@subplan @coverage_boost
Feature: Subplan Execution Service – Defensive Code Path Coverage
  As a developer maintaining the subplan execution service
  I want to exercise the defensive error-handling code paths
  So that coverage includes the safety-net branches for parallel, wave, and dependency-ordered execution

  # --- Parallel execution: generic Exception from future.result() (lines 298-303) ---

  @parallel @defensive
  Scenario: Parallel execution catches generic exception from future and marks subplan ERRORED
    Given a subplan execution service in parallel mode with 2 subplans
    And the internal retry method is patched to raise a RuntimeError for the first subplan
    When parallel execution is invoked
    Then the first subplan should be marked ERRORED with the RuntimeError message
    And the second subplan should complete normally

  # --- Parallel execution: safety-net for uncaptured futures (lines 331-334) ---

  @parallel @defensive
  Scenario: Parallel fail-fast safety net cancels subplans missing from as_completed results
    Given a subplan execution service in parallel fail-fast mode with 3 subplans
    And as_completed is patched to skip the third future and the first subplan fails
    When parallel execution is invoked with patched as_completed
    Then the third subplan should be marked CANCELLED by the safety net
    And the results should contain all 3 subplans

  # --- Dependency-ordered: empty ready list causes break (line 381) ---

  @dependency_ordered @defensive
  Scenario: Dependency-ordered execution breaks out when no nodes are ready due to unresolvable deps
    Given a subplan execution service in dependency-ordered mode with 2 subplans
    And topological sort is patched to accept a circular dependency graph
    When dependency-ordered execution is invoked with the circular graph
    Then execution should complete without raising an error
    And the number of completed subplans should be less than 2

  # --- Wave execution: CancelledError from future.result() (lines 573-575) ---

  @wave @defensive
  Scenario: Wave execution catches CancelledError from a future and marks subplan CANCELLED
    Given a subplan execution service in dependency-ordered mode with 3 independent subplans
    And the internal retry method is patched to raise CancelledError for the second subplan in wave
    When dependency-ordered execution is invoked for the wave scenario
    Then the second subplan should be marked CANCELLED
    And the other subplans in the wave should complete successfully

  # --- Wave execution: generic Exception from future.result() (lines 576-578) ---

  @wave @defensive
  Scenario: Wave execution catches generic Exception from a future and marks subplan ERRORED
    Given a subplan execution service in dependency-ordered mode with 3 independent subplans for exception test
    And the internal retry method is patched to raise ValueError for the second subplan in wave
    When dependency-ordered execution is invoked for the wave exception scenario
    Then the second subplan should be marked ERRORED with the ValueError message
    And the other wave subplans should still complete
