*** Settings ***
Documentation    TDD Issue #967 — plan execute only transitions state, does not run
...              strategize or execute phase processing.  Integration smoke tests
...              exercising the CLI orchestration layer via real
...              PlanLifecycleService (in-memory) and PlanExecutor (stub actors)
...              to verify that a plan in Strategize/QUEUED state can be taken
...              through to Execute phase.  The bug fix is already in the
...              codebase; these tests serve as permanent regression guards.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment With Database Isolation
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
TDD CLI Execute Plan From Strategize QUEUED State
    [Documentation]    Verify that the CLI execute_plan handler correctly
    ...                orchestrates run_strategize before transitioning when
    ...                a plan is in Strategize/QUEUED state.
    ...                Bug #967: originally the CLI only called service.execute_plan().
    [Tags]  tdd_issue    tdd_issue_967    tdd_issue_4178
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    cli-execute-from-queued    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}    tdd-cli-execute-from-queued-ok

TDD CLI Execute Orchestrates Full Lifecycle
    [Documentation]    Verify that the CLI execute_plan handler calls both
    ...                run_strategize and run_execute for a QUEUED plan.
    ...                Bug #967: the CLI skipped PlanExecutor orchestration.
    [Tags]  tdd_issue    tdd_issue_967    tdd_issue_4178
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    cli-full-orchestration    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}    tdd-cli-full-orchestration-ok

TDD Positive Control Proper Orchestration
    [Documentation]    Positive control: verify that the proper service-level
    ...                orchestration path (run_strategize then execute_plan)
    ...                works correctly.
    [Tags]  tdd_issue    tdd_issue_967    tdd_issue_4178
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    proper-orchestration    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}    tdd-proper-orchestration-ok

TDD CLI Auto Discovery Includes QUEUED Plans
    [Documentation]    Verify that the CLI auto-discovery filter includes plans
    ...                in Strategize/QUEUED state, not just Strategize/COMPLETE.
    ...                Bug #967: the original filter excluded QUEUED plans.
    [Tags]  tdd_issue    tdd_issue_967    tdd_issue_4178
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    cli-auto-discovery    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}    tdd-cli-auto-discovery-ok
