*** Settings ***
Documentation    Smoke tests for LLM trace observability
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Record And Retrieve LLM Trace
    [Documentation]    Record a trace and verify retrieval by ID
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    record-and-retrieve    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    llm-trace-record-ok

List Traces By Plan
    [Documentation]    Record multiple traces and list by plan ID
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    list-by-plan    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    llm-trace-list-plan-ok

Compute Metrics For Plan
    [Documentation]    Compute operational metrics from recorded traces
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    compute-metrics    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    llm-trace-metrics-ok

Verify Metric Key Count
    [Documentation]    All 14 operational metric keys should be defined
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    metric-key-count    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    llm-trace-metric-keys-ok

Verify LLM Trace Model Validation
    [Documentation]    Model should reject invalid inputs
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validation    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    llm-trace-validation-ok

Verify Lifecycle Hooks
    [Documentation]    Lifecycle hooks should produce correct metric entries
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    lifecycle-hooks    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    llm-trace-hooks-ok
