*** Settings ***
Documentation     Smoke tests for correction flows: revert, append, dry-run,
...               impact analysis, cancellation, and error handling.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Revert Simple Correction
    [Documentation]    Verify simple revert invalidates target decision
    [Tags]    phase2    correction    flows    revert
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    revert-simple    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    revert-simple-ok

Revert Deep Subtree
    [Documentation]    Verify revert walks full BFS subtree
    [Tags]    phase2    correction    flows    revert
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    revert-deep-subtree    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    revert-deep-subtree-ok

Append Correction
    [Documentation]    Verify append spawns a child plan
    [Tags]    phase2    correction    flows    append
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    append-correction    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    append-correction-ok

Dry Run Report Generation
    [Documentation]    Verify dry-run report contains expected fields
    [Tags]    phase2    correction    flows    dryrun
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    dry-run-report    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    dry-run-report-ok

Impact Analysis Risk Levels
    [Documentation]    Verify risk classification low / high thresholds
    [Tags]    phase2    correction    flows    impact
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    impact-risk-levels    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    impact-risk-levels-ok

Cancel Correction
    [Documentation]    Verify pending correction can be cancelled
    [Tags]    phase2    correction    flows    cancel
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    cancel-correction    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cancel-correction-ok

Execute Already Cancelled Error
    [Documentation]    Verify executing a cancelled correction raises error
    [Tags]    phase2    correction    flows    error
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    execute-cancelled-error    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    execute-cancelled-error-ok

List Corrections By Plan
    [Documentation]    Verify listing corrections filters by plan_id
    [Tags]    phase2    correction    flows    query
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    list-corrections-by-plan    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    list-corrections-by-plan-ok
