refactor: comprehensive audit — fix bugs, harden security, deduplicate providers, add CI/Docker
Phase 1: Fix compilation (config_path Option<PathBuf>, streaming test, stale test cleanup) Phase 2: Fix critical bugs (remove block_on deadlocks in 4 providers, fix broken SQL query builder) Phase 3: Security hardening (session manager, real auth, token masking, Gemini key to header, password policy) Phase 4: Implement stubs (real provider test, /proc health metrics, client/provider/backup endpoints, has_images) Phase 5: Code quality (shared provider helpers, explicit re-exports, all Clippy warnings fixed, unwrap removal, 6 unused deps removed, dashboard split into 7 sub-modules) Phase 6: Infrastructure (GitHub Actions CI, multi-stage Dockerfile, rustfmt.toml, clippy.toml, script fixes)
This commit is contained in:
92
src/lib.rs
92
src/lib.rs
@@ -6,8 +6,8 @@
|
||||
pub mod auth;
|
||||
pub mod client;
|
||||
pub mod config;
|
||||
pub mod database;
|
||||
pub mod dashboard;
|
||||
pub mod database;
|
||||
pub mod errors;
|
||||
pub mod logging;
|
||||
pub mod models;
|
||||
@@ -19,58 +19,62 @@ pub mod state;
|
||||
pub mod utils;
|
||||
|
||||
// Re-exports for convenience
|
||||
pub use auth::*;
|
||||
pub use config::*;
|
||||
pub use database::*;
|
||||
pub use errors::*;
|
||||
pub use logging::*;
|
||||
pub use models::*;
|
||||
pub use providers::*;
|
||||
pub use server::*;
|
||||
pub use state::*;
|
||||
pub use auth::{AuthenticatedClient, validate_token};
|
||||
pub use config::{
|
||||
AppConfig, DatabaseConfig, DeepSeekConfig, GeminiConfig, GrokConfig, ModelMappingConfig, ModelPricing,
|
||||
OllamaConfig, OpenAIConfig, PricingConfig, ProviderConfig, ServerConfig,
|
||||
};
|
||||
pub use database::{DbPool, init as init_db, test_connection};
|
||||
pub use errors::AppError;
|
||||
pub use logging::{LoggingContext, RequestLog, RequestLogger};
|
||||
pub use models::{
|
||||
ChatChoice, ChatCompletionRequest, ChatCompletionResponse, ChatCompletionStreamResponse, ChatMessage,
|
||||
ChatStreamChoice, ChatStreamDelta, ContentPart, ContentPartValue, FromOpenAI, ImageUrl, MessageContent,
|
||||
OpenAIContentPart, OpenAIMessage, OpenAIRequest, ToOpenAI, UnifiedMessage, UnifiedRequest, Usage,
|
||||
};
|
||||
pub use providers::{Provider, ProviderManager, ProviderResponse, ProviderStreamChunk};
|
||||
pub use server::router;
|
||||
pub use state::AppState;
|
||||
|
||||
/// Test utilities for integration testing
|
||||
#[cfg(test)]
|
||||
pub mod test_utils {
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
state::AppState,
|
||||
rate_limiting::RateLimitManager,
|
||||
client::ClientManager,
|
||||
providers::ProviderManager,
|
||||
};
|
||||
|
||||
use crate::{client::ClientManager, providers::ProviderManager, rate_limiting::RateLimitManager, state::AppState};
|
||||
use sqlx::sqlite::SqlitePool;
|
||||
|
||||
|
||||
/// Create a test application state
|
||||
pub async fn create_test_state() -> Arc<AppState> {
|
||||
// Create in-memory database
|
||||
let pool = SqlitePool::connect("sqlite::memory:")
|
||||
.await
|
||||
.expect("Failed to create test database");
|
||||
|
||||
|
||||
// Run migrations
|
||||
crate::database::init(&crate::config::DatabaseConfig {
|
||||
path: std::path::PathBuf::from(":memory:"),
|
||||
max_connections: 5,
|
||||
}).await.expect("Failed to initialize test database");
|
||||
|
||||
})
|
||||
.await
|
||||
.expect("Failed to initialize test database");
|
||||
|
||||
let rate_limit_manager = RateLimitManager::new(
|
||||
crate::rate_limiting::RateLimiterConfig::default(),
|
||||
crate::rate_limiting::CircuitBreakerConfig::default(),
|
||||
);
|
||||
|
||||
|
||||
let client_manager = Arc::new(ClientManager::new(pool.clone()));
|
||||
|
||||
|
||||
// Create provider manager
|
||||
let provider_manager = ProviderManager::new();
|
||||
|
||||
|
||||
let model_registry = crate::models::registry::ModelRegistry {
|
||||
providers: std::collections::HashMap::new(),
|
||||
};
|
||||
|
||||
|
||||
let (dashboard_tx, _) = tokio::sync::broadcast::channel(100);
|
||||
|
||||
|
||||
let config = Arc::new(crate::config::AppConfig {
|
||||
server: crate::config::ServerConfig {
|
||||
port: 8080,
|
||||
@@ -82,11 +86,35 @@ pub mod test_utils {
|
||||
max_connections: 5,
|
||||
},
|
||||
providers: crate::config::ProviderConfig {
|
||||
openai: crate::config::OpenAIConfig { api_key_env: "OPENAI_API_KEY".to_string(), base_url: "".to_string(), default_model: "".to_string(), enabled: true },
|
||||
gemini: crate::config::GeminiConfig { api_key_env: "GEMINI_API_KEY".to_string(), base_url: "".to_string(), default_model: "".to_string(), enabled: true },
|
||||
deepseek: crate::config::DeepSeekConfig { api_key_env: "DEEPSEEK_API_KEY".to_string(), base_url: "".to_string(), default_model: "".to_string(), enabled: true },
|
||||
grok: crate::config::GrokConfig { api_key_env: "GROK_API_KEY".to_string(), base_url: "".to_string(), default_model: "".to_string(), enabled: true },
|
||||
ollama: crate::config::OllamaConfig { base_url: "".to_string(), enabled: true, models: vec![] },
|
||||
openai: crate::config::OpenAIConfig {
|
||||
api_key_env: "OPENAI_API_KEY".to_string(),
|
||||
base_url: "".to_string(),
|
||||
default_model: "".to_string(),
|
||||
enabled: true,
|
||||
},
|
||||
gemini: crate::config::GeminiConfig {
|
||||
api_key_env: "GEMINI_API_KEY".to_string(),
|
||||
base_url: "".to_string(),
|
||||
default_model: "".to_string(),
|
||||
enabled: true,
|
||||
},
|
||||
deepseek: crate::config::DeepSeekConfig {
|
||||
api_key_env: "DEEPSEEK_API_KEY".to_string(),
|
||||
base_url: "".to_string(),
|
||||
default_model: "".to_string(),
|
||||
enabled: true,
|
||||
},
|
||||
grok: crate::config::GrokConfig {
|
||||
api_key_env: "GROK_API_KEY".to_string(),
|
||||
base_url: "".to_string(),
|
||||
default_model: "".to_string(),
|
||||
enabled: true,
|
||||
},
|
||||
ollama: crate::config::OllamaConfig {
|
||||
base_url: "".to_string(),
|
||||
enabled: true,
|
||||
models: vec![],
|
||||
},
|
||||
},
|
||||
model_mapping: crate::config::ModelMappingConfig { patterns: vec![] },
|
||||
pricing: crate::config::PricingConfig {
|
||||
@@ -111,7 +139,7 @@ pub mod test_utils {
|
||||
auth_tokens: vec![],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/// Create a test HTTP client
|
||||
pub fn create_test_client() -> reqwest::Client {
|
||||
reqwest::Client::builder()
|
||||
|
||||
Reference in New Issue
Block a user