*** Settings ***
Documentation    TDD Issue #821 — context tier service has data models but no runtime logic
...              for promotion, demotion, or eviction.  Integration smoke tests verifying
...              that ContextTierService automatically promotes fragments on repeated access,
...              demotes stale fragments, and evicts fragments when the hot tier budget
...              overflows.  Currently the service has manual promote()/demote()/evict_lru()
...              methods but no automatic runtime behaviour wired into get() or store().
...              Tests are tagged tdd_expected_fail 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_context_tier_runtime.py

*** Test Cases ***
TDD Promotion On Repeated Access
    [Documentation]    Verify that accessing a cold-tier fragment repeatedly via get()
    ...                auto-promotes it to warm or hot tier.
    [Tags]    tdd_issue    tdd_issue_821
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    promote-on-access    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-promote-on-access-ok

TDD Demotion On Staleness
    [Documentation]    Verify that a stale hot-tier fragment is automatically demoted
    ...                to warm or cold tier by a staleness enforcement runtime.
    [Tags]    tdd_issue    tdd_issue_821
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    demote-on-staleness    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-demote-on-staleness-ok

TDD Eviction On Budget Overflow
    [Documentation]    Verify that storing beyond the hot tier token budget triggers
    ...                automatic LRU eviction of the oldest fragment.
    [Tags]    tdd_issue    tdd_issue_821
    ${result}=    Run Process    ${PYTHON}    ${HELPER}    evict-on-overflow    cwd=${WORKSPACE}    timeout=30s
    Log    ${result.stdout}
    Log    ${result.stderr}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    tdd-evict-on-overflow-ok
