*** Settings ***
Documentation     Smoke tests for checkpoint and rollback: create, list, rollback,
...               prune, guards, and metadata auditability.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

*** Variables ***
${HELPER}    robot/helper_checkpoint_rollback.py

*** Test Cases ***
Create Checkpoint
    [Documentation]    Verify checkpoint creation succeeds
    [Tags]    phase2    checkpoint    create
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    create-checkpoint    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    create-checkpoint-ok

List Checkpoints
    [Documentation]    Verify listing checkpoints returns expected count
    [Tags]    phase2    checkpoint    list
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    list-checkpoints    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    list-checkpoints-ok

Rollback To Checkpoint
    [Documentation]    Verify rollback restores sandbox state
    [Tags]    phase2    checkpoint    rollback
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    rollback-checkpoint    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    rollback-checkpoint-ok

Rollback Rejected Applied Plan
    [Documentation]    Verify rollback blocked when plan is applied
    [Tags]    phase2    checkpoint    rollback    guard
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    rollback-applied-guard    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    rollback-applied-guard-ok

Rollback Rejected Missing Sandbox
    [Documentation]    Verify rollback blocked when sandbox is missing
    [Tags]    phase2    checkpoint    rollback    guard
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    rollback-sandbox-guard    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    rollback-sandbox-guard-ok

Prune Checkpoints
    [Documentation]    Verify pruning removes oldest checkpoints
    [Tags]    phase2    checkpoint    prune
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    prune-checkpoints    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    prune-checkpoints-ok

Delete Checkpoint
    [Documentation]    Verify deleting a checkpoint removes it
    [Tags]    phase2    checkpoint    delete
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    delete-checkpoint    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    delete-checkpoint-ok

Checkpoint Metadata Auditability
    [Documentation]    Verify checkpoint metadata stores reason and source
    [Tags]    phase2    checkpoint    metadata
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    checkpoint-metadata    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-metadata-ok

Auto Prune On Create
    [Documentation]    Verify auto-prune on checkpoint creation
    [Tags]    phase2    checkpoint    prune
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    auto-prune-create    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    auto-prune-create-ok

Checkpoint Spec Fields
    [Documentation]    Verify spec-aligned fields: decision_id, checkpoint_type, resource_id, filesystem_path, size_bytes
    [Tags]    phase2    checkpoint    spec
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    checkpoint-spec-fields    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-spec-fields-ok

Correction Service With Checkpoint
    [Documentation]    Verify correction service accepts checkpoint_service
    [Tags]    phase2    checkpoint    correction
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    correction-checkpoint    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    correction-checkpoint-ok
