*** Settings ***
Documentation    M4 correction + subplan lifecycle E2E smoke tests via CLI
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment With Database Isolation
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
M4 Correction Revert Via CLI
    [Documentation]    Invoke plan correct --mode revert and verify success
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    correction-revert    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    m4-correction-revert-ok

M4 Correction Append Via CLI
    [Documentation]    Invoke plan correct --mode append and verify success
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    correction-append    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    m4-correction-append-ok

M4 Correction Dry Run Via CLI
    [Documentation]    Invoke plan correct --dry-run and verify impact output
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    correction-dry-run    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    m4-correction-dry-run-ok

M4 Subplan Status Sequential
    [Documentation]    Verify plan status shows subplan count for sequential config
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    subplan-status-sequential    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    m4-subplan-status-sequential-ok

M4 Subplan Status Parallel
    [Documentation]    Verify plan status shows subplan count for parallel config
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    subplan-status-parallel    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    m4-subplan-status-parallel-ok

M4 Failure Handler Evaluation
    [Documentation]    Evaluate SubplanFailureHandler decisions
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    failure-handler    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    m4-failure-handler-ok

M4 Fixture Loading
    [Documentation]    Load all M4 fixture files and verify structure
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    fixture-loading    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    m4-fixture-loading-ok

M4 Full Correction And Subplan Flow
    [Documentation]    End-to-end: correction revert + subplan status + failure handler
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    full-flow    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    m4-full-flow-ok
