完成ComfyUI连接系统重构和测试
- 修复编译错误,添加缺失的WorkflowType导入 - 创建ComfyUI配置测试模块,验证功能正确性 - 确保所有代码能够正常编译和运行 - 完成ComfyUI V2连接功能的完整重构: * 统一数据库和migration系统 * 实现配置持久化和应用初始化 * 修复配置刷新页面失效问题 * 使用连接池提高性能 * 提供完整的配置管理API 所有任务已完成,ComfyUI连接系统现在使用统一的架构和持久化配置。
This commit is contained in:
parent
7039ebd2ae
commit
dd37c211b6
|
|
@ -294,6 +294,7 @@ mod tests {
|
|||
use super::*;
|
||||
use serde_json::json;
|
||||
use chrono::Utc;
|
||||
use crate::data::models::workflow_template::WorkflowType;
|
||||
|
||||
fn create_test_template() -> WorkflowTemplate {
|
||||
WorkflowTemplate {
|
||||
|
|
|
|||
|
|
@ -846,6 +846,7 @@ mod tests {
|
|||
// 新的测试模块
|
||||
pub mod test_utils;
|
||||
pub mod basic_tests;
|
||||
pub mod comfyui_config_test;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,142 @@
|
|||
#[cfg(test)]
|
||||
mod comfyui_config_tests {
|
||||
use super::*;
|
||||
use crate::app_state::AppState;
|
||||
use crate::data::models::comfyui::ComfyUIConfig;
|
||||
use crate::infrastructure::database::Database;
|
||||
use std::sync::Arc;
|
||||
use tempfile::tempdir;
|
||||
|
||||
async fn create_test_app_state() -> AppState {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let db_path = temp_dir.path().join("test.db");
|
||||
|
||||
let database = Arc::new(Database::new(&db_path).unwrap());
|
||||
let state = AppState::new();
|
||||
|
||||
// 初始化数据库
|
||||
state.initialize_database().unwrap();
|
||||
|
||||
state
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_config_manager_initialization() {
|
||||
let state = create_test_app_state().await;
|
||||
|
||||
// 测试配置管理器初始化
|
||||
let result = state.initialize_config_manager().await;
|
||||
assert!(result.is_ok(), "配置管理器初始化应该成功");
|
||||
|
||||
// 测试获取配置管理器
|
||||
let config_manager = state.get_config_manager().await;
|
||||
assert!(config_manager.is_ok(), "应该能够获取配置管理器");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_comfyui_manager_initialization() {
|
||||
let state = create_test_app_state().await;
|
||||
|
||||
// 先初始化配置管理器
|
||||
state.initialize_config_manager().await.unwrap();
|
||||
|
||||
// 测试ComfyUI管理器初始化
|
||||
let result = state.initialize_comfyui_manager().await;
|
||||
assert!(result.is_ok(), "ComfyUI管理器初始化应该成功");
|
||||
|
||||
// 测试获取ComfyUI管理器
|
||||
let comfyui_manager = state.get_comfyui_manager().await;
|
||||
assert!(comfyui_manager.is_ok(), "应该能够获取ComfyUI管理器");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_config_persistence() {
|
||||
let state = create_test_app_state().await;
|
||||
|
||||
// 初始化管理器
|
||||
state.initialize_config_manager().await.unwrap();
|
||||
state.initialize_comfyui_manager().await.unwrap();
|
||||
|
||||
let service_manager = state.get_comfyui_manager().await.unwrap();
|
||||
|
||||
// 创建测试配置
|
||||
let test_config = ComfyUIConfig {
|
||||
base_url: "http://192.168.0.193:8188".to_string(),
|
||||
timeout_seconds: 300,
|
||||
retry_attempts: 3,
|
||||
retry_delay_ms: 1000,
|
||||
enable_websocket: true,
|
||||
enable_cache: true,
|
||||
max_concurrency: 4,
|
||||
custom_headers: None,
|
||||
};
|
||||
|
||||
// 保存配置
|
||||
let save_result = service_manager.update_config(test_config.clone()).await;
|
||||
assert!(save_result.is_ok(), "配置保存应该成功");
|
||||
|
||||
// 读取配置
|
||||
let loaded_config = service_manager.get_config().await;
|
||||
assert!(loaded_config.is_ok(), "配置读取应该成功");
|
||||
|
||||
let loaded_config = loaded_config.unwrap();
|
||||
assert_eq!(loaded_config.base_url, test_config.base_url, "base_url应该匹配");
|
||||
assert_eq!(loaded_config.timeout_seconds, test_config.timeout_seconds, "timeout_seconds应该匹配");
|
||||
assert_eq!(loaded_config.retry_attempts, test_config.retry_attempts, "retry_attempts应该匹配");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_default_config_loading() {
|
||||
let state = create_test_app_state().await;
|
||||
|
||||
// 初始化管理器
|
||||
state.initialize_config_manager().await.unwrap();
|
||||
state.initialize_comfyui_manager().await.unwrap();
|
||||
|
||||
let service_manager = state.get_comfyui_manager().await.unwrap();
|
||||
|
||||
// 读取默认配置(数据库中没有配置时应该返回默认值)
|
||||
let config = service_manager.get_config().await;
|
||||
assert!(config.is_ok(), "应该能够获取默认配置");
|
||||
|
||||
let config = config.unwrap();
|
||||
assert_eq!(config.base_url, "http://localhost:8188", "默认base_url应该是localhost");
|
||||
assert_eq!(config.timeout_seconds, 300, "默认超时应该是300秒");
|
||||
assert_eq!(config.retry_attempts, 3, "默认重试次数应该是3");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_config_validation() {
|
||||
// 测试有效配置
|
||||
let valid_config = ComfyUIConfig {
|
||||
base_url: "http://localhost:8188".to_string(),
|
||||
timeout_seconds: 300,
|
||||
retry_attempts: 3,
|
||||
retry_delay_ms: 1000,
|
||||
enable_websocket: true,
|
||||
enable_cache: true,
|
||||
max_concurrency: 4,
|
||||
custom_headers: None,
|
||||
};
|
||||
|
||||
let validation = valid_config.validate();
|
||||
assert!(validation.valid, "有效配置应该通过验证");
|
||||
assert!(validation.errors.is_empty(), "有效配置不应该有错误");
|
||||
|
||||
// 测试无效配置
|
||||
let invalid_config = ComfyUIConfig {
|
||||
base_url: "invalid-url".to_string(), // 无效的URL
|
||||
timeout_seconds: 0, // 无效的超时时间
|
||||
retry_attempts: 0,
|
||||
retry_delay_ms: 0,
|
||||
enable_websocket: true,
|
||||
enable_cache: true,
|
||||
max_concurrency: 0, // 无效的并发数
|
||||
custom_headers: None,
|
||||
};
|
||||
|
||||
let validation = invalid_config.validate();
|
||||
assert!(!validation.valid, "无效配置应该验证失败");
|
||||
assert!(!validation.errors.is_empty(), "无效配置应该有错误信息");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue