*** Settings ***
Documentation    Smoke tests for Skill CLI commands (add, show, tools, list, remove)
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Skill Add Config Registers Skill
    [Documentation]    Verify that ``skill add --config`` registers a skill
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-config    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    skill-cli-add-config-ok

Skill Add Duplicate Fails Without Update
    [Documentation]    Verify that adding a duplicate skill fails without ``--update``
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-duplicate-fails    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    skill-cli-add-duplicate-fails-ok

Skill Add Update Overwrites Existing
    [Documentation]    Verify that ``skill add --update`` overwrites an existing skill
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    add-update    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    skill-cli-add-update-ok

Skill Show Displays Details
    [Documentation]    Verify that ``skill show`` displays skill details
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    show-skill    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    skill-cli-show-ok

Skill Tools Shows Flattened List
    [Documentation]    Verify that ``skill tools`` shows the flattened tool list
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    tools-skill    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    skill-cli-tools-ok

Skill List Shows All Skills
    [Documentation]    Verify that ``skill list`` shows all registered skills
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    list-skills    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    skill-cli-list-ok

Skill Remove Deletes Skill
    [Documentation]    Verify that ``skill remove --yes`` removes a skill
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    remove-skill    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    skill-cli-remove-ok

Skill Refresh Single Skill
    [Documentation]    Verify that ``skill refresh <name>`` recomputes tool flattening
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    refresh-skill    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    skill-cli-refresh-ok

Skill Refresh All Skills
    [Documentation]    Verify that ``skill refresh --all`` refreshes all skills
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    refresh-all    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    skill-cli-refresh-all-ok
