*** Settings ***
Documentation    Smoke tests for LSP server stub startup and protocol
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
LSP Server Initialize Handshake
    [Documentation]    Send initialize request and verify response
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    initialize    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    lsp-initialize-ok

LSP Server Shutdown Handshake
    [Documentation]    Send initialize, shutdown, exit and verify clean exit
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    shutdown    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    lsp-shutdown-ok

LSP Server Unsupported Method
    [Documentation]    Send unsupported method and verify MethodNotFound error
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    unsupported    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    lsp-unsupported-ok

LSP Server Startup Reports PID
    [Documentation]    Verify server startup reports PID
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    startup-pid    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    lsp-startup-pid-ok

LSP Server Full Lifecycle
    [Documentation]    Complete lifecycle: initialize, shutdown, exit
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    full-lifecycle    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    lsp-full-lifecycle-ok
