*** Settings ***
Documentation    End-to-end tests for Semantic Escalation confidence scoring
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Confidence Computation With All Factors High
    [Documentation]    All positive factors produce high confidence
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    confidence-high    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    confidence-high-ok

Confidence Computation With All Factors Low
    [Documentation]    All negative factors produce zero confidence
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    confidence-low    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    confidence-low-ok

Threshold Comparison Proceeds When Above
    [Documentation]    Proceed when confidence >= threshold
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    threshold-proceed    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    threshold-proceed-ok

Threshold Comparison Escalates When Below
    [Documentation]    Escalate when confidence < threshold
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    threshold-escalate    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    threshold-escalate-ok

Historical Success Tracking Records And Retrieves
    [Documentation]    Success rate updates after recording outcomes
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    history-tracking    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    history-tracking-ok

Escalation With Manual Profile Always Escalates
    [Documentation]    Manual profile (threshold 1.0) always escalates
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    profile-manual    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    profile-manual-ok

Escalation With FullAuto Profile Always Proceeds
    [Documentation]    Full-auto profile (threshold 0.0) always proceeds
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    profile-fullauto    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    profile-fullauto-ok

Escalation With Cautious Profile Uses Intermediate Thresholds
    [Documentation]    Cautious profile proceeds only with sufficient confidence
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    profile-cautious    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    profile-cautious-ok

EscalationDecision Model Captures All Fields
    [Documentation]    Decision model includes all required fields
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    decision-fields    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    decision-fields-ok

Zero Threshold Always Proceeds Even With Zero Confidence
    [Documentation]    Spec: threshold 0.0 means always automatic
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    zero-threshold    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    zero-threshold-ok
