*** Settings ***
Documentation     Integration tests for sandbox boundary algebra: sandbox_boundary(),
...               compute_sandbox_domains(), BoundaryCache, and SandboxManager
...               boundary-aware keying.
...               Covers M6 sandbox boundary algebra (#548).
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

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

*** Test Cases ***
Sandbox Boundary Walk To Nearest Sandboxable Ancestor
    [Documentation]    Verify sandbox_boundary() walks containment edges to nearest sandboxable resource
    [Tags]    sandbox    boundary    walk
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    boundary-walk    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    boundary-walk-ok

Domain Grouping Partitions Resources By Boundary
    [Documentation]    Verify compute_sandbox_domains() groups resources by sandbox boundary
    [Tags]    sandbox    boundary    domains
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    domain-grouping    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    domain-grouping-ok

Boundary Cache Stores And Retrieves Results
    [Documentation]    Verify BoundaryCache caches boundary lookups for plan execution
    [Tags]    sandbox    boundary    cache
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    boundary-cache    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    boundary-cache-ok

Manager Keys Sandboxes By Boundary ID
    [Documentation]    Verify SandboxManager resolves keys via boundary algebra so child resources share sandbox
    [Tags]    sandbox    boundary    manager
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    manager-boundary-keying    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    manager-boundary-keying-ok

Multi Resource Plan With Separate Sandbox Domains
    [Documentation]    Verify multi-resource plan with different boundaries creates separate sandboxes
    [Tags]    sandbox    boundary    multi
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    multi-resource-plan    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    multi-resource-plan-ok
