*** Settings ***
Documentation    Integration tests for real checkpoint rollback via git reset --hard.
...              Verifies that CheckpointService.rollback_to_checkpoint() actually
...              restores file system state by executing git reset --hard in the
...              sandbox working directory.  Covers file reversion, file removal,
...              domain event emission, and sandbox boundary enforcement.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Checkpoint Rollback Restores Modified File Content
    [Documentation]    Create files, checkpoint, modify, rollback, verify original content restored.
    [Tags]    checkpoint    rollback    git
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    rollback-restores-content    cwd=${WORKSPACE}    timeout=30s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-rollback-restores-content-ok

Checkpoint Rollback Removes Files Added After Checkpoint
    [Documentation]    Create files, checkpoint, add new file, rollback, verify new file removed.
    [Tags]    checkpoint    rollback    git
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    rollback-removes-added-files    cwd=${WORKSPACE}    timeout=30s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-rollback-removes-added-files-ok

Checkpoint Rollback Emits Domain Event
    [Documentation]    Verify that rollback emits a CHECKPOINT_RESTORED domain event.
    [Tags]    checkpoint    rollback    event
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    rollback-emits-event    cwd=${WORKSPACE}    timeout=30s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-rollback-emits-event-ok

Checkpoint Rollback Rejects Nonexistent Sandbox
    [Documentation]    Verify that rollback rejects a sandbox path that does not exist.
    [Tags]    checkpoint    rollback    boundary
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    rollback-rejects-nonexistent-sandbox    cwd=${WORKSPACE}    timeout=30s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-rollback-rejects-nonexistent-sandbox-ok
