//! Fence-specific tests for `TokenBucketGovernor`.

use klieo_bus_memory::MemoryBus;
use klieo_ops::governor::TokenBucketGovernor;
use klieo_ops::governor::{BudgetLimit, Governor, GovernorError};
use klieo_ops::types::{BudgetScope, ProviderId};

#[tokio::test]
async fn fence_blocks_subsequent_acquires() {
    let bus = MemoryBus::new();
    let kv = bus.kv.clone();
    let g = TokenBucketGovernor::builder(kv)
        .llm_limit(ProviderId("p".into()), 5)
        .build();
    g.fence(
        BudgetScope::Provider(ProviderId("p".into())),
        BudgetLimit::Rps(0),
    )
    .await
    .expect("fence ok");
    match g.acquire_llm(ProviderId("p".into()), 100).await {
        Ok(_) => panic!("must reject after fence"),
        Err(err) => assert!(
            matches!(err, GovernorError::Saturated { .. }),
            "expected Saturated, got {err:?}"
        ),
    }
}
