*** Settings ***
Documentation    Smoke tests for Invariant CLI commands
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Invariant Add Global
    [Documentation]    Verify that ``invariant add --global`` creates a global invariant
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-global    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-add-global-ok

Invariant Add Project
    [Documentation]    Verify that ``invariant add --project`` creates a project invariant
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-project    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-add-project-ok

Invariant Add Plan
    [Documentation]    Verify that ``invariant add --plan`` creates a plan invariant
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-plan    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-add-plan-ok

Invariant Add Action
    [Documentation]    Verify that ``invariant add --action`` creates an action invariant
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-action    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-add-action-ok

Invariant List Empty
    [Documentation]    Verify that ``invariant list`` works when no invariants exist
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    list-empty    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-list-empty-ok

Invariant List With Filter
    [Documentation]    Verify that ``invariant list --global`` filters by scope
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    list-filter    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-list-filter-ok

Invariant Remove
    [Documentation]    Verify that ``invariant remove --yes`` soft-deletes
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    remove    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-remove-ok

Invariant Scope Conflict Rejected
    [Documentation]    Verify that conflicting scope flags are rejected
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    scope-conflict    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-scope-conflict-ok

Invariant Add Missing Scope Rejected
    [Documentation]    Verify that ``invariant add`` fails when no scope flag is provided
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-no-scope    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-add-no-scope-ok

Invariant List JSON Format
    [Documentation]    Verify that ``invariant list --format json`` outputs JSON
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    list-json    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-list-json-ok
