#![cfg(any())]
use ai_code_buddy::core::analysis::perform_analysis;
use ai_code_buddy::{Args, OutputFormat};
use anyhow::Result;
use git2::Repository;
use tempfile;
#[test]
fn legacy_analysis_simple_placeholder() {
assert!(true);
}
#[test]
fn test_perform_analysis_basic() -> Result<()> {
let temp_dir = tempfile::tempdir()?;
let repo = Repository::init(&temp_dir)?;
let mut config = repo.config()?;
config.set_str("user.name", "Test User")?;
config.set_str("user.email", "test@example.com")?;
let file_path = temp_dir.path().join("test.rs");
std::fs::write(&file_path, "fn main() {}")?;
let mut index = repo.index()?;
index.add_path(std::path::Path::new("test.rs"))?;
index.write()?;
let tree_id = index.write_tree()?;
let tree = repo.find_tree(tree_id)?;
let signature = git2::Signature::now("Test User", "test@example.com")?;
let _commit = repo.commit(
Some("HEAD"),
&signature,
&signature,
"Initial commit",
&tree,
&[],
)?;
let args = Args {
repo_path: temp_dir.path().to_string_lossy().to_string(),
source_branch: "main".to_string(),
target_branch: "HEAD".to_string(),
verbose: false,
output_format: OutputFormat::Json,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: false,
force_cpu: true,
disable_ai: false,
cli_mode: true,
show_credits: false,
parallel: false,
};
let result = perform_analysis(&args);
assert!(result.is_ok() || result.is_err());
Ok(())
}
#[test]
fn test_perform_analysis_invalid_repository() {
let args = Args {
repo_path: "/non/existent/path".to_string(),
source_branch: "main".to_string(),
target_branch: "HEAD".to_string(),
verbose: false,
output_format: OutputFormat::Summary,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: false,
force_cpu: true,
disable_ai: false,
cli_mode: true,
show_credits: false,
parallel: false,
};
let result = perform_analysis(&args);
assert!(result.is_err());
}
#[test]
fn test_analysis_gpu_settings() -> Result<()> {
let temp_dir = tempfile::tempdir()?;
let repo = Repository::init(&temp_dir)?;
let mut config = repo.config()?;
config.set_str("user.name", "Test User")?;
config.set_str("user.email", "test@example.com")?;
let file_path = temp_dir.path().join("test.rs");
std::fs::write(&file_path, "fn main() {}")?;
let mut index = repo.index()?;
index.add_path(std::path::Path::new("test.rs"))?;
index.write()?;
let tree_id = index.write_tree()?;
let tree = repo.find_tree(tree_id)?;
let signature = git2::Signature::now("Test User", "test@example.com")?;
let _commit = repo.commit(
Some("HEAD"),
&signature,
&signature,
"Initial commit",
&tree,
&[],
)?;
let args_gpu = Args {
repo_path: temp_dir.path().to_string_lossy().to_string(),
source_branch: "main".to_string(),
target_branch: "HEAD".to_string(),
verbose: false,
output_format: OutputFormat::Summary,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: true,
force_cpu: false,
disable_ai: false,
cli_mode: true,
show_credits: false,
};
let result = perform_analysis(&args_gpu);
assert!(result.is_ok() || result.is_err());
let args_cpu = Args {
repo_path: temp_dir.path().to_string_lossy().to_string(),
source_branch: "main".to_string(),
target_branch: "HEAD".to_string(),
verbose: false,
output_format: OutputFormat::Summary,
exclude_patterns: vec![],
include_patterns: vec![],
use_gpu: false,
force_cpu: true,
disable_ai: false,
cli_mode: true,
show_credits: false,
};
let result = perform_analysis(&args_cpu);
assert!(result.is_ok() || result.is_err());
Ok(())
}