*** Settings ***
Documentation     End-to-end correction with influence DAG traversal.
...               Verifies that corrections cascade through both structural
...               tree edges and influence DAG (decision_dependencies) edges.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Structural Only Revert
    [Documentation]    Revert with only structural children
    [Tags]    phase2    correction    influence_dag
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    structural-only    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    structural-only-ok

Influence Only Revert
    [Documentation]    Revert with only influence DAG edges
    [Tags]    phase2    correction    influence_dag
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    influence-only    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    influence-only-ok

Combined Structural And Influence Revert
    [Documentation]    Revert traverses union of structural + influence edges
    [Tags]    phase2    correction    influence_dag
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    combined-revert    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    combined-revert-ok

Cycle Detection In Influence DAG
    [Documentation]    Corrupt cycle in influence DAG handled gracefully
    [Tags]    phase2    correction    influence_dag
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    cycle-detection    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cycle-detection-ok

Decision Creation Records Dependencies
    [Documentation]    record_decision with dependency_decision_ids populates DAG
    [Tags]    phase2    correction    influence_dag
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    record-deps    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    record-deps-ok

End To End Correction With Influence Cascade
    [Documentation]    Full flow: record decisions with deps, then revert cascades
    [Tags]    phase2    correction    influence_dag
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    e2e-cascade    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    e2e-cascade-ok
