use chaotic_semantic_memory::prelude::*;
#[tokio::test]
async fn cache_put_existing_key_updates_value() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.with_concept_cache_size(4)
.build()
.await
.unwrap();
framework
.inject_concept("cache-update-1", HVec10240::random())
.await
.unwrap();
let query = HVec10240::random();
let results1 = framework.probe_batch_cached(&[query], 5).await.unwrap();
let results2 = framework.probe_batch_cached(&[query], 5).await.unwrap();
assert_eq!(results1.len(), results2.len());
}
#[tokio::test]
async fn cache_capacity_one_evicts_on_second_query() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.with_concept_cache_size(1) .build()
.await
.unwrap();
framework
.inject_concept("evict-single", HVec10240::random())
.await
.unwrap();
let q1 = HVec10240::random();
let q2 = HVec10240::random();
framework.probe_batch_cached(&[q1], 5).await.unwrap();
framework.probe_batch_cached(&[q2], 5).await.unwrap();
framework.probe_batch_cached(&[q1], 5).await.unwrap();
let metrics = framework.metrics_snapshot().await;
assert!(metrics.cache_evictions_total >= 1);
}
#[tokio::test]
async fn cache_clear_removes_all_entries() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.with_concept_cache_size(16)
.build()
.await
.unwrap();
framework
.inject_concept("clear-test", HVec10240::random())
.await
.unwrap();
for _ in 0..3 {
let q = HVec10240::random();
framework.probe_batch_cached(&[q], 5).await.unwrap();
}
let metrics_before = framework.metrics_snapshot().await;
assert!(metrics_before.cache_misses_total >= 3);
framework.clear_similarity_cache().await;
let q = HVec10240::random();
framework.probe_batch_cached(&[q], 5).await.unwrap();
let metrics_after = framework.metrics_snapshot().await;
assert!(metrics_after.cache_misses_total >= 4);
}