@plan @executor @subplan @coverage
Feature: PlanExecutor child plan execution coverage
  As a developer
  I want comprehensive tests for _execute_child_plan, _execute_subplans fallback,
  _apply_subplan_results_to_plan exec_result=None, and checkpoint PlanError handling
  So that uncovered lines in plan_executor.py are fully exercised

  # ------------------------------------------------------------------
  # _execute_child_plan — success path (lines 606, 616-649, 662)
  # ------------------------------------------------------------------

  Scenario: Execute child plan succeeds in stub mode
    Given a child3 PlanExecutor for child plan execution
    And child3 a SubplanStatus for a valid child plan
    When I child3 call _execute_child_plan on the executor
    Then child3 the SubplanExecutionOutput should indicate success
    And child3 the SubplanExecutionOutput should have a changeset_summary
    And child3 the running_plan_ids should be empty

  # ------------------------------------------------------------------
  # _execute_child_plan — circular detection (lines 607-615)
  # ------------------------------------------------------------------

  Scenario: Execute child plan detects circular re-entrant execution
    Given a child3 PlanExecutor for child plan execution
    And child3 a SubplanStatus for a valid child plan
    And I child3 pre-add the subplan_id to running_plan_ids
    When I child3 call _execute_child_plan on the executor
    Then child3 the SubplanExecutionOutput should indicate failure
    And child3 the SubplanExecutionOutput error should mention circular

  # ------------------------------------------------------------------
  # _execute_child_plan — plan not found (lines 620-624)
  # ------------------------------------------------------------------

  Scenario: Execute child plan returns failure when child plan not found
    Given a child3 PlanExecutor with lifecycle returning None for child plan
    And child3 a SubplanStatus for a valid child plan
    When I child3 call _execute_child_plan on the executor
    Then child3 the SubplanExecutionOutput should indicate failure
    And child3 the SubplanExecutionOutput error should mention "not found"

  # ------------------------------------------------------------------
  # _execute_child_plan — strategize produces no decisions (lines 626-634)
  # ------------------------------------------------------------------

  Scenario: Execute child plan returns failure when strategize produces no decisions
    Given a child3 PlanExecutor for child plan with empty definition
    And child3 a SubplanStatus for a valid child plan
    When I child3 call _execute_child_plan on the executor
    Then child3 the SubplanExecutionOutput should indicate failure
    And child3 the SubplanExecutionOutput error should mention "no decisions"

  # ------------------------------------------------------------------
  # _execute_child_plan — exception during execution (lines 650-660)
  # ------------------------------------------------------------------

  Scenario: Execute child plan catches exception and returns failure output
    Given a child3 PlanExecutor whose lifecycle start_strategize raises RuntimeError
    And child3 a SubplanStatus for a valid child plan
    When I child3 call _execute_child_plan on the executor
    Then child3 the SubplanExecutionOutput should indicate failure
    And child3 the SubplanExecutionOutput error should contain the exception message

  # ------------------------------------------------------------------
  # _execute_subplans — fallback when subplan_execution_service is None
  # but subplan_service is available (lines 521-527)
  # ------------------------------------------------------------------

  Scenario: _execute_subplans creates SubplanExecutionService when not injected
    Given a child3 PlanExecutor with subplan_service but no subplan_execution_service
    And child3 a SpawnResult with one spawned status
    When I child3 call _execute_subplans on the executor
    Then child3 the SubplanExecutionResult should not be None

  # ------------------------------------------------------------------
  # _execute_subplans — returns None when no subplan service (line 521)
  # ------------------------------------------------------------------

  Scenario: _execute_subplans returns None when both services are missing
    Given a child3 PlanExecutor with no subplan services at all
    And child3 a SpawnResult with one spawned status
    When I child3 call _execute_subplans on the executor
    Then child3 the SubplanExecutionResult should be None

  # ------------------------------------------------------------------
  # _execute_subplans — returns None when statuses is empty (line 532)
  # ------------------------------------------------------------------

  Scenario: _execute_subplans returns None when spawned_statuses is empty
    Given a child3 PlanExecutor with subplan_service and success executor
    And child3 a SpawnResult with no spawned statuses
    When I child3 call _execute_subplans on the executor
    Then child3 the SubplanExecutionResult should be None

  # ------------------------------------------------------------------
  # _apply_subplan_results_to_plan — exec_result is None (lines 569-570)
  # ------------------------------------------------------------------

  Scenario: _apply_subplan_results keeps spawned statuses when exec_result is None
    Given a child3 PlanExecutor for apply subplan results
    And child3 a SpawnResult with one spawned status
    When I child3 call _apply_subplan_results_to_plan with exec_result None
    Then child3 the plan subplan_statuses should match the spawn result statuses

  # ------------------------------------------------------------------
  # Property accessors for optional services (lines 433, 438, 443)
  # ------------------------------------------------------------------

  Scenario: Optional service properties return configured values
    Given a child3 PlanExecutor with all optional services configured
    Then child3 the fix_revalidate_orchestrator property should return the configured instance
    And child3 the subplan_service property should return the configured instance
    And child3 the subplan_execution_service property should return the configured instance

  # ------------------------------------------------------------------
  # _try_create_checkpoint — PlanError re-raise (lines 731-741, 745)
  # ------------------------------------------------------------------

  Scenario: _try_create_checkpoint re-raises PlanError from plan update failure
    Given a child3 PlanExecutor with checkpoint manager and lifecycle that fails on commit_plan
    And child3 a sandbox that returns a valid checkpoint
    When I child3 attempt _try_create_checkpoint expecting PlanError
    Then a child3 PlanError should be raised about persisting checkpoint metadata
