*** Settings ***
Documentation    TDD Issue #1152 — budget eviction permanently deletes hot-tier fragments
...              instead of demoting to warm tier.  Integration smoke tests verifying that
...              ContextTierService._enforce_hot_budget() and evict_lru() demote evicted
...              fragments to the warm tier rather than permanently deleting them.
...              Tests are tagged so CI passes via result inversion.
Resource         ${CURDIR}/common.resource
Suite Setup      Setup Test Environment
Suite Teardown   Cleanup Test Environment

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

*** Test Cases ***
TDD Budget Eviction Demotes To Warm Not Deletes
    [Documentation]    Verify that when _enforce_hot_budget() evicts a fragment due to
    ...                token budget overflow, the evicted fragment is demoted to the warm
    ...                tier rather than permanently deleted.
    [Tags]  tdd_issue    tdd_issue_1152    tdd_issue    tdd_issue_4316    tdd_expected_fail

    ${result}=    Run Process    ${PYTHON}    ${HELPER}    budget-eviction-demotes    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-budget-eviction-demotes-ok

TDD Evict LRU Demotes To Warm Not Deletes
    [Documentation]    Verify that evict_lru(HOT, 1) demotes the evicted fragment to the
    ...                warm tier rather than permanently deleting it.
    [Tags]  tdd_issue    tdd_issue_1152    tdd_issue    tdd_issue_4316    tdd_expected_fail

    ${result}=    Run Process    ${PYTHON}    ${HELPER}    evict-lru-demotes    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-evict-lru-demotes-ok
