*** Settings ***
Documentation    Integration tests for devcontainer lifecycle management (issue #514)
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
ContainerLifecycleState Enum Values
    [Documentation]    Verify all six lifecycle states exist
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    enum-values    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    enum-values-ok

Valid Transition Detected To Building
    [Documentation]    Verify detected->building transition
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    transition-valid    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    transition-valid-ok

Invalid Transition Rejected
    [Documentation]    Verify invalid transitions raise ValueError
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    transition-invalid    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    transition-invalid-ok

Lazy Activation With Mock Runner
    [Documentation]    Verify lazy activation with mock devcontainer CLI
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    lazy-activation    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    lazy-activation-ok

Stop Container With Mock Runner
    [Documentation]    Verify stop transitions active to stopped
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    stop-container    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    stop-container-ok

Rebuild Container With Mock Runner
    [Documentation]    Verify rebuild transitions stopped to active
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    rebuild-container    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    rebuild-container-ok

Session Cleanup Stops Active Containers
    [Documentation]    Verify session cleanup stops all active containers
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    session-cleanup    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    session-cleanup-ok

JSON Output Parsing
    [Documentation]    Verify devcontainer up JSON output parsing
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    json-parsing    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    json-parsing-ok

Lifecycle Registry Persistence
    [Documentation]    Verify tracker persists in registry
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    registry-persist    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    registry-persist-ok

CleanupService Has Devcontainer Method
    [Documentation]    Verify CleanupService.stop_active_devcontainers exists
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    cleanup-method    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cleanup-method-ok
