*** Settings ***
Documentation     Integration tests for Workflow Example 4: Multi-Project
...               Dependency Update.  Exercises the supervised automation
...               profile with 4 projects, child plan spawning,
...               dependency-ordered execution, and coordinated apply.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Register 4 Project Links
    [Documentation]    Verify 4 project links (common-lib + 3 services) per spec
    [Tags]    wf04    projects    smoke
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    register-projects
    ...    timeout=60s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    ...    Register projects failed: ${result.stderr}
    Should Contain    ${result.stdout}    register-projects-ok

Create Coordinated Update Action
    [Documentation]    Create the coordinated-dep-update action with actors per spec
    [Tags]    wf04    action    smoke
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    create-action
    ...    timeout=60s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    ...    Create action failed: ${result.stderr}
    Should Contain    ${result.stdout}    create-action-ok

Use Action Across 4 Projects With Supervised Profile
    [Documentation]    Use action targeting 4 projects with supervised automation
    [Tags]    wf04    plan    supervised
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-use
    ...    timeout=60s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    ...    Plan use failed: ${result.stderr}
    Should Contain    ${result.stdout}    plan-use-ok

Strategize With Dependency Ordered Config
    [Documentation]    Drive strategize phase and verify subplan config
    [Tags]    wf04    strategize    subplan
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    strategize-cycle
    ...    timeout=60s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    ...    Strategize cycle failed: ${result.stderr}
    Should Contain    ${result.stdout}    strategize-cycle-ok

Spawn 4 Child Plans
    [Documentation]    Spawn child plan statuses for each project
    [Tags]    wf04    subplan    spawn
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    spawn-children
    ...    timeout=60s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    ...    Spawn children failed: ${result.stderr}
    Should Contain    ${result.stdout}    spawn-children-ok

Execute Children In Dependency Order
    [Documentation]    Common-lib executes first (blocking), then services in parallel
    [Tags]    wf04    execute    dependency-order
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    execute-children
    ...    timeout=60s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    ...    Execute children failed: ${result.stderr}
    Should Contain    ${result.stdout}    execute-children-ok

Apply In Dependency Order
    [Documentation]    Apply common-lib first, then services — verifies coordinated apply
    [Tags]    wf04    apply    dependency-order    critical
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    apply-ordered
    ...    timeout=60s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    ...    Apply ordered failed: ${result.stderr}
    Should Contain    ${result.stdout}    apply-ordered-ok

Full Multi-Project Lifecycle End To End
    [Documentation]    Complete WF04 lifecycle: action -> use -> strategize ->
    ...               execute -> apply with multi-project scopes, changesets,
    ...               cross-project validation, and coordinated apply
    [Tags]    wf04    lifecycle    critical    end-to-end
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    full-lifecycle
    ...    timeout=120s    on_timeout=kill
    Should Be Equal As Integers    ${result.rc}    0
    ...    Full lifecycle failed: ${result.stderr}
    Should Contain    ${result.stdout}    full-lifecycle-ok
