use do_memory_core::{
ComplexityLevel, ExecutionStep, SelfLearningMemory, TaskContext, TaskOutcome, TaskType,
};
#[tokio::test]
async fn test_search_patterns_basic() {
let memory = SelfLearningMemory::new();
let context = TaskContext {
domain: "web-api".to_string(),
language: Some("rust".to_string()),
framework: Some("axum".to_string()),
complexity: ComplexityLevel::Moderate,
tags: vec!["rest".to_string(), "async".to_string()],
};
let episode_id = memory
.start_episode(
"Build REST API".to_string(),
context.clone(),
TaskType::CodeGeneration,
)
.await;
let steps = vec![
ExecutionStep::new(
1,
"create_project".to_string(),
"Create new Rust project".to_string(),
),
ExecutionStep::new(
2,
"add_dependencies".to_string(),
"Add Axum and tower dependencies".to_string(),
),
ExecutionStep::new(
3,
"create_router".to_string(),
"Setup routes and handlers".to_string(),
),
ExecutionStep::new(
4,
"add_middleware".to_string(),
"Add logging and cors middleware".to_string(),
),
ExecutionStep::new(
5,
"write_tests".to_string(),
"Write integration tests".to_string(),
),
];
for step in steps {
memory.log_step(episode_id, step).await;
}
let _ = memory
.complete_episode(
episode_id,
TaskOutcome::Success {
verdict: "API created successfully".to_string(),
artifacts: vec!["api.rs".to_string(), "main.rs".to_string()],
},
)
.await;
let results = memory
.search_patterns_semantic("How to build a REST API", context, 5)
.await
.unwrap_or_default();
assert!(results.len() <= 5);
}
#[tokio::test]
async fn test_recommend_patterns_for_task() {
let memory = SelfLearningMemory::new();
let context = TaskContext {
domain: "cli".to_string(),
language: Some("rust".to_string()),
framework: None,
complexity: ComplexityLevel::Simple,
tags: vec!["argparse".to_string()],
};
let results = memory
.recommend_patterns_for_task("Parse command line arguments", context, 3)
.await
.unwrap();
assert!(results.len() <= 3);
}
#[tokio::test]
async fn test_discover_analogous_patterns() {
let memory = SelfLearningMemory::new();
let target_context = TaskContext {
domain: "web-api".to_string(),
language: Some("rust".to_string()),
framework: None,
complexity: ComplexityLevel::Moderate,
tags: vec![],
};
let results = memory
.discover_analogous_patterns("cli", target_context, 5)
.await
.unwrap();
assert!(results.len() <= 5);
}
#[tokio::test]
async fn test_pattern_search_with_filters() {
let memory = SelfLearningMemory::new();
let context = TaskContext {
domain: "data-processing".to_string(),
language: Some("python".to_string()),
framework: Some("pandas".to_string()),
complexity: ComplexityLevel::Complex,
tags: vec!["etl".to_string()],
};
let config = do_memory_core::memory::SearchConfig::strict();
let results = memory
.search_patterns_with_config("ETL pipeline", context, config, 10)
.await
.unwrap();
assert!(results.len() <= 10);
}