*** Settings ***
Resource          ${CURDIR}/common.resource
Library           OperatingSystem
Library           Process

*** Variables ***
${SRC_DIR}        ${CURDIR}/..

*** Test Cases ***
Provider Registry Uses Env Defaults
    [Documentation]    Ensure ProviderRegistry selects OpenAI when OPENAI_API_KEY is configured
    ${result}=    Run Process    ${PYTHON}    robot/helper_provider_registry.py    env-defaults
    ...    cwd=${SRC_DIR}
    ...    env:OPENAI_API_KEY=robot-openai-key
    ...    env:CLEVERAGENTS_TESTING_USE_MOCK_AI=
    Log Process Failure    ${result}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    registry-openai-ok



*** Keywords ***
Log Process Failure
    [Arguments]    ${result}
    Run Keyword If    ${result.rc} == 0    Return From Keyword
    Log To Console    Process failed with rc=${result.rc}
    Log To Console    STDOUT:${\n}${result.stdout}
    Log To Console    STDERR:${\n}${result.stderr}
