Update unit tests for basic keywords

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-12-24 09:29:28 -03:00
parent 3d0a9a843d
commit 56334dd7b1
8 changed files with 1010 additions and 1195 deletions

View file

@ -1,14 +1,9 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use botserver::basic::keywords::agent_reflection::{
extract_insights_from_text, ReflectionConfig, ReflectionResult, ReflectionType,
};
use uuid::Uuid;
#[test]
fn test_reflection_type_from_str() {
assert_eq!(
ReflectionType::from("conversation_quality"),
@ -29,8 +24,6 @@
}
#[test]
fn test_reflection_config_default() {
let config = ReflectionConfig::default();
assert!(!config.enabled);
@ -39,8 +32,6 @@
}
#[test]
fn test_reflection_result_new() {
let bot_id = Uuid::new_v4();
let session_id = Uuid::new_v4();
@ -53,8 +44,6 @@
}
#[test]
fn test_reflection_result_from_json() {
let json_response = r#"{
"score": 7.5,
@ -78,8 +67,6 @@
}
#[test]
fn test_reflection_result_needs_improvement() {
let mut result =
ReflectionResult::new(Uuid::new_v4(), Uuid::new_v4(), ReflectionType::Performance);
@ -92,8 +79,6 @@
}
#[test]
fn test_extract_insights_from_text() {
let text = "Here are some insights:\n\
1. Users prefer short responses\n\
@ -106,8 +91,6 @@
}
#[test]
fn test_reflection_type_prompt_template() {
let template = ReflectionType::ConversationQuality.prompt_template();
assert!(template.contains("{conversation}"));
@ -115,8 +98,6 @@
}
#[test]
fn test_reflection_result_summary() {
let mut result =
ReflectionResult::new(Uuid::new_v4(), Uuid::new_v4(), ReflectionType::Performance);

View file

@ -1,14 +1,9 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use botserver::basic::keywords::code_sandbox::{
generate_node_lxc_config, generate_python_lxc_config, CodeLanguage, ExecutionResult,
SandboxConfig, SandboxRuntime,
};
#[test]
fn test_sandbox_config_default() {
let config = SandboxConfig::default();
assert!(config.enabled);
@ -18,8 +13,6 @@
}
#[test]
fn test_execution_result_success() {
let result = ExecutionResult::success("Hello, World!".to_string(), String::new(), 100);
assert!(result.is_success());
@ -27,8 +20,6 @@
}
#[test]
fn test_execution_result_error() {
let result = ExecutionResult::error("Something went wrong");
assert!(!result.is_success());
@ -36,8 +27,6 @@
}
#[test]
fn test_execution_result_timeout() {
let result = ExecutionResult::timeout();
assert!(!result.is_success());
@ -45,8 +34,6 @@
}
#[test]
fn test_code_language_from_str() {
assert_eq!(CodeLanguage::from("python"), CodeLanguage::Python);
assert_eq!(CodeLanguage::from("PYTHON"), CodeLanguage::Python);
@ -58,8 +45,6 @@
}
#[test]
fn test_code_language_file_extension() {
assert_eq!(CodeLanguage::Python.file_extension(), "py");
assert_eq!(CodeLanguage::JavaScript.file_extension(), "js");
@ -67,8 +52,6 @@
}
#[test]
fn test_code_language_interpreter() {
assert_eq!(CodeLanguage::Python.interpreter(), "python3");
assert_eq!(CodeLanguage::JavaScript.interpreter(), "node");
@ -76,8 +59,6 @@
}
#[test]
fn test_sandbox_runtime_from_str() {
assert_eq!(SandboxRuntime::from("lxc"), SandboxRuntime::LXC);
assert_eq!(SandboxRuntime::from("docker"), SandboxRuntime::Docker);
@ -89,8 +70,6 @@
}
#[test]
fn test_lxc_config_generation() {
let python_config = generate_python_lxc_config();
assert!(python_config.contains("gb-sandbox-python"));

View file

@ -1,17 +1,12 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use serde_json;
use botserver::basic::keywords::episodic_memory::{
extract_json, ConversationMessage, Episode, EpisodicMemoryConfig, EpisodicMemoryManager,
ResolutionStatus, Sentiment,
};
use chrono::Utc;
use rhai::Map;
use uuid::Uuid;
#[test]
fn test_default_config() {
let config = EpisodicMemoryConfig::default();
assert!(config.enabled);
@ -21,8 +16,6 @@ use serde_json;
}
#[test]
fn test_should_summarize() {
let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig {
enabled: true,
@ -38,21 +31,15 @@ use serde_json;
}
#[test]
fn test_extract_json() {
let response = "Here's the summary:\n```json\n{\"summary\": \"test\"}\n```\n";
assert!(extract_json(response).is_ok());
let response = "The result is {\"summary\": \"test\"}";
assert!(extract_json(response).is_ok());
}
#[test]
fn test_generate_summary_prompt() {
let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig::default());
let messages = vec![ConversationMessage {
@ -68,8 +55,6 @@ use serde_json;
}
#[test]
fn test_parse_summary_response() {
let manager = EpisodicMemoryManager::new(EpisodicMemoryConfig::default());
let response = r#"{
@ -104,8 +89,6 @@ use serde_json;
}
#[test]
fn test_episode_to_dynamic() {
let episode = Episode {
id: Uuid::new_v4(),

View file

@ -1,17 +1,11 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use serde_json;
use botserver::basic::keywords::human_approval::{
ApprovalChannel, ApprovalConfig, ApprovalDecision, ApprovalManager, ApprovalStatus,
};
use chrono::{Duration, Utc};
use rhai::Map;
use uuid::Uuid;
#[test]
fn test_default_config() {
let config = ApprovalConfig::default();
assert!(config.enabled);
@ -20,8 +14,6 @@ use serde_json;
}
#[test]
fn test_create_request() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let request = manager.create_request(
@ -43,8 +35,6 @@ use serde_json;
}
#[test]
fn test_is_expired() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let mut request = manager.create_request(
@ -62,14 +52,11 @@ use serde_json;
assert!(!manager.is_expired(&request));
request.expires_at = Utc::now() - Duration::seconds(10);
assert!(manager.is_expired(&request));
}
#[test]
fn test_process_decision() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let mut request = manager.create_request(
@ -99,8 +86,6 @@ use serde_json;
}
#[test]
fn test_evaluate_condition() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let context = serde_json::json!({
@ -120,8 +105,6 @@ use serde_json;
}
#[test]
fn test_handle_timeout_with_default() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let mut request = manager.create_request(
@ -145,8 +128,6 @@ use serde_json;
}
#[test]
fn test_request_to_dynamic() {
let manager = ApprovalManager::new(ApprovalConfig::default());
let request = manager.create_request(

View file

@ -1,25 +1,18 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use botserver::basic::keywords::on_change::{
detect_provider_from_email, is_cloud_path, parse_folder_path, sanitize_path_for_filename,
ChangeEventType, FolderChangeEvent, FolderMonitor, FolderProvider,
};
use uuid::Uuid;
#[test]
fn test_parse_folder_path_account() {
let (provider, email, path) =
parse_folder_path("account://user@gmail.com/Documents/invoices");
let (provider, email, path) = parse_folder_path("account://user@gmail.com/Documents/invoices");
assert_eq!(provider, FolderProvider::GDrive);
assert_eq!(email, Some("user@gmail.com".to_string()));
assert_eq!(path, "/Documents/invoices");
}
#[test]
fn test_parse_folder_path_gdrive() {
let (provider, email, path) = parse_folder_path("gdrive:///shared/reports");
assert_eq!(provider, FolderProvider::GDrive);
@ -28,8 +21,6 @@
}
#[test]
fn test_parse_folder_path_onedrive() {
let (provider, email, path) = parse_folder_path("onedrive:///business/docs");
assert_eq!(provider, FolderProvider::OneDrive);
@ -38,8 +29,6 @@
}
#[test]
fn test_parse_folder_path_dropbox() {
let (provider, email, path) = parse_folder_path("dropbox:///team/assets");
assert_eq!(provider, FolderProvider::Dropbox);
@ -48,8 +37,6 @@
}
#[test]
fn test_parse_folder_path_local() {
let (provider, email, path) = parse_folder_path("/home/user/documents");
assert_eq!(provider, FolderProvider::Local);
@ -58,8 +45,6 @@
}
#[test]
fn test_is_cloud_path() {
assert!(is_cloud_path("account://user@gmail.com/docs"));
assert!(is_cloud_path("gdrive:///shared"));
@ -70,8 +55,6 @@
}
#[test]
fn test_folder_provider_from_str() {
assert_eq!(
FolderProvider::from_str("gdrive"),
@ -113,8 +96,6 @@
}
#[test]
fn test_change_event_type_from_str() {
assert_eq!(
ChangeEventType::from_str("create"),
@ -152,8 +133,6 @@
}
#[test]
fn test_sanitize_path() {
assert_eq!(
sanitize_path_for_filename("/home/user/docs"),
@ -170,8 +149,6 @@
}
#[test]
fn test_folder_monitor_struct() {
let monitor = FolderMonitor {
id: Uuid::new_v4(),
@ -193,8 +170,6 @@
}
#[test]
fn test_folder_change_event_struct() {
let event = FolderChangeEvent {
id: Uuid::new_v4(),
@ -213,8 +188,6 @@
}
#[test]
fn test_detect_provider_from_email() {
assert_eq!(
detect_provider_from_email("user@gmail.com"),

View file

@ -1,14 +1,10 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use botserver::basic::keywords::on_email::{
is_email_path, parse_email_path, sanitize_email_for_filename, EmailAttachment, EmailMonitor,
EmailReceivedEvent,
};
use uuid::Uuid;
#[test]
fn test_email_monitor_struct() {
let monitor = EmailMonitor {
id: Uuid::new_v4(),
@ -27,8 +23,6 @@
}
#[test]
fn test_email_monitor_with_filters() {
let monitor = EmailMonitor {
id: Uuid::new_v4(),
@ -46,8 +40,6 @@
}
#[test]
fn test_email_attachment_struct() {
let attachment = EmailAttachment {
filename: "document.pdf".to_string(),
@ -61,8 +53,6 @@
}
#[test]
fn test_email_received_event_struct() {
let event = EmailReceivedEvent {
id: Uuid::new_v4(),
@ -88,8 +78,6 @@
}
#[test]
fn test_parse_email_path_basic() {
let result = parse_email_path("email://user@gmail.com");
assert!(result.is_some());
@ -99,8 +87,6 @@
}
#[test]
fn test_parse_email_path_with_folder() {
let result = parse_email_path("email://user@gmail.com/INBOX");
assert!(result.is_some());
@ -110,8 +96,6 @@
}
#[test]
fn test_parse_email_path_invalid() {
assert!(parse_email_path("user@gmail.com").is_none());
assert!(parse_email_path("mailto:user@gmail.com").is_none());
@ -119,8 +103,6 @@
}
#[test]
fn test_is_email_path() {
assert!(is_email_path("email://user@gmail.com"));
assert!(is_email_path("email://user@company.com/INBOX"));
@ -130,8 +112,6 @@
}
#[test]
fn test_sanitize_email_for_filename() {
assert_eq!(
sanitize_email_for_filename("user@gmail.com"),
@ -148,8 +128,6 @@
}
#[test]
fn test_email_event_without_attachments() {
let event = EmailReceivedEvent {
id: Uuid::new_v4(),
@ -169,8 +147,6 @@
}
#[test]
fn test_multiple_to_addresses() {
let event = EmailReceivedEvent {
id: Uuid::new_v4(),
@ -195,8 +171,6 @@
}
#[test]
fn test_multiple_attachments() {
let attachments = vec![
EmailAttachment {

View file

@ -1,14 +1,8 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use botserver::basic::keywords::play::{
detect_content_type, extract_title_from_source, ContentType, PlayOptions,
};
#[test]
fn test_content_type_from_extension() {
assert_eq!(ContentType::from_extension("mp4"), ContentType::Video);
assert_eq!(ContentType::from_extension("MP3"), ContentType::Audio);
@ -27,8 +21,6 @@
}
#[test]
fn test_content_type_from_mime() {
assert_eq!(ContentType::from_mime("video/mp4"), ContentType::Video);
assert_eq!(ContentType::from_mime("audio/mpeg"), ContentType::Audio);
@ -37,8 +29,6 @@
}
#[test]
fn test_play_options_from_string() {
let opts = PlayOptions::from_string("autoplay,loop,muted");
assert!(opts.autoplay);
@ -60,8 +50,6 @@
}
#[test]
fn test_detect_content_type() {
assert_eq!(
detect_content_type("https://youtube.com/watch?v=123"),
@ -84,8 +72,6 @@
}
#[test]
fn test_extract_title_from_source() {
assert_eq!(extract_title_from_source("documents/report.pdf"), "report");
assert_eq!(
@ -99,8 +85,6 @@
}
#[test]
fn test_player_component() {
assert_eq!(ContentType::Video.player_component(), "video-player");
assert_eq!(ContentType::Audio.player_component(), "audio-player");

View file

@ -1,21 +1,11 @@
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use botserver::basic::keywords::set_schedule::parse_natural_schedule;
#[test]
fn test_every_minute() {
assert_eq!(parse_natural_schedule("every minute").unwrap(), "* * * * *");
}
#[test]
fn test_every_n_minutes() {
assert_eq!(
parse_natural_schedule("every 5 minutes").unwrap(),
@ -32,16 +22,12 @@
}
#[test]
fn test_every_hour() {
assert_eq!(parse_natural_schedule("every hour").unwrap(), "0 * * * *");
assert_eq!(parse_natural_schedule("hourly").unwrap(), "0 * * * *");
}
#[test]
fn test_every_n_hours() {
assert_eq!(
parse_natural_schedule("every 2 hours").unwrap(),
@ -54,32 +40,24 @@
}
#[test]
fn test_every_day() {
assert_eq!(parse_natural_schedule("every day").unwrap(), "0 0 * * *");
assert_eq!(parse_natural_schedule("daily").unwrap(), "0 0 * * *");
}
#[test]
fn test_every_week() {
assert_eq!(parse_natural_schedule("every week").unwrap(), "0 0 * * 0");
assert_eq!(parse_natural_schedule("weekly").unwrap(), "0 0 * * 0");
}
#[test]
fn test_every_month() {
assert_eq!(parse_natural_schedule("every month").unwrap(), "0 0 1 * *");
assert_eq!(parse_natural_schedule("monthly").unwrap(), "0 0 1 * *");
}
#[test]
fn test_at_time() {
assert_eq!(parse_natural_schedule("at 9am").unwrap(), "0 9 * * *");
assert_eq!(parse_natural_schedule("at 9:30am").unwrap(), "30 9 * * *");
@ -90,8 +68,6 @@
}
#[test]
fn test_day_of_week() {
assert_eq!(parse_natural_schedule("every monday").unwrap(), "0 0 * * 1");
assert_eq!(parse_natural_schedule("every friday").unwrap(), "0 0 * * 5");
@ -99,8 +75,6 @@
}
#[test]
fn test_day_with_time() {
assert_eq!(
parse_natural_schedule("every monday at 9am").unwrap(),
@ -113,8 +87,6 @@
}
#[test]
fn test_weekdays() {
assert_eq!(parse_natural_schedule("weekdays").unwrap(), "0 0 * * 1-5");
assert_eq!(
@ -128,8 +100,6 @@
}
#[test]
fn test_weekends() {
assert_eq!(parse_natural_schedule("weekends").unwrap(), "0 0 * * 0,6");
assert_eq!(
@ -139,8 +109,6 @@
}
#[test]
fn test_combined() {
assert_eq!(
parse_natural_schedule("every day at 9am").unwrap(),
@ -153,8 +121,6 @@
}
#[test]
fn test_hour_range() {
assert_eq!(
parse_natural_schedule("every hour from 9 to 17").unwrap(),
@ -163,8 +129,6 @@
}
#[test]
fn test_business_hours() {
assert_eq!(
parse_natural_schedule("business hours").unwrap(),
@ -181,8 +145,6 @@
}
#[test]
fn test_raw_cron_passthrough() {
assert_eq!(parse_natural_schedule("0 * * * *").unwrap(), "0 * * * *");
assert_eq!(
@ -196,8 +158,6 @@
}
#[test]
fn test_invalid_input() {
assert!(parse_natural_schedule("potato salad").is_err());
assert!(parse_natural_schedule("every 100 minutes").is_err());