ai-code-buddy 0.4.20

An AI-powered code review tool with elegant Bevy-based TUI
Documentation
// Re-enabled analysis tests for improved coverage
use ai_code_buddy::args::{Args, OutputFormat};
use ai_code_buddy::core::analysis::perform_analysis;
use anyhow::Result;
use pretty_assertions::assert_eq;
use tempfile::TempDir;

fn create_test_args(repo_path: String) -> Args {
    Args {
        repo_path,
        source_branch: "main".to_string(),
        target_branch: "main".to_string(),
        cli_mode: false,
        verbose: false,
        show_credits: false,
        output_format: OutputFormat::Summary,
        exclude_patterns: vec![],
        include_patterns: vec![],
        use_gpu: false,
        force_cpu: true,
        parallel: false,
        disable_ai: false,
    }
}

#[test]
fn test_perform_analysis_basic() -> Result<()> {
    // Create a temporary git repository
    let temp_dir = TempDir::new()?;
    let repo_path = temp_dir.path().to_string_lossy().to_string();

    // Initialize git repo
    git2::Repository::init(&temp_dir.path())?;

    let args = create_test_args(repo_path);
    let review = perform_analysis(&args)?;

    // Should complete successfully
    assert_eq!(review.files_count, 0); // No changed files in same branch
    assert_eq!(review.issues_count, 0);

    Ok(())
}

#[test]
fn test_perform_analysis_different_output_formats() -> Result<()> {
    let temp_dir = TempDir::new()?;
    let repo_path = temp_dir.path().to_string_lossy().to_string();

    git2::Repository::init(&temp_dir.path())?;

    let output_formats = vec![
        OutputFormat::Summary,
        OutputFormat::Detailed,
        OutputFormat::Json,
        OutputFormat::Markdown,
    ];

    for format in output_formats {
        let mut args = create_test_args(repo_path.clone());
        args.output_format = format;

        let review = perform_analysis(&args)?;

        // Should complete successfully for all formats
        assert_eq!(review.files_count, 0);
    }

    Ok(())
}

#[test]
fn test_perform_analysis_with_verbose() -> Result<()> {
    let temp_dir = TempDir::new()?;
    let repo_path = temp_dir.path().to_string_lossy().to_string();

    git2::Repository::init(&temp_dir.path())?;

    let mut args = create_test_args(repo_path);
    args.verbose = true;

    let review = perform_analysis(&args)?;

    // Should complete successfully with verbose output
    assert_eq!(review.files_count, 0);

    Ok(())
}

#[test]
fn test_perform_analysis_invalid_repository() -> Result<()> {
    let temp_dir = TempDir::new()?;
    let repo_path = temp_dir
        .path()
        .join("nonexistent")
        .to_string_lossy()
        .to_string();

    let args = create_test_args(repo_path);

    // Should return an error for invalid repository
    let result = perform_analysis(&args);
    assert!(result.is_err());

    Ok(())
}

#[test]
fn legacy_analysis_placeholder() {
    assert!(true);
}