*** Settings ***
Documentation     Integration tests for overlay filesystem sandbox.
...               Covers OverlaySandbox lifecycle, rollback, validation,
...               directory structure, fallback mode, and state errors.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Overlay Sandbox Full Lifecycle
    [Documentation]    Verify create -> get_path -> modify -> commit -> cleanup
    [Tags]    sandbox    overlay    lifecycle
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    overlay-lifecycle    cwd=${WORKSPACE}    on_timeout=kill    timeout=60s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    overlay-lifecycle-ok

Overlay Sandbox Rollback
    [Documentation]    Verify rollback discards changes and restores original state
    [Tags]    sandbox    overlay    rollback
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    overlay-rollback    cwd=${WORKSPACE}    on_timeout=kill    timeout=60s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    overlay-rollback-ok

Overlay Sandbox Input Validation
    [Documentation]    Verify empty inputs and non-existent paths are rejected
    [Tags]    sandbox    overlay    validation
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    overlay-validation    cwd=${WORKSPACE}    on_timeout=kill    timeout=60s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    overlay-validation-ok

Overlay Sandbox Directory Structure
    [Documentation]    Verify upper/work/merged directories are created
    [Tags]    sandbox    overlay    structure
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    overlay-directory-structure    cwd=${WORKSPACE}    on_timeout=kill    timeout=60s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    overlay-directory-structure-ok

Overlay Sandbox Fallback Mode
    [Documentation]    Verify userspace fallback when OverlayFS unavailable
    [Tags]    sandbox    overlay    fallback
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    overlay-fallback-mode    cwd=${WORKSPACE}    on_timeout=kill    timeout=60s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    overlay-fallback-mode-ok

Overlay Sandbox State Errors
    [Documentation]    Verify state machine rejects invalid transitions
    [Tags]    sandbox    overlay    state
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    overlay-state-errors    cwd=${WORKSPACE}    on_timeout=kill    timeout=60s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    overlay-state-errors-ok
