*** Settings ***
Documentation    Smoke tests for Skill flattening, capability summaries, and plan validation
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Flatten Simple Skill With Tool Refs
    [Documentation]    Flatten a skill with 5 tool refs and verify deterministic order
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    flatten-simple    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-simple-ok

Flatten Skill With Deep Includes
    [Documentation]    Flatten skill with 3 levels of includes in depth-first order
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    flatten-deep    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-deep-ok

Flatten Skill With Wide Includes
    [Documentation]    Flatten skill including 10 other skills
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    flatten-wide    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-wide-ok

Flatten Skill With Inline Tools
    [Documentation]    Flatten a skill with inline tools and verify keying
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    flatten-inline    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-inline-ok

Flatten Skill With Cycle Raises Error
    [Documentation]    Detect cycles in include chains and report clear error path
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    flatten-cycle    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-cycle-ok

Flatten Skill With Per-Include Overrides
    [Documentation]    Apply per-include overrides to included tool entries
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    flatten-include-overrides    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-include-overrides-ok

Flatten Skill Rejects Non-Overridable Fields
    [Documentation]    Reject overrides on non-overridable fields (name, source_skill, is_inline)
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    flatten-non-overridable    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-non-overridable-ok

Compute Capability Summary
    [Documentation]    Compute capability summary with diverse inline tools
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    capability-summary    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-capability-summary-ok

Tools Method Returns Entries And Summary
    [Documentation]    SkillRegistry.tools() returns both entries and summary
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    tools-method    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-tools-method-ok

Validate Plan With Valid Skills
    [Documentation]    validate_plan with a valid plan returns empty error list
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validate-plan-ok    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-validate-plan-ok

Validate Plan With Missing Skill
    [Documentation]    validate_plan reports error for missing skill
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    validate-plan-missing    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    flatten-validate-plan-missing-ok
