*** Settings ***
Documentation     Integration tests for LSP resource types: executable,
...               lsp-server, lsp-workspace, lsp-document.
...               Spec reference: ADR-039, ADR-040
...               Issue: #832
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

*** Variables ***
${HELPER}    robot/helper_resource_type_lsp.py

*** Test Cases ***
LSP Resource Types Are Importable
    [Documentation]    Verify LSP_RESOURCE_TYPES can be imported from the data module
    [Tags]    lsp    resource    import
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    import-lsp-types    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0    Import failed: ${result.stderr}
    Should Contain    ${result.stdout}    import-lsp-types-ok

LSP Types Present In BUILTIN_NAMES
    [Documentation]    Verify all 4 LSP types are in BUILTIN_NAMES
    [Tags]    lsp    resource    builtin
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    check-builtin-names    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0    BUILTIN_NAMES check failed: ${result.stderr}
    Should Contain    ${result.stdout}    check-builtin-names-ok

LSP Types Survive DB Bootstrap Roundtrip
    [Documentation]    Bootstrap in-memory DB and verify all 4 LSP types are retrievable
    [Tags]    lsp    resource    bootstrap    database
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    db-roundtrip    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0    DB roundtrip failed: ${result.stderr}
    Should Contain    ${result.stdout}    db-roundtrip-ok

LSP Type Hierarchy Is Correct
    [Documentation]    Verify parent/child relationships: server->workspace->document
    [Tags]    lsp    resource    hierarchy
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    check-hierarchy    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0    Hierarchy check failed: ${result.stderr}
    Should Contain    ${result.stdout}    check-hierarchy-ok

Executable Has Auto-Discovery Configuration
    [Documentation]    Verify executable type has auto_discovery with trigger_types
    [Tags]    lsp    resource    discovery
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    check-auto-discovery    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0    Discovery check failed: ${result.stderr}
    Should Contain    ${result.stdout}    check-auto-discovery-ok

Non-User-Addable LSP Types Reject Manual Registration
    [Documentation]    Verify lsp-workspace and lsp-document reject manual registration
    [Tags]    lsp    resource    guard
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    check-user-addable-guard    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0    User-addable guard failed: ${result.stderr}
    Should Contain    ${result.stdout}    check-user-addable-guard-ok
