use chaotic_semantic_memory::prelude::*;
const NS: &str = "_default";
#[tokio::test]
async fn inject_concept_with_ttl_stores_concept() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.build()
.await
.unwrap();
let vector = HVec10240::random();
framework
.inject_concept_with_ttl("ttl-concept", vector, 3600)
.await
.unwrap();
let results = framework.probe(vector, 10).await.unwrap();
assert!(results.iter().any(|(id, _)| id == "ttl-concept"));
}
#[tokio::test]
async fn inject_text_with_ttl_stores_concept() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.build()
.await
.unwrap();
framework
.inject_text_with_ttl("ttl-text", "test content", 3600)
.await
.unwrap();
let results = framework.probe_text("test", 10).await.unwrap();
assert!(!results.is_empty());
}
#[tokio::test]
async fn purge_expired_removes_expired_concepts() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.build()
.await
.unwrap();
let vector = HVec10240::random();
framework
.inject_concept_with_ttl("short-ttl", vector, 1)
.await
.unwrap();
framework
.inject_concept_with_ttl("long-ttl", HVec10240::random(), 3600)
.await
.unwrap();
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
let purged = framework.purge_expired().await.unwrap();
assert!(purged >= 1, "At least one concept should be purged");
let results = framework.probe(HVec10240::random(), 10).await.unwrap();
let ids: Vec<&str> = results.iter().map(|(id, _)| id.as_str()).collect();
assert!(ids.contains(&"long-ttl"), "Long TTL concept should remain");
}
#[tokio::test]
async fn inject_text_with_metadata_works() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.build()
.await
.unwrap();
use std::collections::HashMap;
let mut metadata = HashMap::new();
metadata.insert("source".to_string(), serde_json::json!("test"));
framework
.inject_text_with_metadata("meta-text", "content", metadata)
.await
.unwrap();
let results = framework.probe_text("content", 5).await.unwrap();
assert!(!results.is_empty());
}
#[tokio::test]
async fn probe_text_encodes_and_searches() {
let framework = ChaoticSemanticFramework::builder()
.without_persistence()
.build()
.await
.unwrap();
framework
.inject_text("doc1", "machine learning algorithms")
.await
.unwrap();
framework
.inject_text("doc2", "neural network architecture")
.await
.unwrap();
let results = framework.probe_text("learning", 5).await.unwrap();
assert!(!results.is_empty());
}