*** Settings ***
Documentation    Integration tests for Invariant Reconciliation Actor auto-invocation
...              Verifies that the reconciliation actor is automatically invoked during
...              plan lifecycle phase transitions and blocks transitions on failure.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Reconciliation Auto-Invocation At Strategize Start
    [Documentation]    Reconciliation runs automatically when start_strategize is called
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    strategize    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    autowire-strategize-ok
    Should Contain    ${result.stdout}    reconciliation_invoked

Reconciliation Auto-Invocation At Execute Transition
    [Documentation]    Reconciliation runs automatically at execute_plan transition
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    execute    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    autowire-execute-ok
    Should Contain    ${result.stdout}    reconciliation_invoked

Reconciliation Auto-Invocation At Apply Transition
    [Documentation]    Reconciliation runs automatically at apply_plan transition
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    apply    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    autowire-apply-ok
    Should Contain    ${result.stdout}    reconciliation_invoked

Reconciliation Blocks Transition On Failure
    [Documentation]    When reconciliation fails, the phase transition is blocked
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    block    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    autowire-block-ok
    Should Contain    ${result.stdout}    ReconciliationBlockedError

Reconciliation Skipped When Actor Unset
    [Documentation]    No reconciliation when invariant_actor is None
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    skip    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    autowire-skip-ok
    Should Contain    ${result.stdout}    reconciliation_skipped
