*** Settings ***
Documentation    TDD Issue #1022 — InvariantService invariants lost across CLI invocations
...              Integration tests verifying that invariants added via the CLI
...              persist across simulated process restarts.  InvariantService
...              stores invariants in an in-memory dict only, so each CLI
...              invocation starts with an empty service.  These tests exercise
...              add-then-list and add-then-remove across fresh service
...              instances.  They fail until the bug is fixed; the
...              tag inverts the result so CI passes.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
TDD Invariant Add Then List Project Across Invocations
    [Documentation]    Add a project invariant in invocation 1, list in invocation 2.
    [Tags]  tdd_issue    tdd_issue_1022    tdd_issue    tdd_issue_4318    tdd_expected_fail

    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-then-list-project    cwd=${WORKSPACE}    timeout=30s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-persist-project-ok

TDD Invariant Add Then List Global Across Invocations
    [Documentation]    Add a global invariant in invocation 1, list in invocation 2.
    [Tags]  tdd_issue    tdd_issue_1022    tdd_issue    tdd_issue_4318    tdd_expected_fail

    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-then-list-global    cwd=${WORKSPACE}    timeout=30s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-persist-global-ok

TDD Invariant Remove Cross Instance
    [Documentation]    Add invariant in instance 1, remove by ID in instance 2.
    [Tags]  tdd_issue    tdd_issue_1022    tdd_issue    tdd_issue_4318    tdd_expected_fail

    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-then-remove-cross    cwd=${WORKSPACE}    timeout=30s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    invariant-cross-remove-ok
