*** Settings ***
Documentation    Bug #968 — plan explain expects decision_id but M3 test passes plan_id
...              Integration tests verifying that ``plan explain <plan_id>`` succeeds
...              when given a plan ID rather than a decision ID.  Bug #968 has been fixed:
...              the command now correctly resolves a plan_id to its decisions.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment With Database Isolation
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
TDD Plan Explain Succeeds With Plan ID
    [Documentation]    Verify that ``plan explain <plan_id>`` exits with rc=0
    ...                when given a plan ID that has associated decisions.
    ...                Bug #968: the command currently exits with rc=1.
    [Tags]  tdd_issue    tdd_issue_968    tdd_issue_4178
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    explain-with-plan-id    cwd=${WORKSPACE}    timeout=180s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-plan-explain-plan-id-ok

TDD Plan Explain With Plan ID Shows Root Question
    [Documentation]    Verify that ``plan explain <plan_id>`` output contains
    ...                the root decision question when given a plan ID.
    ...                Bug #968: the command fails before rendering any output.
    [Tags]  tdd_issue    tdd_issue_968    tdd_issue_4178
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    explain-plan-id-shows-question    cwd=${WORKSPACE}    timeout=180s    on_timeout=kill
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-plan-explain-plan-id-question-ok
