*** Settings ***
Documentation    Agent Skills discovery integration tests
Library          OperatingSystem
Library          Collections
Library          helper_skill_discovery.py
Variables        ${CURDIR}/common_vars.py

*** Test Cases ***

Parse Single Agent Skills Path
    [Documentation]    Parse a single comma-separated path string
    ${paths}=    Parse Agent Skills Paths    /opt/skills
    Length Should Be    ${paths}    1

Parse Multiple Agent Skills Paths
    [Documentation]    Parse multiple comma-separated paths
    ${paths}=    Parse Agent Skills Paths    /opt/skills,/home/user/skills
    Length Should Be    ${paths}    2

Parse Empty Agent Skills Paths
    [Documentation]    Empty string returns no paths
    ${paths}=    Parse Agent Skills Paths    ${EMPTY}
    Length Should Be    ${paths}    0

Discover Agent Skills From Directory
    [Documentation]    Scan a temp directory with SKILL.md folders
    ${tmpdir}=    Create Agent Skills Directory    2
    ${discovered}=    Scan Agent Skills Directory    ${tmpdir}
    Length Should Be    ${discovered}    2
    Cleanup Temp Directory    ${tmpdir}

Discover Agent Skills Skips Folders Without SKILL MD
    [Documentation]    Directories without SKILL.md are skipped
    ${tmpdir}=    Create Mixed Directory
    ${discovered}=    Scan Agent Skills Directory    ${tmpdir}
    Length Should Be    ${discovered}    1
    Cleanup Temp Directory    ${tmpdir}

Build ToolSpec From Discovered Skill
    [Documentation]    Build a ToolSpec with agent_skills source metadata
    ${spec}=    Build Agent Skill ToolSpec    my-tool    /opt/skills/my-tool
    Should Be Equal    ${spec.name}    agent_skills/my-tool
    Should Be Equal    ${spec.source}    agent_skills
    Dictionary Should Contain Key    ${spec.source_metadata}    path

Register Discovered Skills Without Conflicts
    [Documentation]    Register skills in an empty ToolRegistry
    ${result}=    Register Agent Skills In Fresh Registry    3
    Should Be Equal As Integers    ${result}[registered_count]    3
    Should Be Equal As Integers    ${result}[conflict_count]    0

Register Discovered Skills With Conflict Skip
    [Documentation]    Name collisions are skipped with skip strategy
    ${result}=    Register Agent Skills With Collision    skip
    Should Be Equal As Integers    ${result}[registered_count]    0
    Should Be Equal As Integers    ${result}[conflict_count]    1

Register Discovered Skills With Conflict Replace
    [Documentation]    Name collisions are replaced with replace strategy
    ${result}=    Register Agent Skills With Collision    replace
    Should Be Equal As Integers    ${result}[registered_count]    1
    Should Be Equal As Integers    ${result}[conflict_count]    1

Config Key Registered
    [Documentation]    skills.agent_skills_paths config key exists
    ${entry}=    Get Config Entry    skills.agent_skills_paths
    Should Not Be Equal    ${entry}    ${None}
    Should Be Equal    ${entry.env_var}    CLEVERAGENTS_SKILLS_AGENT_SKILLS_PATHS
