*** Settings ***
Documentation     Smoke tests for sandbox checkpoint and rollback hooks.
...               Covers M4 checkpoint infrastructure: creation, rollback, listing.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Verify Checkpoint Creation During Execute
    [Documentation]    Create a checkpoint before execute and verify its fields
    [Tags]    sandbox    checkpoint    create
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    checkpoint-create    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-create-ok

Verify Rollback After Failed Apply
    [Documentation]    Snapshot sandbox, modify files, rollback, verify restoration
    [Tags]    sandbox    checkpoint    rollback
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    checkpoint-rollback    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-rollback-ok

Verify Checkpoint Listing Order
    [Documentation]    Create multiple checkpoints and verify ordering
    [Tags]    sandbox    checkpoint    listing
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    checkpoint-listing    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-listing-ok

Verify Checkpoint Deletion
    [Documentation]    Create and delete a checkpoint, verify removal
    [Tags]    sandbox    checkpoint    delete
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    checkpoint-delete    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-delete-ok

Verify PlanExecutor Checkpoint Integration
    [Documentation]    PlanExecutor accepts optional checkpoint_manager
    [Tags]    sandbox    checkpoint    integration
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    executor-integration    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    executor-integration-ok
