*** Settings ***
Documentation    Regression guard tests for bug #647 - Container.resolve() crash
...              Three CLI commands (plan tree, plan explain, plan correct)
...              are regression-guarded after the historical
...              Container.resolve() crash was fixed.
...
...              These tests use a REAL DI container (not MagicMock).
...              Existing M3 tests missed this class of issue because
...              they mock get_container() with MagicMock which auto-creates
...              any attribute.
...
...              NOTE: Bug #647 appears fixed; these tests now run as normal
...              regression checks for correct command behavior.
...
...              Tags: tdd_issue, tdd_issue_647
Resource         ${CURDIR}/common.resource
Suite Setup      Run Keywords    Setup Test Environment    AND    Setup Database Isolation
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Plan Tree Regression Guard For Container.resolve()
    [Documentation]    Regression guard: plan tree should run without resolve() crash
    [Tags]    tdd_issue    tdd_issue_647
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-tree-crash    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Run Keyword If    ${result.rc} == 2    Fail    Unexpected non-AttributeError failure: ${result.stderr}
    # Helper exits 0 only when command behaves correctly.
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    plan-tree-crash-ok

Plan Explain Regression Guard For Container.resolve()
    [Documentation]    Regression guard: plan explain should run without resolve() crash
    [Tags]    tdd_issue    tdd_issue_647
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-explain-crash    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Run Keyword If    ${result.rc} == 2    Fail    Unexpected non-AttributeError failure: ${result.stderr}
    # Helper exits 0 only when command behaves correctly.
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    plan-explain-crash-ok

Plan Correct Regression Guard For Container.resolve()
    [Documentation]    Regression guard: plan correct should run without resolve() crash
    [Tags]    tdd_issue    tdd_issue_647
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-correct-crash    cwd=${WORKSPACE}    timeout=120s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Run Keyword If    ${result.rc} == 2    Fail    Unexpected non-AttributeError failure: ${result.stderr}
    # Helper exits 0 only when command behaves correctly.
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    plan-correct-crash-ok
