*** Settings ***
Documentation     Smoke tests for subplan spawn service, validation,
...               and metadata persistence.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Spawn Single Child Plan From Decision Entry
    [Documentation]    Verify spawning a single child plan creates status and metadata
    [Tags]    subplan    spawn
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    spawn-single    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    spawn-single-ok

Spawn Multiple Child Plans From Decisions
    [Documentation]    Verify spawning multiple child plans from decision entries
    [Tags]    subplan    spawn    multiple
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    spawn-multiple    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    spawn-multiple-ok

Validate Resource Scope Missing
    [Documentation]    Verify validation rejects missing resource scopes
    [Tags]    subplan    spawn    validation
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validate-resource    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    validate-resource-ok

Validate Max Parallel Exceeded
    [Documentation]    Verify validation rejects exceeding max_parallel bounds
    [Tags]    subplan    spawn    validation    parallel
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validate-max-parallel    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    validate-max-parallel-ok

Spawn Metadata Persistence
    [Documentation]    Verify spawn metadata contains correct plan IDs and mode
    [Tags]    subplan    spawn    metadata
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    metadata-persistence    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    metadata-persistence-ok

Service Validation Guards
    [Documentation]    Verify service rejects invalid inputs
    [Tags]    subplan    spawn    validation
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validation-guards    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    validation-guards-ok

Build Spawn Entries From Decisions
    [Documentation]    Verify building spawn entries from decision objects
    [Tags]    subplan    spawn    entries
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    build-entries    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    build-entries-ok
