*** Settings ***
Documentation    Smoke tests for actor YAML loader and discovery
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Discover Example Actors
    [Documentation]    Load all actors from examples/actors/ and verify count
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discover-examples    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    actor-count:

Discover Actors From Custom Directory
    [Documentation]    Discover actors from a temporary directory with a valid YAML
    ${tmp}=    Set Variable    ${TEMPDIR}${/}actor_loading_robot
    Run Keyword And Ignore Error    Remove Directory    ${tmp}    recursive=True
    Create Directory    ${tmp}
    Create File    ${tmp}${/}test.yaml    name: local/robot-test\ntype: llm\ndescription: Robot test actor\nversion: "1.0"\nmodel: gpt-4\n
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discover    ${tmp}    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    actor-loaded: local/robot-test
    Should Contain    ${result.stdout}    actor-count: 1

Reject Invalid Actor YAML
    [Documentation]    Attempt to discover from a directory with invalid YAML and assert failure
    ${tmp}=    Set Variable    ${TEMPDIR}${/}actor_loading_invalid
    Run Keyword And Ignore Error    Remove Directory    ${tmp}    recursive=True
    Create Directory    ${tmp}
    Create File    ${tmp}${/}bad.yaml    name: [\ninvalid yaml content\n
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discover-invalid    ${tmp}    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    actor-loading-expected-fail

Default Namespace Applied
    [Documentation]    Verify that actors without namespace get local/ prefix
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    namespace-default    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    namespace-default-ok: local/bare-name

Load Hierarchical Actor YAML Via Loader
    [Documentation]    Discover hierarchical_workflow.yaml via ActorLoader and verify graph properties
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discover-hierarchical    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    actor-loaded: workflows/dev-workflow
    Should Contain    ${result.stdout}    actor-type: graph
    Should Contain    ${result.stdout}    node-count: 3
    Should Contain    ${result.stdout}    edge-count: 2
