use kernelx_core::{ capabilities::{Chat, Vision}, prelude::*, providers::Provider, Error, }; use crate::common::MockProvider; mod common; #[tokio::test(flavor = "multi_thread")] async fn test_provider_model_capabilities() { let provider = MockProvider::builder() .api_key("test-key") .models(vec![ ModelInfo { id: "gpt-4".to_string(), capabilities: vec![Capability::Chat, Capability::Complete], }, ModelInfo { id: "gpt-4-vision".to_string(), capabilities: vec![Capability::Chat, Capability::Complete, Capability::Vision], }, ]) .build() .unwrap(); // Test successful model retrieval with correct capabilities let chat_model = provider.get_model::("gpt-4"); assert!(chat_model.is_ok()); // Test model not found error let result = provider.get_model::("non-existent-model"); assert!(matches!(result, Err(Error::ModelNotFound(_)))); // Test capability mismatch error let result = provider.get_model::("gpt-4"); assert!(matches!(result, Err(Error::UnsupportedCapability(_)))); // Test model with all capabilities let vision_model = provider.get_model::("gpt-4-vision"); assert!(vision_model.is_ok()); } #[tokio::test(flavor = "multi_thread")] async fn test_provider_builder_validation() { // Test missing API key let result = MockProvider::builder().build(); assert!( matches!(result, Err(Error::Config(_))), "Expected Config error for missing API key" ); // Test with minimal configuration let result = MockProvider::builder().api_key("test-key").build(); assert!(result.is_ok(), "Expected success with minimal config"); // Test with full configuration let result = MockProvider::builder() .api_key("test-key") .api_base("http://test.com") .models(vec![ModelInfo { id: "test-model".to_string(), capabilities: vec![Capability::Chat], }]) .build(); assert!(result.is_ok(), "Expected success with full config"); // Test with empty API key let result = MockProvider::builder().api_key("").build(); assert!( matches!(result, Err(Error::Config(_))), "Expected Config error for empty API key" ); } #[tokio::test(flavor = "multi_thread")] async fn test_provider_model_info() { let provider = MockProvider::builder() .api_key("test-key") .models(vec![ ModelInfo { id: "model-1".to_string(), capabilities: vec![Capability::Chat], }, ModelInfo { id: "model-2".to_string(), capabilities: vec![Capability::Complete, Capability::Vision], }, ]) .build() .unwrap(); let models = provider.models(); assert_eq!(models.len(), 2); assert!(models[0].capabilities.contains(&Capability::Chat)); assert!(models[1].capabilities.contains(&Capability::Complete)); assert!(models[1].capabilities.contains(&Capability::Vision)); }