*** Settings ***
Documentation    Integration test — parallel subplan spawn orchestration.
...              Verifies that SubplanService.spawn() creates real child Plan
...              domain objects, inherits project links, sets correct execution
...              mode, and attaches SubplanStatus entries to the parent plan
...              when configured for parallel execution.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

*** Variables ***
${HELPER}    ${CURDIR}/helper_subplan_spawn_orchestration.py

*** Test Cases ***
Parallel Spawn Creates Child Plans With Correct Identity
    [Documentation]    Verify parallel spawn creates child Plans with parent/root IDs.
    [Tags]    subplan    orchestration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    parallel-spawn-identity    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    parallel-spawn-identity-ok

Parallel Spawn Child Plans Inherit Project Links
    [Documentation]    Verify child plans inherit project links from the parent.
    [Tags]    subplan    orchestration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    parallel-spawn-project-links    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    parallel-spawn-project-links-ok

Parallel Spawn Attaches Statuses To Parent
    [Documentation]    Verify that spawn() attaches SubplanStatus entries to the
    ...                parent plan for lifecycle tracking.
    [Tags]    subplan    orchestration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    parallel-spawn-parent-statuses    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    parallel-spawn-parent-statuses-ok

Parallel Spawn Execution Mode Is Parallel
    [Documentation]    Verify the spawn result reports PARALLEL execution mode.
    [Tags]    subplan    orchestration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    parallel-spawn-mode    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    parallel-spawn-mode-ok
