*** Settings ***
Documentation    Smoke tests for Action YAML schema validation
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Validate Simple Action YAML
    [Documentation]    Parse the simple example action YAML and assert success
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validate    ${CURDIR}/../examples/actions/simple.yaml    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    action-schema-ok

Validate Invariant-Heavy Action YAML
    [Documentation]    Parse the invariant-heavy example action YAML and assert success
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validate    ${CURDIR}/../examples/actions/invariant-heavy.yaml    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    action-schema-ok

Validate Read-Only Action YAML
    [Documentation]    Parse the read-only example action YAML and assert success
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validate    ${CURDIR}/../examples/actions/read-only.yaml    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    action-schema-ok

Validate Estimation-Actor Action YAML
    [Documentation]    Parse the estimation-actor example action YAML and assert success
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validate    ${CURDIR}/../examples/actions/estimation-actor.yaml    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    action-schema-ok

Validate Inputs-Schema Action YAML
    [Documentation]    Parse the inputs-schema example action YAML and assert success
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validate    ${CURDIR}/../examples/actions/inputs-schema.yaml    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    action-schema-ok

Reject Invalid Action YAML
    [Documentation]    Attempt to parse an intentionally invalid YAML and assert failure
    # Create a temporary invalid YAML
    ${invalid_yaml}=    Set Variable    ${TEMPDIR}${/}invalid_action.yaml
    Create File    ${invalid_yaml}    description: missing required fields\n
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validate-invalid    ${invalid_yaml}    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    action-schema-expected-fail
