*** Settings ***
Documentation     Smoke tests for subplan model hierarchy, configuration defaults,
...               failure handling, and CLI status surface rendering.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Root Plan Identity Flags
    [Documentation]    Verify root plan has is_root_plan=True, is_subplan=False, depth=0
    [Tags]    subplan    model    identity
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    root-identity    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    root-identity-ok

Child Plan Identity Flags
    [Documentation]    Verify child plan has is_subplan=True, is_root_plan=False, depth=-1
    [Tags]    subplan    model    identity
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    child-identity    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    child-identity-ok

Three Level Hierarchy Root Propagation
    [Documentation]    Verify root_plan_id propagates through three levels
    [Tags]    subplan    model    hierarchy
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    hierarchy-propagation    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    hierarchy-propagation-ok

SubplanConfig Defaults
    [Documentation]    Verify SubplanConfig defaults are sensible
    [Tags]    subplan    model    config
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    config-defaults    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    config-defaults-ok

SubplanConfig Custom Settings
    [Documentation]    Verify SubplanConfig accepts custom parallel/retry settings
    [Tags]    subplan    model    config
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    config-custom    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    config-custom-ok

Failure Handler Stop Others On Fail Fast
    [Documentation]    Verify SubplanFailureHandler stops others when fail_fast=True
    [Tags]    subplan    model    failure
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    failure-stop-others    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    failure-stop-others-ok

Failure Handler Retry Retriable Error
    [Documentation]    Verify SubplanFailureHandler retries retriable TimeoutError
    [Tags]    subplan    model    failure    retry
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    failure-retry-retriable    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    failure-retry-retriable-ok

Failure Handler Skip Non Retriable Error
    [Documentation]    Verify SubplanFailureHandler skips non-retriable ConfigurationError
    [Tags]    subplan    model    failure    retry
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    failure-skip-non-retriable    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    failure-skip-non-retriable-ok

CLI Dict Renders Parent Plan Id For Child
    [Documentation]    Verify as_cli_dict includes parent_plan_id for child plans
    [Tags]    subplan    model    cli
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    cli-dict-child    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-dict-child-ok

CLI Dict Renders Subplan Count
    [Documentation]    Verify as_cli_dict includes subplan_count when subplans exist
    [Tags]    subplan    model    cli
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    cli-dict-subplan-count    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-dict-subplan-count-ok

Plan With Subplan Config And Statuses
    [Documentation]    Verify Plan model accepts subplan config and status list
    [Tags]    subplan    model    plan
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-with-config    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    plan-with-config-ok
