*** Settings ***
Documentation    Smoke tests for autonomy guardrails and audit trail
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Guardrail Step Limit Allows Within Bounds
    [Documentation]    Step limit allows when under limit
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    step-allow    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    step-allow-ok

Guardrail Step Limit Blocks At Max
    [Documentation]    Step limit blocks when at max steps
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    step-block    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    step-block-ok

Guardrail Budget Allows Within Limit
    [Documentation]    Budget allows when within limit
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    budget-allow    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    budget-allow-ok

Guardrail Budget Blocks Exceeded
    [Documentation]    Budget blocks when exceeded
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    budget-block    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    budget-block-ok

Guardrail Confirmation Required
    [Documentation]    Confirmation required for listed operation
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    confirm-required    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    confirm-required-ok

Guardrail Audit Trail Records Events
    [Documentation]    Audit trail records enforcement events
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    audit-trail    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    audit-trail-ok

Guardrail Service Metadata Persistence
    [Documentation]    Service can serialize and restore from metadata
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    metadata    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    metadata-ok

Guardrail Wall Clock Allows Within Limit
    [Documentation]    Wall-clock allows when within time limit
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    wall-clock-allow    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    wall-clock-allow-ok

Guardrail Wall Clock Blocks When Expired
    [Documentation]    Wall-clock blocks when time limit exceeded
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    wall-clock-block    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    wall-clock-block-ok

Guardrail Actor Tool Call Limit
    [Documentation]    Actor tool-call limit enforcement
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    actor-limit    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    actor-limit-ok

Guardrail Audit Trail Eviction
    [Documentation]    Audit trail evicts oldest entries when full
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    eviction    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    eviction-ok

Guardrail Zero Budget Edge Case
    [Documentation]    Zero budget blocks any positive cost
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    zero-budget    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    zero-budget-ok

Guardrail CLI Flags Summary
    [Documentation]    Summary of autonomy guardrail features
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    summary    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    summary-ok
