*** Settings ***
Documentation     Smoke tests for async job execution: domain model, worker,
...               payload serialization, and config validation.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Async Job Status Transitions
    [Documentation]    Verify job status transitions follow the state machine
    [Tags]    async    domain    transitions
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    status-transitions    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    status-transitions-ok

Async Worker Pickup And Execute
    [Documentation]    Verify worker picks up and executes a queued job
    [Tags]    async    worker    execution
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    worker-execute    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    worker-execute-ok

Async Job Payload Serialization
    [Documentation]    Verify payload serialization round-trip
    [Tags]    async    serialization
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    payload-roundtrip    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    payload-roundtrip-ok

Async Worker Health Report
    [Documentation]    Verify worker health report contains expected fields
    [Tags]    async    worker    health
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    health-report    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    health-report-ok

Async Stuck Job Detection
    [Documentation]    Verify stuck jobs are detected and marked failed
    [Tags]    async    worker    stuck
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    stuck-detection    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    stuck-detection-ok

Async Job Cleanup
    [Documentation]    Verify completed jobs are cleaned up after TTL
    [Tags]    async    worker    cleanup
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    job-cleanup    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    job-cleanup-ok
