*** Settings ***
Documentation     Integration tests for PlanExecutor subplan spawning.
...               Verifies that subplan_spawn and subplan_parallel_spawn
...               decisions are realised as actual child plan executions
...               during the Execute phase (Forgejo #3561).
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

*** Variables ***
${HELPER}    robot/helper_plan_executor_subplan_spawning.py

*** Test Cases ***
Subplan Spawn Decision Realisation
    [Documentation]    Verify subplan_spawn decision triggers SubplanService.spawn
    ...                and SubplanExecutionService.execute_all during Execute phase
    [Tags]    plan    execute    subplan    spawn    integration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    spawn-decision-realisation    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    spawn-decision-realisation-ok

Parallel Subplan Spawn Decision Realisation
    [Documentation]    Verify subplan_parallel_spawn decision triggers parallel execution
    [Tags]    plan    execute    subplan    spawn    parallel    integration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    parallel-spawn-decision-realisation    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    parallel-spawn-decision-realisation-ok

No-Op When No Spawn Decisions
    [Documentation]    Verify execute phase is a no-op for subplans when no spawn decisions exist
    [Tags]    plan    execute    subplan    noop    integration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    noop-no-spawn-decisions    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    noop-no-spawn-decisions-ok

No-Op When SubplanService Not Configured
    [Documentation]    Verify execute phase completes normally when SubplanService is absent
    [Tags]    plan    execute    subplan    noop    integration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    noop-no-subplan-service    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    noop-no-subplan-service-ok

Parent Plan Status Tracking On Child Failure
    [Documentation]    Verify parent plan error_details records failed subplan IDs
    [Tags]    plan    execute    subplan    failure    integration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    parent-status-tracking-failure    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    parent-status-tracking-failure-ok

SubplanService Properties Exposed
    [Documentation]    Verify PlanExecutor exposes subplan_service and subplan_execution_service properties
    [Tags]    plan    execute    subplan    properties    integration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    subplan-service-properties    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    subplan-service-properties-ok
