*** Settings ***
Documentation    Integration smoke tests for ACMS Strategy Coordinator and Fusion Engine
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
StrategyCoordinator Coordinates Strategies
    [Documentation]    StrategyCoordinator selects, allocates, and executes strategies
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    coord-basic    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    coord-basic-ok

StrategyCoordinator Budget Allocation
    [Documentation]    StrategyCoordinator allocates budget proportionally to confidence
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    coord-budget    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    coord-budget-ok

StrategyCoordinator Per-Strategy Max Caps
    [Documentation]    StrategyCoordinator enforces per-strategy max token caps
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    coord-caps    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    coord-caps-ok

StrategyCoordinator Circuit Breaker
    [Documentation]    StrategyCoordinator reports circuit-broken strategies
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    coord-circuit    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    coord-circuit-ok

FusionEngine Dedup
    [Documentation]    FusionEngine deduplicates fragments by URI + content hash
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    fuse-dedup    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    fuse-dedup-ok

FusionEngine Depth Resolution
    [Documentation]    FusionEngine resolves detail depth conflicts
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    fuse-depth    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    fuse-depth-ok

FusionEngine Knapsack Packing
    [Documentation]    FusionEngine packs fragments within budget using greedy knapsack
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    fuse-pack    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    fuse-pack-ok

FusionEngine Budget Overage Guard
    [Documentation]    FusionEngine drops lowest-relevance fragments on budget overage
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    fuse-overage    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    fuse-overage-ok

Integration Coordinator Then Fusion
    [Documentation]    StrategyCoordinator output feeds into FusionEngine
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    integration    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    integration-ok
