*** Settings ***
Documentation    Smoke tests for CLI --format flag parity (json/yaml/plain/table/rich)
...              and global --format flag propagation to subcommands.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Action List Format JSON Outputs Valid JSON
    [Documentation]    Verify that ``action list --format json`` emits parseable JSON
    [Tags]    tdd_issue    tdd_issue_4206    tdd_expected_fail
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    action-list-json    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-formats-action-list-json-ok

Action Show Format YAML Outputs Valid YAML
    [Documentation]    Verify that ``action show --format yaml`` emits parseable YAML
    [Tags]    tdd_issue    tdd_issue_4206    tdd_expected_fail
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    action-show-yaml    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-formats-action-show-yaml-ok

Plan Lifecycle List Format JSON Outputs Valid JSON
    [Documentation]    Verify that ``plan list --format json`` emits JSON
    [Tags]    tdd_issue    tdd_issue_4206    tdd_expected_fail
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-list-json    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-formats-plan-list-json-ok

Plan Status Format Plain Outputs Key-Value Pairs
    [Documentation]    Verify that ``plan status <id> --format plain`` emits plain text
    [Tags]    tdd_issue    tdd_issue_4206
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-status-plain    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-formats-plan-status-plain-ok

# ---------------------------------------------------------------------------
# Global --format flag propagation tests (Issue #2908)
# ---------------------------------------------------------------------------

Global Format Flag JSON Propagates To Version Command
    [Documentation]    Verify that global ``--format json`` propagates to the version command
    [Tags]    tdd_issue    tdd_issue_4206    tdd_expected_fail
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    global-format-json-version    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-global-format-json-version-ok

Global Format Flag YAML Propagates To Version Command
    [Documentation]    Verify that global ``--format yaml`` propagates to the version command
    [Tags]    tdd_issue    tdd_issue_4206    tdd_expected_fail
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    global-format-yaml-version    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-global-format-yaml-version-ok

Global Format Flag Plain Propagates To Version Command
    [Documentation]    Verify that global ``--format plain`` propagates to the version command
    [Tags]    tdd_issue    tdd_issue_4206
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    global-format-plain-version    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-global-format-plain-version-ok

Global Format Flag JSON Propagates To Info Command
    [Documentation]    Verify that global ``--format json`` propagates to the info command
    [Tags]    tdd_issue    tdd_issue_4206
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    global-format-json-info    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-global-format-json-info-ok

Global Format Flag JSON Propagates To Diagnostics Command
    [Documentation]    Verify that global ``--format json`` propagates to the diagnostics command
    [Tags]    tdd_issue    tdd_issue_4206
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    global-format-json-diagnostics    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-global-format-json-diagnostics-ok

Global Format Shorthand Flag Works
    [Documentation]    Verify that global ``-f json`` shorthand propagates to the version command
    [Tags]    tdd_issue    tdd_issue_4206    tdd_expected_fail
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    global-format-shorthand    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-global-format-shorthand-ok

All Six Formats Work With Version Command
    [Documentation]    Verify all six output formats work via the global --format flag
    [Tags]    tdd_issue    tdd_issue_4206
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    global-format-all-six    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    cli-global-format-all-six-ok
