*** Settings ***
Documentation    Integration tests for devcontainer handler CLI round-trip and DAG hierarchy
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
DevcontainerHandler Protocol Conformance
    [Documentation]    Verify DevcontainerHandler satisfies ResourceHandler protocol
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    protocol-check    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    protocol-check-ok

DevcontainerHandler Default Strategy
    [Documentation]    Verify DevcontainerHandler uses snapshot strategy
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    strategy-check    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    strategy-check-ok

Devcontainer Discovery Valid Config
    [Documentation]    Discover devcontainer from directory with valid config
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discovery-valid    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    discovery-valid-ok

Devcontainer Discovery Invalid JSON
    [Documentation]    Skip invalid devcontainer.json during discovery
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discovery-invalid    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    discovery-invalid-ok

Devcontainer Discovery Root Config
    [Documentation]    Discover root-level .devcontainer.json
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discovery-root    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    discovery-root-ok

Devcontainer Discovery Non-Trigger Type
    [Documentation]    No discovery for non-trigger resource types
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discovery-nontrigger    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    discovery-nontrigger-ok

Builtin Types Include Devcontainer
    [Documentation]    Verify devcontainer types in BUILTIN_NAMES
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    builtin-types    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    builtin-types-ok

DAG Hierarchy Validation
    [Documentation]    Verify devcontainer type parent/child DAG constraints
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    dag-hierarchy    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    dag-hierarchy-ok

Handler Resolver Dynamic Import
    [Documentation]    Verify resolve_handler loads DevcontainerHandler dynamically
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    resolver-import    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    resolver-import-ok

Discovery Result Validation
    [Documentation]    Verify DevcontainerDiscoveryResult validates inputs
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    result-validation    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    result-validation-ok

Devcontainer Discovery Named Single Config
    [Documentation]    Discover a single named devcontainer configuration
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discovery-named-single    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    discovery-named-single-ok

Devcontainer Discovery Named Multiple Configs
    [Documentation]    Discover multiple named devcontainer configurations
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discovery-named-multiple    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    discovery-named-multiple-ok

Devcontainer Discovery Named Mixed Root And Named
    [Documentation]    Discover mixed root and named devcontainer configurations
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discovery-named-mixed    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    discovery-named-mixed-ok

Devcontainer Discovery Named Config Name Attribute
    [Documentation]    Verify config_name attribute on DevcontainerDiscoveryResult
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discovery-named-config-name-attr    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    discovery-named-config-name-attr-ok
