*** Settings ***
Documentation    End-to-end tests for ComponentResolver with 3-level scope chain
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
ComponentResolver Global Default Resolution
    [Documentation]    Verify global default is resolved when no overrides exist
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    global-default    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    component-resolver-global-ok

ComponentResolver Project Override
    [Documentation]    Verify project-level override takes precedence over global
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    project-override    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    component-resolver-project-override-ok

ComponentResolver Plan Override
    [Documentation]    Verify plan-level override takes highest precedence
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    plan-override    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    component-resolver-plan-override-ok

ComponentResolver Fallthrough To Global
    [Documentation]    Verify fallthrough when no plan or project override matches
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    fallthrough    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    component-resolver-fallthrough-ok

ComponentResolver Missing Component Error
    [Documentation]    Verify ComponentNotFoundError for unregistered components
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    not-found    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    component-resolver-not-found-ok

ComponentResolver Caching Behavior
    [Documentation]    Verify resolution results are cached
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    caching    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    component-resolver-caching-ok

ComponentResolver Security Module Prefix
    [Documentation]    Verify disallowed module prefixes are rejected
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    security    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    component-resolver-security-ok

ComponentResolver Introspection APIs
    [Documentation]    Verify list_global_types, list_project_types, list_plan_types
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    introspection    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    component-resolver-introspection-ok

ComponentResolver Clear All
    [Documentation]    Verify clear removes all registrations
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    clear    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    component-resolver-clear-ok
