*** Settings ***
Documentation    Integration tests for LSP functional runtime
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Transport Lifecycle Start And Stop
    [Documentation]    StdioTransport can start and stop a process
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    transport-lifecycle    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    transport-lifecycle-ok

Transport Rejects Empty Command
    [Documentation]    StdioTransport rejects empty command
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    transport-empty-command    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    transport-empty-command-ok

Lifecycle Manager Empty State
    [Documentation]    LspLifecycleManager starts with no servers
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    lifecycle-manager-empty    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    lifecycle-manager-empty-ok

Runtime Input Validation
    [Documentation]    LspRuntime validates inputs correctly
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    runtime-validation    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    runtime-validation-ok

Language Discovery
    [Documentation]    LanguageDiscovery detects languages from extensions
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    discovery    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    discovery-ok

Tool Adapter Modes
    [Documentation]    LspToolAdapter generates specs in both modes
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    tool-adapter-modes    cwd=${WORKSPACE}    on_timeout=kill    timeout=30s
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tool-adapter-modes-ok
