*** Settings ***
Documentation    Integration smoke tests for ACMS v1 context assembly pipeline
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
Create Context Fragment
    [Documentation]    Create a ContextFragment and verify defaults
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    fragment-create    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    acms-fragment-ok

Calculate Budget Available Tokens
    [Documentation]    Create ContextBudget and verify available_tokens
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    budget-calc    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    acms-budget-ok

Assemble With Relevance Strategy
    [Documentation]    Assemble fragments with relevance strategy
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    assemble-relevance    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    acms-assemble-relevance-ok

Assemble With Recency Strategy
    [Documentation]    Assemble fragments with recency strategy
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    assemble-recency    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    acms-assemble-recency-ok

Assemble With Tiered Strategy
    [Documentation]    Assemble fragments with tiered strategy
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    assemble-tiered    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    acms-assemble-tiered-ok

Verify Payload Budget Check
    [Documentation]    Verify is_within_budget property on assembled payload
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    payload-budget-check    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    acms-payload-budget-ok

Assemble With Size Budget Context View
    [Documentation]    Verify max_file_size pre-filter and enforcement metadata
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    assemble-size-budget    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    acms-assemble-size-budget-ok

Skeleton Context Inheritance Parent To Child Plan
    [Documentation]    Verify parent plan context is compressed and propagated to child plan via SkeletonCompressor.
    ...    Issue #3563: SkeletonCompressor must be invoked in assemble() so child plans receive non-empty skeleton_fragments.
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    skeleton-context-inheritance    cwd=${WORKSPACE}
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    acms-skeleton-inheritance-ok
