*** Settings ***
Documentation    End-to-end Robot suite for CLI lifecycle: action -> plan -> execute -> apply
...              with git_worktree sandbox simulation and ChangeSet capture verification.
...              Also includes negative tests for invalid project names, missing resources,
...              and invalid --arg values.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Action Create Via Config CLI
    [Documentation]    Create an action from a YAML config and verify success
    [Tags]    cli    lifecycle    positive    tdd_issue    tdd_issue_4207
    ${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}    robot-lifecycle-action-create-ok

Plan Use Creates Strategize Plan With Sandbox
    [Documentation]    Use an action with simulated git_worktree sandbox workspace
    [Tags]    cli    lifecycle    sandbox    positive    tdd_issue    tdd_issue_4207
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-use-sandbox    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    robot-lifecycle-plan-use-sandbox-ok

Plan Execute With ChangeSet Capture
    [Documentation]    Execute plan and verify ChangeSet entry is captured
    [Tags]    cli    lifecycle    changeset    positive    tdd_issue    tdd_issue_4207
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-execute-changeset    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    robot-lifecycle-plan-execute-changeset-ok

Plan Apply With ChangeSet Verification
    [Documentation]    Apply plan and verify ChangeSet summary (creates + modifies)
    [Tags]    cli    lifecycle    changeset    positive    tdd_issue    tdd_issue_4207
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-apply-changeset    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    robot-lifecycle-plan-apply-changeset-ok

Full Lifecycle Action To Apply With Sandbox
    [Documentation]    End-to-end: create action, use, execute, apply with sandbox + changeset
    [Tags]    cli    lifecycle    e2e    positive
    ${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}    robot-lifecycle-full-e2e-sandbox-ok

Invalid Project Name Rejected
    [Documentation]    Verify that an invalid project name format is handled gracefully
    [Tags]    cli    lifecycle    negative    tdd_issue    tdd_issue_4207
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    invalid-project-name    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    robot-lifecycle-invalid-project-name-ok

Missing Resource Returns Error
    [Documentation]    Verify that a non-existent action returns an appropriate error
    [Tags]    cli    lifecycle    negative    tdd_issue    tdd_issue_4207
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    missing-resource    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    robot-lifecycle-missing-resource-ok

Invalid Arg Format Rejected
    [Documentation]    Verify that --arg without '=' separator is rejected
    [Tags]    cli    lifecycle    negative    tdd_issue    tdd_issue_4207
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    invalid-arg-format    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    robot-lifecycle-invalid-arg-format-ok
