use std::path::PathBuf;
use tempfile::TempDir;
use wiremock::MockServer;
use crate::analysis::code_quality::CodeQualityAnalyzer;
use crate::config::LlmConfig;
use crate::diff::hunks::{Hunk, HunkLine};
use crate::llm::cache::Cache;
use crate::llm::chain::ProviderChain;
use crate::test_support::{cfg_for, fast_retry_chain, temp_cache};
pub(crate) fn analyzer_with_fast_retry(cfg: &LlmConfig, cache: Cache) -> CodeQualityAnalyzer {
CodeQualityAnalyzer::new(fast_retry_chain(std::slice::from_ref(cfg)), cache)
}
pub(crate) fn python_hunk(file_path: &str, line_no: u32) -> Hunk {
Hunk {
file_path: PathBuf::from(file_path),
old_start: line_no.saturating_sub(1),
old_count: 0,
new_start: line_no,
new_count: 1,
lines: vec![HunkLine::Added("x = 1".to_owned())],
}
}
pub(crate) fn hunks_for_python_at(line_no: u32) -> Vec<Hunk> {
vec![python_hunk("src/lib.py", line_no)]
}
pub(crate) fn hunks_for_python_at_two_lines() -> Vec<Hunk> {
vec![Hunk {
file_path: PathBuf::from("src/lib.py"),
old_start: 99,
old_count: 0,
new_start: 100,
new_count: 2,
lines: vec![
HunkLine::Added("a = 1".to_owned()),
HunkLine::Added("b = 2".to_owned()),
],
}]
}
pub(crate) fn analyzer_for(server: &MockServer) -> (CodeQualityAnalyzer, TempDir) {
let (cache, dir) = temp_cache();
let cfg = cfg_for(server, "m", 3);
let chain = ProviderChain::new(&[&cfg]).expect("chain builds from a valid config");
let analyzer = CodeQualityAnalyzer::new(chain, cache);
(analyzer, dir)
}