*** Settings ***
Documentation     Integration tests for validation apply gate
Resource          common.resource
Library           Process
Library           OperatingSystem
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

*** Test Cases ***
Gate Allows Apply When Validation Passes
    [Documentation]    Verify gate allows apply when required validation passes
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_validation_apply.py
    ...    run-gate    01PLAN0001    lint-check    res-001    required    lint-check    passed
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    val-gate-ok: ALLOWED

Gate Blocks Apply When Validation Fails
    [Documentation]    Verify gate blocks apply when required validation fails
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_validation_apply.py
    ...    run-gate    01PLAN0001    lint-check    res-001    required    other    irrelevant
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    val-gate-ok: BLOCKED

Build Validation Summary Metadata
    [Documentation]    Verify validation summary produces plan metadata
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_validation_apply.py
    ...    summary    01PLAN0001    2    1
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    val-summary-ok:
    Should Contain    ${result.stdout}    all_required_passed

Check Block With No Failures
    [Documentation]    Verify gate reports ALLOWED with no failures
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_validation_apply.py
    ...    check-block    01PLAN0001    3    0
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    val-check-block-ok: ALLOWED

Check Block With Failures
    [Documentation]    Verify gate reports BLOCKED with failures
    ${result}=    Run Process    ${PYTHON}    ${CURDIR}/helper_validation_apply.py
    ...    check-block    01PLAN0001    1    2
    ...    stderr=STDOUT
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    val-check-block-ok: BLOCKED
