use crate::common::MockProvider; use kernelx_core::prelude::*; mod common; #[tokio::test] async fn test_provider_config_flow() { let base_config = ModelConfig::default() .with_temperature(0.8) .with_system_prompt("Base system prompt"); let provider = MockProvider::builder() .api_key("test-key") .with_config(base_config.clone()) .build() .unwrap(); // Verify provider's base config matches what we provided assert_eq!(provider.config().temperature, base_config.temperature); assert_eq!(provider.config().system_prompt, base_config.system_prompt); } #[tokio::test] async fn test_model_config_override() { let provider = MockProvider::builder() .api_key("test-key") .with_config( ModelConfig::default() .with_temperature(0.8) .with_system_prompt("Provider system prompt"), ) .build() .unwrap(); let model = provider .get_model::("mock-model") .unwrap() .system_prompt("Model system prompt") .temperature(0.5); // Verify model config overrides provider config assert_eq!(model.config().temperature, Some(0.5)); assert_eq!( model.config().system_prompt.as_deref(), Some("Model system prompt") ); } #[tokio::test] async fn test_system_prompt_in_complete() { let provider = MockProvider::builder().api_key("test-key").build().unwrap(); let model = provider .get_model::("mock-model") .unwrap() .system_prompt("I am a test system"); let result = model.complete("Hello").await.unwrap(); // Mock returns fixed response assert_eq!(result, "Mock completion response"); } #[tokio::test] async fn test_system_prompt_in_chat() { let provider = MockProvider::builder().api_key("test-key").build().unwrap(); let model = provider .get_model::("mock-model") .unwrap() .system_prompt("I am a test system"); let messages = vec![ChatMessage::user("Hello")]; let result = model.chat(messages).await.unwrap(); // Mock returns fixed response assert_eq!(result, "Mock chat response"); } #[tokio::test] async fn test_config_inheritance() { let config = ModelConfig::default() .with_temperature(0.8) .with_max_tokens(100); let provider = MockProvider::builder() .api_key("test-key") .with_config(config.clone()) .build() .unwrap(); let model = provider .get_model::("mock-model") .unwrap() .temperature(0.5); // Override only temperature // Temperature should be overridden assert_eq!(model.config().temperature, Some(0.5)); // Max tokens should be inherited from provider config assert_eq!(model.config().max_tokens, config.max_tokens); } #[tokio::test] async fn test_multiple_model_configs() { let provider = MockProvider::builder().api_key("test-key").build().unwrap(); let model1 = provider .get_model::("mock-model") .unwrap() .system_prompt("System 1") .temperature(0.5); let model2 = provider .get_model::("mock-model") .unwrap() .system_prompt("System 2") .temperature(0.7); // Verify each model has its own independent config assert_eq!(model1.config().temperature, Some(0.5)); assert_eq!(model1.config().system_prompt.as_deref(), Some("System 1")); assert_eq!(model2.config().temperature, Some(0.7)); assert_eq!(model2.config().system_prompt.as_deref(), Some("System 2")); }