*** Settings ***
Documentation    Integration tests for tool-level execution environment preferences
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Default Preference Is NONE
    [Documentation]    Default ExecutionEnvironmentPreference has mode=none
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    default-preference    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    default-preference-ok

Required Mode Validates
    [Documentation]    Required mode creates correctly with no target_resource
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    required-mode    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    required-mode-ok

Preferred Mode Validates
    [Documentation]    Preferred mode creates correctly with no target_resource
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    preferred-mode    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    preferred-mode-ok

Specific Mode With Target
    [Documentation]    Specific mode requires and accepts target_resource
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    specific-mode    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    specific-mode-ok

Specific Mode Validates Target Required
    [Documentation]    Specific mode validates target_resource is present
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    specific-validates-target    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    specific-validates-target-ok

ToolSpec Has Execution Environment Field
    [Documentation]    ToolSpec model includes execution_environment field
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    toolspec-field    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    toolspec-field-ok

Domain Tool Has Execution Environment Field
    [Documentation]    Domain Tool model includes execution_environment field
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    domain-tool-field    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    domain-tool-field-ok

Tool From Config Parses Execution Environment
    [Documentation]    Tool.from_config parses execution_environment from YAML dict
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    tool-from-config    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tool-from-config-ok

Runner NONE Preference Uses Caller Env
    [Documentation]    ToolRunner with NONE preference uses caller-supplied env
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    runner-none-preference    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    runner-none-preference-ok

Runner Required Fails Without Container
    [Documentation]    ToolRunner with REQUIRED preference fails without container
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    runner-required-no-container    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    runner-required-no-container-ok

Runner Preferred Falls Back To Host
    [Documentation]    ToolRunner with PREFERRED preference falls back to host
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    runner-preferred-fallback    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    runner-preferred-fallback-ok

Runner Specific Targets Container
    [Documentation]    ToolRunner with SPECIFIC preference targets named container
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    runner-specific-container    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    runner-specific-container-ok
