*** Settings ***
Documentation     Integration tests for plan resume functionality.
...               Covers resume eligibility validation, checkpoint recording,
...               dry-run preview, live resume, and graceful shutdown.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Resume Eligibility For Errored Plan
    [Documentation]    Verify errored plans are eligible for resume
    [Tags]    resume    eligibility    critical
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    eligibility-errored    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    eligibility-errored-ok

Resume Eligibility Rejects Terminal Plans
    [Documentation]    Verify applied/cancelled/constrained plans cannot be resumed
    [Tags]    resume    eligibility    terminal
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    eligibility-terminal    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    eligibility-terminal-ok

Record Step Checkpoints
    [Documentation]    Verify step-level checkpoints are recorded correctly
    [Tags]    resume    checkpoint
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    record-checkpoints    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    record-checkpoints-ok

Dry Run Resume Shows Resume Point
    [Documentation]    Verify dry-run shows resume summary without changing state
    [Tags]    resume    dry-run
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    dry-run-resume    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    dry-run-resume-ok

Live Resume Resets Errored Plan
    [Documentation]    Verify live resume transitions errored plan to processing
    [Tags]    resume    live    critical
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    live-resume    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    live-resume-ok

Graceful Shutdown Recording
    [Documentation]    Verify graceful shutdown marks metadata as interrupted
    [Tags]    resume    shutdown
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    graceful-shutdown    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    graceful-shutdown-ok

Resume Metadata Properties
    [Documentation]    Verify ResumeMetadata model computed properties
    [Tags]    resume    model
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    metadata-properties    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    metadata-properties-ok

Resume Summary CLI Dictionary
    [Documentation]    Verify ResumeSummary.as_cli_dict() returns correct keys
    [Tags]    resume    cli
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    summary-cli-dict    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    summary-cli-dict-ok

Resume Validation Errors
    [Documentation]    Verify proper error handling for invalid inputs
    [Tags]    resume    errors
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    validation-errors    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    validation-errors-ok

Resume Checkpoint With Sandbox Ref
    [Documentation]    Verify checkpoint records sandbox reference correctly
    [Tags]    resume    checkpoint    sandbox
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    checkpoint-sandbox    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    checkpoint-sandbox-ok
