*** Settings ***
Documentation    Integration test for Workflow Example 14: server mode team collaboration
...              Validates server mode configuration, diagnostics, namespace management,
...              action publishing to team namespaces, and plan monitoring across namespaces.
...              Uses the supervised automation profile as required by the specification.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
WF14 Server Mode Config
    [Documentation]    Set server.url, server.token, core.namespace config values and verify readback
    [Tags]    integration    server-mode    wf14    config
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    config-server-mode    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Not Contain    ${result.stdout}${result.stderr}    Traceback
    Should Contain    ${result.stdout}    wf14-config-server-mode-ok

WF14 Diagnostics
    [Documentation]    Verify config registry contains required server-mode keys and that default values match the specification
    [Tags]    integration    server-mode    wf14    diagnostics
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    diagnostics    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Not Contain    ${result.stdout}${result.stderr}    Traceback
    Should Contain    ${result.stdout}    wf14-diagnostics-ok

WF14 Action Publish To Namespace
    [Documentation]    Create a namespaced action and verify listing plus supervised-profile metadata
    [Tags]    integration    server-mode    wf14    action    namespace    publish
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    action-namespace    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Not Contain    ${result.stdout}${result.stderr}    Traceback
    Should Contain    ${result.stdout}    wf14-action-namespace-ok

WF14 Action With Namespaced Actor References
    [Documentation]    Create an action referencing actors from different namespaces and verify fields are preserved
    [Tags]    integration    server-mode    wf14    action    actor
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    action-actor-refs    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Not Contain    ${result.stdout}${result.stderr}    Traceback
    Should Contain    ${result.stdout}    wf14-action-actor-refs-ok

WF14 Shared Action From Namespace
    [Documentation]    List actions from a specific namespace and verify shared actions are visible
    [Tags]    integration    server-mode    wf14    action    namespace    shared
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    shared-actions    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Not Contain    ${result.stdout}${result.stderr}    Traceback
    Should Contain    ${result.stdout}    wf14-shared-actions-ok

WF14 Use Shared Action
    [Documentation]    Use a shared action with required args/project link and verify inherited actors plus initial phase
    [Tags]    integration    server-mode    wf14    plan    use-action
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    use-shared-action    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Not Contain    ${result.stdout}${result.stderr}    Traceback
    Should Contain    ${result.stdout}    wf14-use-shared-action-ok

WF14 Plan List Across Namespace
    [Documentation]    Create plans from namespaced actions and verify namespace plus phase-filtered monitoring
    [Tags]    integration    server-mode    wf14    plan    namespace    monitoring
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-namespace    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Not Contain    ${result.stdout}${result.stderr}    Traceback
    Should Contain    ${result.stdout}    wf14-plan-namespace-ok
