*** Settings ***
Documentation    TDD Issue #823 — subplan spawn creates metadata but does not orchestrate
...              child plan execution.  Integration smoke tests verifying that
...              SubplanService.spawn() creates real child Plan domain objects and
...              triggers lifecycle progression.  Currently spawn() only creates
...              SubplanStatus records and SpawnMetadata without creating child Plans.
...              Tests are tagged tdd_expected_fail so CI passes via result inversion.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
TDD Spawn Result Contains Child Plan Objects
    [Documentation]    Verify that spawn() returns actual child Plan domain objects,
    ...                not just SubplanStatus metadata.
    [Tags]    tdd_issue    tdd_issue_823
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    spawn-child-plans    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-spawn-child-plans-ok

TDD Child Plans Enter Strategize Phase
    [Documentation]    Verify that spawned child plans enter the strategize phase
    ...                and have their lifecycle triggered.
    [Tags]    tdd_issue    tdd_issue_823
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    spawn-lifecycle    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-spawn-lifecycle-ok

TDD Parent Plan Tracks Child Status
    [Documentation]    Verify that spawn() attaches SubplanStatus entries to
    ...                the parent plan so lifecycle can be tracked.
    [Tags]    tdd_issue    tdd_issue_823
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    spawn-parent-tracking    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-spawn-parent-tracking-ok
