multi-llm 1.0.0

Unified multi-provider LLM client with support for OpenAI, Anthropic, Ollama, and LMStudio
Documentation
// Unit Tests for Edge Cases and Error Conditions
//
// UNIT UNDER TEST: Response, ResponseFormat, OpenAI types (edge case behavior)
//
// BUSINESS RESPONSIBILITY:
//   - Maintains system stability when LLM responses are incomplete or malformed
//   - Provides graceful fallback behavior for story processing when structured data is unavailable
//   - Ensures consistent behavior across different response format configurations
//   - Validates system handles various schema validation modes (strict vs non-strict)

use crate::providers::openai_shared::OpenAIJsonSchema;
use crate::provider::Response;
use crate::provider::ResponseFormat;
use serde_json::json;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_empty_structured_response() {
        // Test Response with empty structured response
        let response = Response {
            content: "Simple text response".to_string(),
            structured_response: None,
            tool_calls: vec![],
            usage: None,
            model: Some("test-model".to_string()),
            raw_body: None,
        };

        assert!(response.structured_response.is_none());
        assert_eq!(response.content, "Simple text response");
    }

    #[test]
    fn test_structured_response_with_empty_schema() {
        // Test with minimal empty schema
        let response = Response {
            content: "{}".to_string(),
            structured_response: Some(json!({})),
            tool_calls: vec![],
            usage: None,
            model: Some("test-model".to_string()),
            raw_body: None,
        };

        assert!(response.structured_response.is_some());
        assert_eq!(response.structured_response.unwrap(), json!({}));
    }

    #[test]
    fn test_response_format_with_empty_name() {
        // Test edge case with empty schema name
        let format = ResponseFormat {
            name: String::new(),
            schema: json!({"type": "object"}),
        };

        assert!(format.name.is_empty());
        assert_eq!(format.schema["type"], "object");
    }

    #[test]
    fn test_openai_json_schema_strict_mode_variations() {
        // Test different strict mode settings
        let schema_strict_true = OpenAIJsonSchema {
            name: "test".to_string(),
            schema: json!({"type": "object"}),
            strict: Some(true),
        };

        let schema_strict_false = OpenAIJsonSchema {
            name: "test".to_string(),
            schema: json!({"type": "object"}),
            strict: Some(false),
        };

        let schema_no_strict = OpenAIJsonSchema {
            name: "test".to_string(),
            schema: json!({"type": "object"}),
            strict: None,
        };

        assert_eq!(schema_strict_true.strict, Some(true));
        assert_eq!(schema_strict_false.strict, Some(false));
        assert_eq!(schema_no_strict.strict, None);
    }
}