use crate::common::{create_model_info, setup_mock_provider_with_models, MockProvider}; use kernelx_core::{prelude::*, Error}; mod common; #[tokio::test(flavor = "multi_thread")] async fn test_model_configuration() { let provider = MockProvider::with_capabilities(vec![Capability::Chat, Capability::Complete]).unwrap(); let model = provider .get_model::("mock-model") .unwrap() .system_prompt("You are a test assistant") .temperature(0.7) .max_tokens(100); // Test configuration assert_eq!( model.config().system_prompt.as_deref().unwrap(), "You are a test assistant" ); assert_eq!(model.config().temperature.unwrap(), 0.7); assert_eq!(model.config().max_tokens.unwrap(), 100); // Test model functionality let chat_result = model.chat(vec![ChatMessage::user("test")]).await; assert!(chat_result.is_ok()); assert_eq!(chat_result.unwrap(), "Mock chat response"); } #[tokio::test(flavor = "multi_thread")] async fn test_model_capabilities() { let provider = setup_mock_provider_with_models(vec![ create_model_info("basic", vec![Capability::Complete]), create_model_info("chat", vec![Capability::Chat, Capability::Complete]), create_model_info( "full", vec![ Capability::Chat, Capability::Complete, Capability::Structured, ], ), ]) .unwrap(); // Test capability requirements assert!(provider.get_model::("basic").is_ok()); assert!(provider.get_model::("basic").is_err()); assert!(provider.get_model::("chat").is_ok()); assert!(provider.get_model::("full").is_ok()); // Test error cases assert!(matches!( provider.get_model::("nonexistent"), Err(Error::ModelNotFound(_)) )); assert!(matches!( provider.get_model::("basic"), Err(Error::UnsupportedCapability(_)) )); } #[tokio::test(flavor = "multi_thread")] async fn test_model_config_merging() { let provider = MockProvider::with_capabilities(vec![Capability::Chat, Capability::Complete]).unwrap(); let base_model = provider.get_model::("mock-model").unwrap(); // Test config chaining let model = base_model .system_prompt("First prompt") .temperature(0.5) .max_tokens(100) .system_prompt("Second prompt") // Should override first prompt .temperature(0.7); // Should override first temperature assert_eq!( model.config().system_prompt.as_deref().unwrap(), "Second prompt" ); assert_eq!(model.config().temperature.unwrap(), 0.7); assert_eq!(model.config().max_tokens.unwrap(), 100); }