*** Settings ***
Documentation    Smoke tests for per-session and per-org cost budgets
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

*** Variables ***
${HELPER_SCRIPT}    robot/helper_cost_budgets.py

*** Test Cases ***
Session Cost Budget Records Cost
    [Documentation]    Session budget tracks cumulative cost
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    session-record    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    session-record-ok

Session Cost Budget Detects Exceeded
    [Documentation]    Session budget detects when cap is exceeded
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    session-exceeded    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    session-exceeded-ok

Org Cost Accumulator Records Cost
    [Documentation]    Org accumulator tracks cumulative cost
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    org-record    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    org-record-ok

Org Cost Accumulator Detects Exceeded
    [Documentation]    Org accumulator detects when cap is exceeded
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    org-exceeded    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    org-exceeded-ok

Thread Safe Org Accumulator Works
    [Documentation]    Thread-safe wrapper delegates correctly
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    thread-safe    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    thread-safe-ok

Budget Hierarchy Allows Within All Limits
    [Documentation]    Budget hierarchy allows when under all caps
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    hierarchy-allow    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    hierarchy-allow-ok

Budget Hierarchy Blocks At Session Level
    [Documentation]    Budget hierarchy blocks at session tier
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    hierarchy-session-block    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    hierarchy-session-block-ok

Budget Hierarchy Blocks At Org Level
    [Documentation]    Budget hierarchy blocks at org tier
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    hierarchy-org-block    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    hierarchy-org-block-ok

Budget Hierarchy Blocks At Plan Level
    [Documentation]    Budget hierarchy blocks at plan tier
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    hierarchy-plan-block    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    hierarchy-plan-block-ok

Guardrail Service Budget Hierarchy
    [Documentation]    Guardrail service integrates budget hierarchy
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    guardrail-hierarchy    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    guardrail-hierarchy-ok

Settings Default Budget Fields
    [Documentation]    Settings have correct budget defaults
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    settings-defaults    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    settings-defaults-ok

Session Model Cost Budget Field
    [Documentation]    Session model includes cost_budget field
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    session-model    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    session-model-ok
