*** Settings ***
Documentation    Smoke tests for error recovery patterns,
...              including error classification, recording, retry policy,
...              output formatting, and model checks.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Error Classification
    [Documentation]    Verify error message classification into categories
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    classify    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    classify-ok

Error Recording
    [Documentation]    Verify error recording with metadata and recovery hints
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    record-error    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    record-error-ok

Retry Policy Decisions
    [Documentation]    Verify retry/escalation policy based on thresholds
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    retry-policy    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    retry-policy-ok

Error Output Formatting
    [Documentation]    Verify error output in plain and JSON formats
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    format-output    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    format-output-ok

Error Recovery Model Checks
    [Documentation]    Verify ErrorCategory, RecoveryAction, ErrorRecord, ErrorHistory models
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    model-checks    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    model-checks-ok

Helper No Arguments
    [Documentation]    Verify helper prints usage and exits 1 when called without args
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Should Be Equal As Integers    ${result.rc}    1
    Should Contain    ${result.stdout}    Usage

Helper Unknown Command
    [Documentation]    Verify helper exits 1 for an unknown sub-command
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    not-a-command    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Should Be Equal As Integers    ${result.rc}    1
    Should Contain    ${result.stdout}    Unknown command
