*** Settings ***
Documentation    M3 decision tree, validation gating, and invariant enforcement 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_m3_decision_validation_smoke.py

*** Test Cases ***
M3 Invariant Add Global
    [Documentation]    Add a global invariant constraint via CLI
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    invariant-add-global    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}    m3-invariant-add-global-ok

M3 Invariant Add Project Scoped
    [Documentation]    Add a project-scoped invariant constraint via CLI
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    invariant-add-project    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}    m3-invariant-add-project-ok

M3 Invariant List
    [Documentation]    List invariants via CLI
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    invariant-list    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}    m3-invariant-list-ok

M3 Invariant Remove
    [Documentation]    Remove an invariant by ID via CLI
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    invariant-remove    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}    m3-invariant-remove-ok

M3 Validation Add From Config
    [Documentation]    Register a validation from YAML config via CLI
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validation-add    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}    m3-validation-add-ok

M3 Validation Attach
    [Documentation]    Attach a validation to a resource via CLI
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validation-attach    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}    m3-validation-attach-ok

M3 Validation Detach
    [Documentation]    Detach a validation from a resource via CLI
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validation-detach    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}    m3-validation-detach-ok

M3 Plan Correct Dry Run
    [Documentation]    Run plan correct in dry-run mode to preview correction impact
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-correct-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}    m3-plan-correct-dry-run-ok
