*** Settings ***
Documentation    Integration tests for the LLM-powered Strategy Actor (#828)
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Strategy Actor Stub Mode
    [Documentation]    Strategy actor produces decisions without LLM provider
    [Tags]    strategy    stub
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    stub-mode    cwd=${WORKSPACE}    timeout=60s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    strategy-actor-stub-ok

Strategy Actor LLM JSON Mode
    [Documentation]    Strategy actor parses JSON strategy from mock LLM
    [Tags]    strategy    llm
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    llm-json    cwd=${WORKSPACE}    timeout=60s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    strategy-actor-llm-json-ok

Strategy Actor LLM Fallback
    [Documentation]    Strategy actor falls back to stub when LLM fails
    ...    Retry logic adds ~3s of sleep (exponential back-off) before fallback.
    [Tags]    strategy    llm    fallback
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    llm-fallback    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    strategy-actor-llm-fallback-ok

Strategy Actor Cycle Detection
    [Documentation]    Dependency graph cycle detection works correctly
    [Tags]    strategy    validation
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    cycle-detection    cwd=${WORKSPACE}    timeout=60s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    strategy-actor-cycle-detection-ok

Strategy Actor Resolve Integration
    [Documentation]    resolve_strategy_actor correctly selects actor type
    [Tags]    strategy    resolver
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    resolve-actor    cwd=${WORKSPACE}    timeout=60s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    strategy-actor-resolve-ok

Strategy Actor Decision Conversion
    [Documentation]    Strategy tree is correctly converted to Decision objects
    [Tags]    strategy    decisions
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    decision-conversion    cwd=${WORKSPACE}    timeout=60s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    strategy-actor-decision-conversion-ok

Strategy Actor Prompt Construction
    [Documentation]    Strategy prompts are built correctly from context
    [Tags]    strategy    prompt
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    prompt-construction    cwd=${WORKSPACE}    timeout=60s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    strategy-actor-prompt-ok
