*** Settings ***
Documentation     Integration tests for revert-mode re-execution from decision point.
...               Validates checkpoint restoration, actor state recovery, phase
...               transition signalling, and selective subtree recomputation.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Revert With Checkpoint Restores Sandbox
    [Documentation]    Verify revert delegates to CheckpointService when available
    [Tags]    phase2    correction    revert    re-execution
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    revert-with-checkpoint    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    revert-with-checkpoint-ok

Revert Without Checkpoint Skips Restoration
    [Documentation]    Verify revert works without checkpoint service
    [Tags]    phase2    correction    revert    re-execution
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    revert-no-checkpoint    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    revert-no-checkpoint-ok

Revert Extracts Actor State Ref
    [Documentation]    Verify actor state reference is extracted from decision
    [Tags]    phase2    correction    revert    re-execution
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    revert-actor-state    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    revert-actor-state-ok

Revert Signals Phase Transition
    [Documentation]    Verify revert signals Strategize re-entry
    [Tags]    phase2    correction    revert    re-execution
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    revert-phase-transition    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    revert-phase-transition-ok

Revert Creates User Intervention Decision
    [Documentation]    Verify user_intervention decision ID is generated
    [Tags]    phase2    correction    revert    re-execution
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    revert-intervention-id    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    revert-intervention-id-ok

Full Revert Re Execution Flow
    [Documentation]    End-to-end revert with checkpoint + actor state + phase transition
    [Tags]    phase2    correction    revert    re-execution    e2e
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    full-revert-flow    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    full-revert-flow-ok

Revert Selective Subtree Only
    [Documentation]    Verify only downstream decisions are affected
    [Tags]    phase2    correction    revert    re-execution    subtree
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    revert-selective-subtree    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    revert-selective-subtree-ok
