*** Settings ***
Documentation     Smoke tests for subplan execution scheduler, merge strategies,
...               and integrated execution+merge workflows.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Sequential Execution Completes All Subplans
    [Documentation]    Verify sequential mode executes all subplans in order
    [Tags]    subplan    execution    sequential
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    sequential-all    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sequential-all-ok

Sequential Execution Stops On Fail Fast
    [Documentation]    Verify sequential fail_fast stops after first failure
    [Tags]    subplan    execution    sequential    failfast
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    sequential-failfast    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sequential-failfast-ok

Parallel Execution Completes All Subplans
    [Documentation]    Verify parallel mode executes all subplans
    [Tags]    subplan    execution    parallel
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    parallel-all    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    parallel-all-ok

Dependency Ordered Execution Respects DAG
    [Documentation]    Verify dependency-ordered mode follows topological order
    [Tags]    subplan    execution    dependency
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    dep-ordered    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    dep-ordered-ok

Git Three Way Merge Non Overlapping
    [Documentation]    Verify git three-way merge combines non-overlapping changes
    [Tags]    subplan    merge    git
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    merge-git-clean    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    merge-git-clean-ok

Sequential Apply Merge
    [Documentation]    Verify sequential apply merge strategy
    [Tags]    subplan    merge    sequential
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    merge-sequential    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    merge-sequential-ok

Last Wins Merge Strategy
    [Documentation]    Verify last-wins merge strategy takes final output
    [Tags]    subplan    merge    lastwins
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    merge-last-wins    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    merge-last-wins-ok

Fail On Conflict Merge Raises Error
    [Documentation]    Verify fail-on-conflict strategy raises error on conflicts
    [Tags]    subplan    merge    conflict
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    merge-fail-conflict    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    merge-fail-conflict-ok

Execution With Merge Integration
    [Documentation]    Verify end-to-end execution and merge integration
    [Tags]    subplan    execution    merge    integration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    exec-merge-integration    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    exec-merge-integration-ok

Service Validation Guards
    [Documentation]    Verify service rejects invalid inputs
    [Tags]    subplan    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

Execution Summary Report
    [Documentation]    Verify execution result reports correct summary
    [Tags]    subplan    execution    summary
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    exec-summary    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    exec-summary-ok

Non Retriable Error Is Not Retried
    [Documentation]    Verify non-retriable errors are not retried
    [Tags]    subplan    execution    retry
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    retry-non-retriable    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    retry-non-retriable-ok

Executor Exception Triggers Retry Then Succeeds
    [Documentation]    Verify executor exception triggers retry for retriable errors
    [Tags]    subplan    execution    retry
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    retry-exception    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    retry-exception-ok

Merge Conflict During Execution
    [Documentation]    Verify merge conflict during execution marks result as failed
    [Tags]    subplan    execution    merge    conflict
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    merge-conflict-exec    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    merge-conflict-exec-ok
