*** Settings ***
Documentation    End-to-end smoke tests for action -> plan -> execute -> apply lifecycle via CLI helpers
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Action Create From Config Via CLI
    [Documentation]    Create an action from a YAML config file and verify it succeeds
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    action-create    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-lifecycle-action-create-ok

Plan Use Creates Plan In Strategize Phase
    [Documentation]    Use an action to create a plan in Strategize phase
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-use    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-lifecycle-plan-use-ok

Plan Execute Transitions To Execute Phase
    [Documentation]    Execute a plan, transitioning from Strategize to Execute
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-execute    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-lifecycle-plan-execute-ok

Plan Lifecycle Apply Transitions To Apply Phase
    [Documentation]    Apply a plan, transitioning from Execute to Apply
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-apply    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-lifecycle-plan-apply-ok

Plan Status Shows Plan Details
    [Documentation]    Verify plan status renders plan details
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-status    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-lifecycle-plan-status-ok

Plan Cancel Cancels Non-Terminal Plan
    [Documentation]    Cancel a non-terminal plan
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-cancel    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-lifecycle-plan-cancel-ok

Full Lifecycle Action To Apply
    [Documentation]    End-to-end: create action, use it, execute, apply
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    full-lifecycle    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-lifecycle-full-e2e-ok

Plan Lifecycle List Shows Plans
    [Documentation]    Verify list renders plan table
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-list    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-lifecycle-plan-list-ok

Plan List Namespace Option Filters By Namespace
    [Documentation]    Verify agents plan list --namespace myteam returns only plans in that namespace
    [Tags]    tdd_issue    tdd_issue_4301

    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-list-namespace    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-lifecycle-plan-list-namespace-ok

Plan List Short Namespace Option Works
    [Documentation]    Verify agents plan list -n myteam short-form alias works correctly
    [Tags]    tdd_issue    tdd_issue_4301

    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-list-namespace-short    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-lifecycle-plan-list-namespace-short-ok
