*** Settings ***
Documentation     Integration tests for custom sandbox strategy registration.
...               Covers SandboxStrategyProtocol, SandboxStrategyRegistry,
...               BuiltInSandboxStrategyAdapter, CustomStrategyConfig, and
...               SandboxFactory custom strategy integration.
...               Based on issue #586.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

*** Variables ***
${HELPER_SCRIPT}    robot/helper_custom_sandbox_strategy.py

*** Test Cases ***
SandboxRef Creation And Immutability
    [Documentation]    Verify SandboxRef creation, properties, and frozen semantics
    [Tags]    sandbox    strategy    ref
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    sandbox-ref-lifecycle    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    sandbox-ref-lifecycle-ok

DiffView And DiffEntry Models
    [Documentation]    Verify DiffView and DiffEntry creation and validation
    [Tags]    sandbox    strategy    diff
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    diff-view-lifecycle    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    diff-view-lifecycle-ok

SandboxStrategyProtocol Runtime Check
    [Documentation]    Verify SandboxStrategyProtocol is runtime_checkable with 9 methods
    [Tags]    sandbox    strategy    protocol
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    protocol-check    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    protocol-check-ok

SandboxStrategyRegistry Lifecycle
    [Documentation]    Verify registry register, lookup, config-driven, protocol validation, clear
    [Tags]    sandbox    strategy    registry
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    registry-lifecycle    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    registry-lifecycle-ok

BuiltInSandboxStrategyAdapter Full Lifecycle
    [Documentation]    Verify adapter create/read/write/diff/cleanup with real filesystem
    [Tags]    sandbox    strategy    adapter
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    adapter-lifecycle    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    adapter-lifecycle-ok

Adapter Checkpoint And Restore
    [Documentation]    Verify adapter checkpoint save and restore operations
    [Tags]    sandbox    strategy    adapter    checkpoint
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    adapter-checkpoint    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    adapter-checkpoint-ok

CustomStrategyConfig Validation
    [Documentation]    Verify CustomStrategyConfig rejects empty name, module, class_name
    [Tags]    sandbox    strategy    config
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    config-validation    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    config-validation-ok

SandboxFactory Custom Strategy Integration
    [Documentation]    Verify SandboxFactory with custom registry lookup
    [Tags]    sandbox    strategy    factory
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    factory-custom-integration    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    factory-custom-integration-ok
