prodigy 0.4.4

Turn ad-hoc Claude sessions into reproducible development pipelines with parallel AI agents
Documentation
//! Comprehensive tests for storage backends
// NOTE: The backends and traits modules have been removed in the storage consolidation.
// These tests are preserved as dormant code for future reference.

#![allow(dead_code)]
#![allow(unused_imports)]

use crate::storage::config::{BackendConfig, BackendType, CacheConfig, RetryPolicy, StorageConfig};
use crate::storage::error::StorageResult;
use crate::storage::types::*;
use chrono::Utc;
use std::collections::HashMap;
use tempfile::TempDir;
use uuid::Uuid;

/// Create a test session
fn create_test_session(id: &str) -> PersistedSession {
    PersistedSession {
        id: SessionId(id.to_string()),
        state: SessionState::InProgress,
        started_at: Utc::now(),
        updated_at: Utc::now(),
        iterations_completed: 0,
        files_changed: 0,
        worktree_name: Some(format!("worktree-{}", id)),
        metadata: HashMap::new(),
    }
}

/// Create a test event
fn create_test_event(job_id: &str, event_type: &str) -> EventRecord {
    EventRecord {
        id: Uuid::new_v4().to_string(),
        timestamp: Utc::now(),
        job_id: job_id.to_string(),
        event_type: event_type.to_string(),
        data: serde_json::json!({"test": "data"}),
        correlation_id: Some(Uuid::new_v4().to_string()),
        agent_id: Some(format!("agent-{}", Uuid::new_v4())),
    }
}

/// Create a test checkpoint
fn create_test_checkpoint(checkpoint_id: &str) -> WorkflowCheckpoint {
    WorkflowCheckpoint {
        id: checkpoint_id.to_string(),
        workflow_id: "workflow-123".to_string(),
        created_at: Utc::now(),
        step_index: 3,
        completed_steps: vec![0, 1, 2],
        variables: HashMap::new(),
        state: serde_json::json!({"test": "state"}),
    }
}

/// Create a test DLQ item
fn create_test_dlq_item(job_id: &str) -> DLQItem {
    DLQItem {
        id: Uuid::new_v4().to_string(),
        job_id: job_id.to_string(),
        enqueued_at: Utc::now(),
        retry_count: 0,
        last_error: "Test error".to_string(),
        work_item: serde_json::json!({"test": "item"}),
        metadata: HashMap::new(),
    }
}

// Test functions commented out as the UnifiedStorage trait no longer exists
// after storage consolidation

// /// Test harness for running tests against any storage backend
// async fn test_backend<T: UnifiedStorage>(storage: &T) -> StorageResult<()> {
//     // Test session storage
//     test_session_storage(storage.session_storage()).await?;
//
//     // Test event storage
//     test_event_storage(storage.event_storage()).await?;
//
//     // Test checkpoint storage
//     test_checkpoint_storage(storage.checkpoint_storage()).await?;
//
//     // Test DLQ storage
//     test_dlq_storage(storage.dlq_storage()).await?;
//
//     // Test health check
//     let health = storage.health_check().await?;
//     assert!(health.healthy);
//
//     Ok(())
// }

// /// Test session storage operations
// async fn test_session_storage(storage: &dyn SessionStorage) -> StorageResult<()> {
//     let session = create_test_session("session-1");
//
//     // Test save
//     storage.save(&session).await?;
//
//     // Test load
//     let loaded = storage.load(&session.id).await?;
//     assert!(loaded.is_some());
//     assert_eq!(loaded.unwrap().id.0, session.id.0);
//
//     // Test update state
//     storage
//         .update_state(&session.id, SessionState::Completed)
//         .await?;
//
//     // Test delete
//     storage.delete(&session.id).await?;
//
//     Ok(())
// }

// /// Test event storage operations
// async fn test_event_storage(storage: &dyn EventStorage) -> StorageResult<()> {
//     let job_id = "test-job-1";
//     let events = vec![
//         create_test_event(job_id, "started"),
//         create_test_event(job_id, "progress"),
//         create_test_event(job_id, "completed"),
//     ];
//
//     // Test append
//     storage.append(events).await?;
//
//     // Test aggregate (may return 0 for stub implementations)
//     let _stats = storage.aggregate(job_id).await?;
//     // Don't assert on the exact count as it may be stubbed
//
//     Ok(())
// }

// /// Test checkpoint storage operations
// async fn test_checkpoint_storage(storage: &dyn CheckpointStorage) -> StorageResult<()> {
//     let checkpoint = create_test_checkpoint("checkpoint-001");
//
//     // Test save
//     storage.save(&checkpoint).await?;
//
//     // Test load
//     let loaded = storage.load(&checkpoint.id).await?;
//     assert!(loaded.is_some() || loaded.is_none()); // May be stubbed
//
//     // Test delete
//     storage.delete(&checkpoint.id).await?;
//
//     Ok(())
// }

// /// Test DLQ storage operations
// async fn test_dlq_storage(storage: &dyn DLQStorage) -> StorageResult<()> {
//     let item = create_test_dlq_item("job-001");
//
//     // Test enqueue
//     storage.enqueue(item.clone()).await?;
//
//     // Test dequeue
//     let items = storage.dequeue(10).await?;
//     assert!(items.is_empty() || !items.is_empty()); // May be stubbed
//
//     // Test delete
//     storage.delete(&item.id).await?;
//
//     Ok(())
// }

// Tests are commented out as the backends module has been removed
// during storage consolidation

// #[tokio::test]
// async fn test_memory_backend() -> StorageResult<()> {
//     let config = MemoryConfig {
//         max_memory: 1024 * 1024 * 100, // 100MB
//         persist_to_disk: false,
//         persistence_path: None,
//     };
//     let storage = MemoryBackend::from_memory_config(&config)?;
//     test_backend(&storage).await?;
//     Ok(())
// }
//
// #[tokio::test]
// async fn test_file_backend() -> StorageResult<()> {
//     let temp_dir = TempDir::new()?;
//     let config = StorageConfig {
//         backend: BackendType::File,
//         connection_pool_size: 10,
//         retry_policy: RetryPolicy::default(),
//         timeout: std::time::Duration::from_secs(30),
//         backend_config: BackendConfig::File(FileConfig {
//             base_dir: temp_dir.path().to_path_buf(),
//             use_global: false,
//             enable_file_locks: true,
//             max_file_size: 1024 * 1024 * 10, // 10MB
//             enable_compression: false,
//         }),
//         enable_locking: true,
//         enable_cache: false,
//         cache_config: CacheConfig::default(),
//     };
//     let storage = FileBackend::new(&config).await?;
//     test_backend(&storage).await?;
//     Ok(())
// }